2015年1月5日XX大学XX学院考试题
六、 程序题 1.写一个复数类(操作符重载) #include<iostream> using namespace std; class Complex{ public: Complex(double r=0.0,double i=0.0):read(r),imag(i){}; Complex operator+(const Complex &c2)const; Complex operator-(const Complex &c2)const; void display()const; private: double real,imag; }; Complex Complex::operator+(const Complex &c2)const{ return Complex(real=c2.real+real,imag=c2.imag+imag); } Complex Complex::operator-(const Complex &c2)const{ return Complex(real=c2.real-real,imag=c2.imag-imag); } void Complex::display()const{ cout<<"("<<real<<","<<imag<<")"<<endl; } void int main(){ Complex c1(5,4),c2(2