-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec29.cpp
38 lines (34 loc) · 945 Bytes
/
lec29.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using namespace std;
/*A constructor should be declared in the public section of the class
They are automatically invoked whenever the object is created
They cannot return values and do not have return types
It can have default arguments
We cannot refer to their address*/
class Complex
{
// Creating a Constructor
// Constructor is a special member function with the same name as of the class.
//It is used to initialize the objects of its class.
//It is automatically invoked whenever an object is created.
int a, b;
public:
Complex(void);
void printNumber()
{
cout << "Sum of complex numbers is: " << a << " + " << b << "i " << endl;
}
};
Complex ::Complex(void) // ----> This is a default constructor as it takes no parameters
{
a = 10;
b = 20;
}
int main()
{
Complex c1, c2, c3;
c1.printNumber();
c2.printNumber();
c3.printNumber();
return 0;
}