Found 7346 Articles for C++

C++ Program to get the subarray from an array using a specified range of indices

Arnab Chakraborty
Updated on 13-Dec-2022 15:03:51

9K+ Views

A sequence of memory sections is used to store homogeneous data in an array, a linear sequential data structure. Similar to other data structures, an array needs to have specific qualities to insert, delete, traverse, and update elements efficiently. In C++, our arrays are static. There are also a few dynamic array structures available in C++. In this article, we will see how to get a subarray from a bigger array using starting and ending indices in C++. Understanding the concept with examples Given array A = [10, 14, 65, 85, 96, 12, 35, 74, 69] Given two indices 2 ... Read More

C++ Program to push an array into another array

Arnab Chakraborty
Updated on 13-Dec-2022 15:02:36

5K+ Views

A linear sequential data structure called an array is used to store homogeneous data in a series of memory regions. An array needs to have certain features to insert, delete, traverse, and update elements effectively, just like other data structures do. Our arrays in C++ are static. In addition, C++ offers a few dynamic array structures. There may be a maximum of Z elements that can be stored inside a static array. And there are currently n elements in it. In this article, we will see how to push the elements of one array inside another array in C++. Understanding ... Read More

C++ Program to append an element into an array

Arnab Chakraborty
Updated on 04-Oct-2023 12:16:39

37K+ Views

An array is a linear sequential data structure to hold homogeneous data in consecutive memory locations. Like other data structures, an array also must-have features to insert, delete, traverse and update elements in some efficient way. In C++, our arrays are static. There are a few dynamic array structures also available in C++. For a static array, there may be a Z number of elements that can be stored inside that array. And till now we have n elements into it. In this article, we will see how to insert an element at the end of an array (which is ... Read More

C++ Program to Access private members of a class

Arnab Chakraborty
Updated on 13-Dec-2022 14:54:09

21K+ Views

Private members of a class are only accessed by the members of the class. This is done to preserve the object-oriented paradigm encapsulation, which ensures data and its related functions are kept in one unit and only accessible only from a member of that class. C++ has three different access specifiers to specify the visibility of the members of a class. The three access specifiers are − Public − If a member of a class has the visibility public, then the members can be accessed from any other class. Private − Class members having private visibility can be accessed from ... Read More

C++ Program to Create Custom Exception

Arnab Chakraborty
Updated on 13-Dec-2022 14:47:38

3K+ Views

Exceptions are a very core concept of C++. Exceptions occur when an unwanted or impossible operation has occurred during execution. Handling these unwanted or impossible operations is known as exception handling in C++. Exception handling is mainly done using three specific keywords which are ‘try’, ‘catch’, and ‘throw’. The ‘try’ keyword is used to execute code that may encounter an exception, the ‘catch’ keyword is used to handle such exceptions, and the ‘throws’ keyword is used to create an exception. Exceptions in C++ can be divided into two types, which are STL exceptions and user-defined exceptions. In this article, ... Read More

C++ Program to Show Use of This Keyword in Class

Arnab Chakraborty
Updated on 13-Dec-2022 14:34:28

4K+ Views

The ‘this’ keyword in C++ is very important and it is used in multiple use cases. The ‘this’ keyword or the ‘this’ pointer is used as an implicit object parameter when an object’s member function is called and refers to the invoking object. We take a look at the different use cases of the ‘this’ keyword. Syntax The ‘this’ keyword is used in the following way this->variable_name; Use Case 1: Resolving Variable Shadowing Variable shadowing is a very common use case for the ‘this’ pointer. Variable shadowing occurs when a class member variable and another parameter ... Read More

C++ Program to get the imaginary part of the given complex number

Arnab Chakraborty
Updated on 12-Dec-2022 16:18:07

828 Views

Modern science relies heavily on the concept of complex numbers, which was initially established in the early 17th century. The formula for a complex number is a + ib, where a and b are real values. A complex number is known to have two parts: the real component (a) and the imaginary part (ib). The i or iota has the value √-1. The complex class in C++ is a class that is used to represent complex numbers. The complex class in C++ can represent and control several complex number operations. We take a look at how to represent and display ... Read More

C++ Program to initialize and print a complex number

Arnab Chakraborty
Updated on 07-Dec-2022 11:43:52

2K+ Views

Complex numbers are a very fundamental concept in modern science, the concept is first introduced in the early 17th century. Complex numbers are of the form a + ib, where a and b are real numbers. a is known as the real part and ib is known as the imaginary part of a complex number. In C++, there is a class to represent complex numbers which is the complex class. The complex class in C++ can represent and manipulate various operations on complex numbers. We take a look at how to represent, initialize, and display complex numbers. Initializing using the ... Read More

C++ Program to convert a number into a complex number

Arnab Chakraborty
Updated on 07-Dec-2022 11:54:26

1K+ Views

Complex numbers in C++ are available in the header and it enables a developer to represent and manipulate complex numbers. Complex numbers have the form a + ib, where 'a' is referred to as the complex number's real portion and 'ib' is the number's imaginary part. The imaginary portion is denoted by the letter 'i' whose value is "iota" which is equal to -1. Complex numbers are extremely important in many programs since they are employed in many mathematical and scientific processes. We take a look at how to represent complex numbers in C++ and how to convert a ... Read More

C++ Program to calculate the logarithm gamma of the given number

Arnab Chakraborty
Updated on 07-Dec-2022 11:37:26

358 Views

The gamma function is described as an extension of the factorial of every given number in mathematics. The factorial, on the other hand, can only be defined for real numbers, hence the gamma function exceeds to calculate the factorial on all complex values other than negative integers. It is represented by − $$\mathrm{\Gamma \left ( x \right )=\left ( x-1 \right )!}$$ The gamma function grows quickly for higher values; hence, applying logarithm to the gamma will greatly slow it down. The natural logarithm gamma of a particular number is another name for it. In this article, we will see ... Read More

Advertisements