-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.cpp
More file actions
55 lines (46 loc) · 997 Bytes
/
complex.cpp
File metadata and controls
55 lines (46 loc) · 997 Bytes
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 , img ;
public :
complex(){
real = 0 ;
img = 0 ;
}
complex(int r,int i){
real = r;
img = i ;
}
void display(int r,int i){
cout<<r<<"+"<<i<<"i"<<endl;
}
int operation(complex,complex);
};
int complex :: operation(complex c1, complex c2)
{
int realpart;
realpart = c1.real + c2.real ;
int imgpart ;
imgpart = c1.img+ c2.img ;
cout<<"Addition = ";
cout<<realpart<<" + "<< imgpart <<"i"<<endl;
int a,b;
a = (c1.real * c2.real)-(c1.img * c2.img) ;
b = (c1.real * c2.img) +(c1.img * c2.real);
cout<<"Multiplication = ";
cout<<a<<" + "<<b<<"i"<<endl;
return 0 ;
}
int main(){
complex obj,sum;
complex c1(1,2);
complex c2(3,4);
c1.display(1,2);
c2.display(3,4);
int result;
result = sum.operation(c1,c2);
cout<<result<<endl;
//sum.display(3,2);
return 0;
}