You are viewing a single comment's thread. Return to all comments →
using namespace std;
class complex { private: int real; int img;
public: void setReal(int r); void setImg(int i); int getReal(); int getImg(); complex operator+(complex c) { complex temp; temp.real=real+c.real; temp.img=img+c.img; return temp; } friend ostream & operator<<(ostream & out,complex c); friend istream & operator>>(istream & in,complex &c);
};
int main() { complex c1,c2,c3; cin>>c1; cin>>c2;
c3=c1+c2; cout<<c3; return 0;
} void complex::setReal(int r){real=r;} void complex::setImg(int i){img=i;} int complex::getReal(){return real;} int complex::getImg(){return img;} ostream & operator<<(ostream & out,complex c) { out<>(istream & in,complex &c) { in>>c.real; in.ignore(1,'+'); in.ignore(1,'i'); in>>c.img;
return in;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Overload Operators
You are viewing a single comment's thread. Return to all comments →
include
include
include
include
include
using namespace std;
class complex { private: int real; int img;
};
int main() { complex c1,c2,c3; cin>>c1; cin>>c2;
} void complex::setReal(int r){real=r;} void complex::setImg(int i){img=i;} int complex::getReal(){return real;} int complex::getImg(){return img;} ostream & operator<<(ostream & out,complex c) { out<>(istream & in,complex &c) { in>>c.real; in.ignore(1,'+'); in.ignore(1,'i'); in>>c.img;
}