|
发表于 2009-11-5 01:03:47
|
显示全部楼层
IP:江苏扬州
#include <iostream>
using namespace std;
class complex
{
public:
complex ()
{
real=0;
imag=0;
}
complex(double r,double i)
{
real=r;
imag=i;
}
complex operator -(complex &c2);
void display();
private:
double real;
double imag;
};
complex complex::operator -(complex &c2)
{
return complex(real-c2.real,imag-c2.imag);
}
void complex::display()
{
cout<<"("<<real<<","<<imag<<"i)"<<endl;
}
int main()
{
complex c1(3,4),c2(5,-10),c3;
c3=c1-c2;
cout<<"c1=";
c1.display();
cout<<"c2=";
c2.display();
cout<<"c3=";
c3.display();
return 0;
} |
|