第14周课后习题
复数类的操作
#include<iostream>
using namespace std;
class complex
{
private:
double real,image;
public:
complex(double n,double m)
{
real=n;
image=m;
}
void trans()
{
real=-real;
image=-image;
}
void print()
{
cout<<"("<<real<<", "<<image<<")"<<endl;
}
friend void add(complex&a,complex&b)
{
double rr,ii;
rr=a.real+b.real;
ii=a.image+b.image;
cout<<"("<<rr<<", "<<ii<<")"<<endl;
}
};
int main ()
{
double a,b,c,d;
cin>>a>>b>>c>>d;
complex s1(a,b);
complex s2(c,d);
add(s1,s2);
s2.trans();
add(s1,s2);
s2.trans();
s2.print();
}