Whats in this post?
- Background and Explanation of the code
To copy code: Click “View Source” on the right of this code snippet.
Background and Explanation of the code
The above program is used to add two complex numbers using the concept of constructor overloading.There are three constructor functions associated with the class complex. A particular constructor invoked depends upon the number of arguments passed when an object is created. Both the data members real and imag of object c2 initializes to 5 using constructor with one parameter.The data members of object c1 are initialized using constructor with two parameters.These two complex numbers are added and result is stored in c3 object which is finally displayed.
11 + 13i