您好,登錄后才能下訂單哦!
#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; } friend Complex operator+(Complex &a,Complex &b); friend Complex operator-(Complex &a,Complex &b); void show(); }; Complex operator+(Complex &a,Complex &b) { return Complex(a.real+b.real,a.p_w_picpath+b.p_w_picpath); } Complex operator-(Complex &a,Complex &b) { return Complex(a.real-b.real,a.p_w_picpath-b.p_w_picpath); } void Complex::show() { 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; }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。