您好,登錄后才能下訂單哦!
#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; }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。