#include <iostream>
#include <cmath>
using namespace std;
class Complex{
public:Complex(double real0=,double imaginary0=);
Complex(Complex &a);
void add(Complex b);
void show();
double mod();
private:
double real;
double imaginary;
};
Complex::Complex(double real0,double imaginary0){
real=real0;
imaginary=imaginary0;
}
Complex::Complex(Complex &a){
real=a.real;
imaginary=a.imaginary;
}
void Complex::add(Complex b){
real+=b.real;
imaginary+=b.imaginary;
}
void Complex::show(){
cout<<real<<"+"<<imaginary<<"i"<<endl;
}
double Complex::mod(){
double m;
m=sqrt(real*real+imaginary*imaginary);
return m;
}
int main()
{Complex c1(,);
cout<<"c1 = ";
c1.show();
cout<<"|c1| = " <<c1.mod() <<endl;
Complex c2(4.5);
cout<<"c2= ";
c2.show();
cout<<"|c2| = " <<c2.mod() <<endl;
Complex c3(c1);
c1.add(c2);
c1.show();
cout<<c1.mod()<<endl;
}
总结:对这个复制构造函数还是有些不太理解,实现起来的时候还是有点小困难的,通过同学的帮助还是顺利做出来了。希望自己接下来能继续好好理解摸透每一个程序背后的意义,做到深入理解。
https://www.cnblogs.com/libing-072921/p/10631162.html
https://www.cnblogs.com/jiyuanxiangzhouziying/p/10630503.html
https://www.cnblogs.com/ggwdcs/p/10631615.html