-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathq-6.cpp
55 lines (47 loc) · 845 Bytes
/
q-6.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
using namespace std;
class complex
{
int real;
int imag;
public:
complex(){}
complex(int, int);
complex add(int, complex);
complex add(complex, complex);
void display();
};
complex::complex(int r, int i)
{
real=r;
imag=i;
}
complex complex::add(int a, complex s2)
{
real=s2.real+a;
imag=s2.imag;
}
complex complex::add(complex s1, complex s2)
{
real=s1.real+s2.real;
imag=s1.imag+s2.imag;
}
void complex::display()
{
cout<<real<<" + i"<<imag<<endl;
}
int main()
{
complex s1(5, 6);
complex s2(8, 3);
complex s3, s4;
int a;
cout<<"enter an integer value:"<<endl;
cin>>a;
s3.add(a, s2);
cout<<"on adding integer value:"<<endl;
s3.display();
s4.add(s1, s2);
cout<<"on adding the two numebers:"<<endl;
s4.display();
}