50 lines
689 B
C++
50 lines
689 B
C++
![]() |
/*
|
||
|
Rafay Ahmad
|
||
|
23I-2526
|
||
|
*/
|
||
|
#include <iostream>
|
||
|
using namespace std;
|
||
|
|
||
|
|
||
|
|
||
|
class Complex{
|
||
|
int real;
|
||
|
int img;
|
||
|
|
||
|
public:
|
||
|
|
||
|
Complex(){}
|
||
|
Complex(int real, int img) : real(real), img(img){}
|
||
|
|
||
|
Complex operator+(Complex c){
|
||
|
Complex res;
|
||
|
res.real = real + c.real;
|
||
|
res.img = img + c.img;
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
|
||
|
friend ostream& operator<<(ostream&, Complex&);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
};
|
||
|
|
||
|
ostream& operator<<(ostream& out, Complex& c){
|
||
|
out<<c.real<<"+"<<c.img<<"i\n";
|
||
|
return out;
|
||
|
}
|
||
|
|
||
|
int main(){
|
||
|
|
||
|
Complex c1(1, 2);
|
||
|
Complex c2(2, 3);
|
||
|
Complex c4(2, 3);
|
||
|
|
||
|
Complex c3 = c1 + c2 + c4;
|
||
|
int c3 = c1 + c2 + c4;
|
||
|
cout<<c3;
|
||
|
|
||
|
return 0;
|
||
|
}
|