Friend Function Program in C++

This C++ program demonstrates the use of keyword friend in classes. The program creates two classes ‘X’ and ‘Y’ and declares one class as ‘friend’ in another. By declaring friend, we mean that the friend class ‘Y’ will gain access to all the data members of the class ‘X’. The member functions of the friend … Read more

advertisement

User Defined Exceptions in C++

This C++ program demonstrates user-defined exceptions. The program derives an exception class from the standard exception class named Divide_By_Zero_Exception. The try block throws the Divide_By_Zero_Exception object and catch block handles it by executing the what() member function. Here is the source code of the C++ program which demonstrates user-defined exceptions. The C++ program is successfully … Read more

advertisement

C++ Program to Implement atol Function

This C++ Program which implements atol function which converts a C++ string to an integer value. The function atol( ) skips any trailing blanks and alphabets and if the string iterator has reached the end of the string, a negative value is returned to indicate that no digit is present in the string else the … Read more

advertisement

Enumerations Program in C++

This C++ Program which illustrates the use of enumerations. The program creates an enumeration of months, creates an enumeration variable, assigns it a month value and prints a comment on the current month. Here is source code of the C++ program which illustrates the use of enumerations. The C++ program is successfully compiled and run … Read more

advertisement

Order of Constructor and Destructor Calls in C++

This C++ program demonstrates the order of constructor and destructor calls for globally and locally initialized objects. The constructors of global objects are initialized earlier than local objects and the destructors for local objects are called earlier than global objects. Thus we can say that scope of a global object is larger than a local … Read more

advertisement

Copy Constructor Program in C++

This C++ program illustrates copy-constructor in a class. A copy constructor is a special constructor for a class that is used to make a copy of an existing instance of the class. A copy-constructor looks like a constructor with an object of same class as an argument. Here is the source code of the C++ … Read more

advertisement

C++ Program to Demonstrate the use of Static Data Members in a Class

This C++ program demonstrates the use of static members in a class. A static data member is shared by all objects of a class. We can put a static data member inside a class but we would have to initialize it outside the class using scope resolution operator (::). Here is the source code of … Read more

advertisement

C++ Program to Implement a Class with Mutable Members

This C++ program illustrates the concept of mutable keyword in classes. The keyword mutable enables a const member function to change a variable. This explains the concept of logical const-ness of the object where the object changes in a way that it is not apparent through a public interface. Here is the source code of … Read more

advertisement

C++ Program to Illustrate Const Keyword with Member Functions

This C++ program illustrates the const keyword with member functions. The functions with a const keyword specified before the function definition prevents the calling of non-const data members for a given instance of the class. It also prevents t Here is the source code of the C++ program which illustrates the const keyword with member … Read more

advertisement

C++ Program to Add Two Complex Numbers using Class

This is a C++ Program to add two Complex Numbers. Problem Description We have to input the real and imaginary parts of two complex numbers separately and add them using classes and objects in C++. Expected Input and Output 1. When the real and imaginary part both are positive. First Complex Number = 5 + … Read more

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.