#include <iostream>
using namespace std;
class CComplex
{
public:
CComplex()
{
real = 0.0;
imag = 0.0;
}
CComplex(float x, float y)
{
real = x;
imag = y;
}
CComplex operator + (CComplex &obj1, CComplex &obj2)
{
CComplex obj3(obj1.real + obj2.real, obj1.imag + obj2.imag);
return obj3;
}
CComplex &operator++(CComplex &obj)
{
obj.real += 1;
obj.imag +=1;
return obj;
}
void print()
{
cout<<real<<"+"<<imag<<"i"<<endl;
}
private:
float real;
float imag;
};
CComplex &operator--(CComplex &x)
{
x.real -= 1;
x.imag -= 1;
return x;
}
void main()
{
CComplex obj1(2.1,3.2);
CComplex obj2(3.6,2.5);
cout<<"obj1=";
obj1.print();
cout<<"obj2=";
obj2.print();
CComplex obj3 = obj1 + obj2;
cout<<"befor++, obj3=";
obj3.print();
++obj3;
cout<<"after++, obj3=";
obj3.print();
--obj3;
cout<<"after--, obj3=";
obj3.print();
CComplex obj4 = ++obj3;
cout<<"obj4=";
obj4.print();
}
全是错误 看得头晕了不懂怎么改。。。。
冷凌川
相关分类