摘要: #include using namespace std;class Complex{public: Complex();//此函数必须定义 Complex(double r,double i); friend Complex operator+(Comple... 阅读全文
posted @ 2017-05-14 17:20 衣带渐宽、为伊憔悴 阅读(128) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std;class Complex{public: Complex(); Complex(double r,double i); Complex operator+(Complex &c2); Com... 阅读全文
posted @ 2017-05-14 17:18 衣带渐宽、为伊憔悴 阅读(120) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std;class Complex{public: Complex() { real=0; imag=0; } Complex(double r,double i) { real=r;... 阅读全文
posted @ 2017-05-13 21:33 衣带渐宽、为伊憔悴 阅读(99) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std;class Complex{public: Complex(); Complex(double r,double i); double get_real(); double get_imag(... 阅读全文
posted @ 2017-05-13 21:31 衣带渐宽、为伊憔悴 阅读(152) 评论(0) 推荐(0) 编辑
摘要: //重载双目运算符,双目运算符有两个操作数,通常在运算符的左右两侧,在重载双目运算符时,在友元函数中应该有两个参数//思想:要想将运算符用于用户自定义类上,用户必须自己对运算符进行重载。要对“==”,“”三个运算符进行重载,需要重新定义3个运算符重载函数。可以将重载函... 阅读全文
posted @ 2017-05-12 21:06 衣带渐宽、为伊憔悴 阅读(460) 评论(0) 推荐(0) 编辑
摘要: •说明:有的C++编译系统(如Visual C++ 6.0)没有完全实现C++标准,它所提供不带后缀.h的头文件不支持把成员函数重载为友元函数。但是VisualC++所提供的老形式的带后缀.h的头文件可以支持此项功能,因此可以将程序头两行修改如下,即可顺利运行:#in... 阅读全文
posted @ 2017-05-12 14:16 衣带渐宽、为伊憔悴 阅读(161) 评论(0) 推荐(0) 编辑
摘要: Complex operator+(Complex &c2) { Complex c;c.real=real+c2.real;c.imag=imag+c2.imag;return c;}//+是双目运算符,函数重载中只有一个参数,实际上运算符重载函数有两个参数,是由于... 阅读全文
posted @ 2017-05-12 12:45 衣带渐宽、为伊憔悴 阅读(289) 评论(0) 推荐(0) 编辑
摘要: //对于上面的运算符重载函数operator+还可以写的更简练:Complex Complex::operator+(Complex &c2){return Complex(real+c2.real,imag+c2.imag);}//函数重载运算符的规则//(1)c+... 阅读全文
posted @ 2017-05-10 20:12 衣带渐宽、为伊憔悴 阅读(149) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std;class Complex{public: Complex(){real=0;imag=0;} Complex(int r,int i) { real=r; imag=i; } Complex comple... 阅读全文
posted @ 2017-05-10 19:55 衣带渐宽、为伊憔悴 阅读(255) 评论(0) 推荐(0) 编辑
摘要: 在非洲,蜜蜂是一个非常特殊的物种每年这个物种的一只雌性蜜蜂会产生一只雄峰,而一只雄蜂会产生一只雌蜂和雄峰,生育后他们都会死去。现在科学家发现另一只特殊的蜜蜂,他是不死的,而且仍然可以像其他蜜蜂一样每年生育一次,科学家想知道n年后会有多少只蜜蜂,现在要计算n年后... 阅读全文
posted @ 2017-05-10 18:55 衣带渐宽、为伊憔悴 阅读(144) 评论(0) 推荐(0) 编辑