标签:技术 img void mic oid iostream pac ble space
#include <iostream> #include <cmath> using namespace std; class Complex{ public: Complex(double real0,double imaginary0); Complex(double real0); 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(double real0):real(real0){ } Complex::Complex(Complex &a) { real=a.real;imaginary=a.imaginary;} void Complex::add(Complex b){ real=real+b.real; imaginary=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(3,5); Complex c2(4.5); Complex c3(c1); c1.add(c2); c1.show(); cout<<c1.mod(); return 0; }
标签:技术 img void mic oid iostream pac ble space
原文地址:https://www.cnblogs.com/hongzai1206/p/10637325.html