加油,伙伴们!
#include<iostream>
using namespace std;
class FS{
private:
double real;
double image;
public:
FS()
{
real=0;
image=0;
}
FS(double a,double b)
{
real=a;
image=b;
}
FS operator+(FS &c)
{
FS a;
a.real=this->real+c.real;
a.image=this->image+c.image;
return a;
}
FS operator-(FS &d)
{
FS e;
e.real=real-d.real;
e.image=image-d.image;
return e;
}
void show()
{
cout<<real<<"+"<<image<<"i"<<endl;
}
};
int main()
{
FS c1(1,3);
FS c2(2,5);
FS c3;
c1.show();
c2.show();
c3=(c1+c2);
cout<<"两复数相加得:";
c3.show();
cout<<"两复数相减得:";
(c2-c1).show();
}