-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplex.cpp
More file actions
174 lines (161 loc) · 3.3 KB
/
Copy pathComplex.cpp
File metadata and controls
174 lines (161 loc) · 3.3 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* File: Q3.cpp
* Author: Manish
*
* Created on 24 August, 2018, 6:33 AM
*/
//#include <cstdlib>
//#include<iostream>
//using namespace std;
//
//class complex
//{
//private:
// int r;
// int i;
//public:
// friend istream & operator>>(istream &in ,complex &c)
// {
// cout<<"PLEASE ENTER REAL PART OF COMPLEX NUMBER:";
// in>>c.r;
// cout<<"PLEASE ENTER IMAGINARY PART OF AN COMPLEX NUMBER:";
// in>>c.i;
// }
//
// friend ostream & operator<<(ostream &out ,complex &c)
// {
// cout<<"COMPLEX NUMBER ="<<c.r<<showpos<<c.i<<"i"<<endl;
// }
//
// complex operator+(complex);
// complex operator-(complex);
//};
//
//
//complex complex::operator+(complex c)
//{
// complex temp;
// temp.r=r+c.r;
// temp.i=i+c.i;
// return temp;
// }
//
//complex complex::operator-(complex c)
//{
// complex temp;
// temp.r=r-c.r;
// temp.i=i-c.i;
// return temp;
//}
//
//int main(int argc, char** argv)
//{
// complex c1,c2,c3;
// cout<<"ENTER DETAILS OF FIRST COMPLEX NUMBER:"<<endl;
// cin>>c1>>c2;
// cout<<c1;
//
// cout<<"\nENTER DETAILS OF SECOND COMPLEX NUMBER:"<<endl;
// cin>>c2;
// cout<<c2;
//
// cout<<"ADDITION RESULT OF AN COMPLEX NUMBER:"<<endl;
// c3=c1+c2;
// cout<<c3;
// cout<<"SUBSTRACTION RESULT OF AN COMPLEX NUMBER:"<<endl;
// c3=c1-c2;
// cout<<c3;
// return 0;
//}
/*
* File: Q3.cpp
* Author: Manish
*
* Created on 24 August, 2018, 6:33 AM
*/
#include <cstdlib>
#include<iostream>
using namespace std;
class Complex
{
private:
int r;
int i;
public:
Complex()
{
r=0;
i=0;
}
~Complex()
{
r=0;
i=0;
}
friend istream & operator>>(istream &in ,Complex &c);
friend ostream & operator<<(ostream &out ,Complex &c);
Complex operator+(Complex&);
Complex operator-(Complex&);
Complex operator*(Complex&);
Complex& operator=(const Complex&);
};
istream & operator>>(istream &in ,Complex &c)
{
cout<<"PLEASE ENTER REAL PART OF COMPLEX NUMBER:";
in>>c.r;
cout<<"PLEASE ENTER IMAGINARY PART OF AN COMPLEX NUMBER:";
in>>c.i;
return in;
}
ostream & operator<<(ostream &out ,Complex &c)
{
out<<"COMPLEX NUMBER ="<<showpos<<c.r<<showpos<<c.i<<"i"<<endl;
return out;
}
Complex Complex::operator+(Complex & c)
{
Complex temp;
temp.r=this->r+c.r;
temp.i=this->i+c.i;
return temp;
}
Complex Complex::operator-(Complex & c)
{
Complex temp;
temp.r=this->r-c.r;
temp.i=this->i-c.i;
return temp;
}
Complex Complex::operator*(Complex & c)
{
Complex temp;
temp.r=(this->r*c.r)-(this->i*c.i);
temp.i=r*c.i+i*c.r;
return temp;
}
Complex& Complex::operator=(const Complex &c)
{
this->i=c.i;
this->r=c.r;
return (* this);
}
int main(int argc, char** argv)
{
Complex c1,c2,c3;
cout<<"ENTER DETAILS OF FIRST COMPLEX NUMBER:"<<endl;
cin>>c1;
cout<<c1;
cout<<"\nENTER DETAILS OF SECOND COMPLEX NUMBER:"<<endl;
cin>>c2;
cout<<c2;
cout<<"ADDITION RESULT OF AN COMPLEX NUMBER:"<<endl;
c3=c1+c2;
cout<<c3;
cout<<"SUBSTRACTION RESULT OF AN COMPLEX NUMBER:"<<endl;
c3=c1-c2;
cout<<c3;
cout<<"MULTIPLICATION RESULT OF AN COMPLEX NUMBER:"<<endl;
c3=c1*c2;
cout<<c3;
return 0;
}