Found 7197 Articles for C++

C++ Program to Create Custom Exception

Alshifa Hasnain
Updated on 18-Mar-2025 17:55:41

4K+ Views

In this article, we learn to create custom-made, user−defined exceptions in C++. Exceptions are a core concept of C++. They occur when an unwanted or impossible operation occurs during execution. Handling these unwanted or impossible operations is known as exception handling in C++. What is Exception Handling? Exception handling is mainly done using three specific keywords: ' 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. Exception Types Exceptions in C++ can be divided ... Read More

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

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

5K+ 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

1K+ 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

3K+ 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

2K+ 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

453 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

C++ Program to calculate the logarithm of a given number based on a given base

Arnab Chakraborty
Updated on 07-Dec-2022 11:28:31

5K+ Views

In almost any modern programming languages, we find the few logarithm functions like natural logs, log with base 2, log with base 10 etc. But sometimes we need to calculate logarithm with different base which are not available in the given library functions. To achieve this goal we can use simple logarithmic formula. In this article we will see how to calculate logarithm values with a given number and a given base in C++. Formula to calculate logarithm with given base Let we have taken a number x, and its base is k which is also given. The ... Read More

C++ Program to calculate the base 10 logarithm of the given value

Arnab Chakraborty
Updated on 07-Dec-2022 11:25:49

767 Views

Logarithms for base 10 are relatively required for natural computations in a variety of applications. For competitive examinations, there are a few quick ways to memorise a few log values. There are a few ways to compute logarithm results using library functions when programming, as well as a few shortcuts. In this post, we'll go through a couple methods for computing the base-10 logarithm of a given number in C++. Using log10() function One library function used to determine the base-10 logarithm for a given parameter is called log10(). An integer or a floating-point number could be the ... Read More

C++ Program to Convert Vector to a List

Arnab Chakraborty
Updated on 19-Oct-2022 12:37:53

2K+ Views

Vectors in C++ are dynamic arrays that can contain any type of data, it can be user-defined or primitive. Dynamic is in the sense that the size of a vector can increase or decrease according to the operations. Vectors have support for various functions, for which data manipulation is very easy. Lists on the other hand are containers same as vectors, but list implementation is based on doubly linked lists compared to the array implementation of vectors. Lists offer the same constant time operations anywhere in it, that is the main feature of using lists. We take a look at ... Read More

C++ Program to Convert Array to Set (Hashset)

Arnab Chakraborty
Updated on 19-Oct-2022 11:22:52

5K+ Views

The array is a data structure that is available in C++ and is used to hold a sequential collection of elements of the same type. An array has a size that is fixed, but can be expanded or shrank if needed. It is important to think of an array as a collection of variables of the same type even though it is used to store a collection of data. Sets, or in this case unordered sets are a container that stores elements of a particular datatype in any order. A hash table is used to implement an unordered_set where keys ... Read More

Advertisements