您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
#include <iostream> using namespace std; class Complex { private: int real; int p_w_picpath; public: Complex(int real=0,int p_w_picpath=0):real(real),p_w_picpath(p_w_picpath) { cout<<"Complex::Complex():"<<this<<endl; } Complex(const Complex &x):real(x.real),p_w_picpath(x.p_w_picpath) { cout<<"Complex::Complex(Complex &):"<<this<<endl; } ~Complex() { cout<<"Complex::~Complex():"<<this<<endl; } Complex operator+(const Complex &c) { return Complex(real+c.real,p_w_picpath+c.p_w_picpath); } Complex operator-(const Complex &c) { return Complex(real-c.real,p_w_picpath-c.p_w_picpath); } void show()const { cout<<real; if(p_w_picpath>0) cout<<"+"; cout<<p_w_picpath<<"i"<<endl; } }; int main(int argc, char *argv[]) { Complex a(10,20); Complex b(70,80); Complex c=a+b; Complex d=a-b; a.show(); b.show(); c.show(); d.show(); return 0; }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。