课堂练习
作者:互联网
#include<iostream> #include<cmath> using namespace std; class Complex{ public: Complex(double A=0,double B=0) ; Complex(Complex &c2); void add(Complex c2); void show(); double Q(); private: double imaginary,real; }; Complex::Complex(double A,double B){ real=A; imaginary=B; } Complex::Complex(Complex &c2){ real=c2.real; imaginary=c2.imaginary; } void Complex::add(Complex c) { real+=c.real; imaginary+=c.imaginary; } double Complex::Q(){ double M; M=sqrt(real*real+imaginary*imaginary); return M; } void Complex::show(){ cout<<real<<"+"<<imaginary<<"i"<<endl; } int main(){ Complex c1(3,5); Complex c2(4.5); Complex c3(c1); c1.add(c2); c1.show(); c3.show(); cout<<c1.Q()<<endl; return 0; }
标签:real,课堂练习,double,void,Complex,c2,imaginary 来源: https://www.cnblogs.com/cjj1/p/10645565.html