其他分享
首页 > 其他分享> > 课堂测试

课堂测试

作者:互联网


#include <iostream> #include <cmath> using namespace std; class complex{ public: complex(double real1=0,double imaginary1=0); complex(complex &t); void add(complex a); void show(); double mod(); private: double real; double imaginary; }; complex::complex(double real1,double imaginary1){ real=real1; imaginary=imaginary1; } complex::complex(complex &t){ real=t.real; imaginary=t.imaginary; } void complex::add(complex a){ real=real+a.real; imaginary+=a.imaginary; } void complex::show(){ cout<<real<<"+"<<imaginary<<"i"<<endl; } double complex::mod(){ cout<<sqrt(real*real+imaginary*imaginary)<<endl; } int main() {complex c1(3,5); complex c2(4.5); complex c3(c1); c1.add(c2); c1.show(); c1.mod(); return 0; }

课堂小结:在第一个complexcomplex那里,因为少写了两个1,所以卡了很久,不过在同学的帮助下明白了原因。

 

https://www.cnblogs.com/0122Frank/p/10587023.html#4219744

https://www.cnblogs.com/sqcmxg/p/10574927.html

https://www.cnblogs.com/csl-40/p/10583521.html

标签:real,imaginary1,double,void,complex,测试,课堂,imaginary
来源: https://www.cnblogs.com/elise00/p/10637773.html