Lớp số phức – Complex Number class in C++

#include
#include
class ComplexN
{
float a;
float b;
public:
ComplexN(){};
ComplexN(float a1, float b1):a(a1),b(b1){};
friend ostream & operator <> (istream &, ComplexN &);
ComplexN operator + (const ComplexN &);
ComplexN operator – (const ComplexN &);
ComplexN operator * (const ComplexN &);
};

istream & operator >> (istream & is, ComplexN & r)
{
cout <> r.a;
cout <> r.b;
return is;
}

ostream & operator << (ostream & os,const ComplexN & r)
{
os << setprecision(2) <0.0)
os << ” + ” << setprecision(2) << r.b << “*i”;
else
os << setprecision(2) << r.b <> z1;
cin >> z2;
cout << “z1 = ” << z1 << endl;
cout << “z2 = ” << z2 << endl;
cout << “z1+z2 = ” << z1+z2 << endl;;

return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s