-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.cpp
93 lines (84 loc) · 2.07 KB
/
1.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<iostream>
using namespace std;
// complex obj;
// obj.real ;
//obj.img
// real img
class complex{
private:
int real;
int img;
public:
complex(){
real = 0;
img = 0;
}
friend istream & operator >>(istream &,complex &);
friend ostream & operator <<(ostream &, complex &);
complex operator+(complex);
complex operator*(complex); //2 + i4, 3 + i5 =
};
istream & operator >>(istream& , complex& i){
cin>>i.real>>i.img;
return cin;
}
ostream & operator <<(ostream&, complex& j){
cout<<j.real<<"+ i"<<j.img<<endl;
return cout;
}
complex complex::operator+(complex n){
complex temp;
temp.real = real + n.real;
temp.img = img + n.img;
return temp;
}
complex complex::operator*(complex n){
complex temp;
temp.real = (real*n.real) - (img*n.img);
temp.img = (real * n.img) + (img * n.real);
return temp;
}
int main(){
bool flag = true;
while(flag){
int ch;
complex n1;
complex n2;
cout<<"\n******MENU******\n1.Add\n2.Multiply\n3.Exit\n==> ";
cin>>ch;
if(ch == 1){
cout<<"Enter 1st Complex number: ";
cin>>n1;
cout<<"Enter 2nd Complex Number: ";
cin>>n2;
complex ans = n1+n2;
cout<<ans;
}else if(ch == 2){
cout<<"Enter 1st Complex number: ";
cin>>n1;
cout<<"Enter 2nd Complex Number: ";
cin>>n2;
complex ans = n1*n2;
cout<<ans;
}
else if(ch == 3){
cout<<"\nExit success!";
break;
}
else{
cout<<"Invalid Input!!";
}
cout<<"Do you want to continue(y/n): ";
char a;
cin>>a;
if(a == 'y' || a == 'Y'){
continue;
}else if(a == 'n'||a=='N'){
flag = false;
}else{
cout<<"Invalid input Exit****";
flag = false;
}
}
return 0;
}