/** 程序的版权和版本号声明部分:* Copyright (c) 2013, 烟台大学计算机学院* All rights reserved.* 文件名:test.cpp* 作 者:赵加响* 完毕日期:2014年 4月 22日* 输入描写叙述:* 程序输出:* 问题分析:略* 算法设计:略*/#includeusing namespace std;class Complex{public: Complex(){real=0;imag=0;} Complex(double r,double i){real=r; imag=i;} Complex operator+(Complex &c2); Complex operator-(Complex &c2); Complex operator*(Complex &c2); Complex operator/(Complex &c2); friend ostream&operator<<(ostream&,Complex&); friend Complex operator-(Complex &c);//取负private: double real; double imag;};//以下定义成员函数Complex operator-(Complex &c){ Complex c1; c1.imag=0-c.imag; c1.real=0-c.real; return c1;}Complex Complex::operator+(Complex &c2){ Complex c; c.real=real+c2.real; c.imag=imag+c2.imag; return c;}Complex Complex::operator-(Complex &c2){ Complex c; c.real=real-c2.real; c.imag=imag-c2.imag; return c;}Complex Complex::operator*(Complex &c2){ Complex c; c.real=(real*c2.real-imag*c2.imag); c.imag=imag*c2.real+real*c2.imag; return c;}Complex Complex::operator/(Complex &c2){ Complex c; c.real=(real*c2.real+imag*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag); c.imag=(imag*c2.real-real*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag); return c;}ostream&operator<<(ostream&output,Complex&c){ if(c.imag>0) { output<<"("< <<"+"< <<"i)"<
感悟:还行吧!!
!
!。!