-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex no. addition.cpp
More file actions
56 lines (54 loc) · 1.36 KB
/
complex no. addition.cpp
File metadata and controls
56 lines (54 loc) · 1.36 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
using namespace std;
class complexno
{
int real,imag;
public:
complexno()
{
real=0;
imag=0;
}
complexno(int i)
{
real=i;
imag=i;
}
complexno(int a, int b){
real=a;
imag=b;
}
void add(complexno c1,complexno c2)
{
real=c1.real+c2.real;
imag=c1.imag+c2.imag;
}
void display()
{
cout<<real<<"+"<<imag<<"i";
}
};
int main()
{
cout<<"\n\n program to find the addition of two complex numbers using constructor overloading ";
int real,imag;
cout<<"\n \n Enter a single value parts for real and imaginary parts of first complex numbers " ;
cin>>real;
complexno c1(real);
cout<<"\n first complex number is given by : ";
c1.display();
cout<<"\n\n Enter the differnt values of real and imaginary parts of second complex numbers";
cin>>real>>imag;
complexno c2(real,imag);
cout<<"\n second complex number is given by : ";
c2.display();
complexno c3;
cout<<"\n \n initially third complex number is : ";
c3.display();
cout<<"\n\nstoring the result of addition of first and second complex number into third.....";
c3.add(c1,c2);
cout<<"\n\n now third complex number is";
c3.display();
cout<<"\n";
return 0;
}