日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > c/c++ >内容正文

c/c++

C++学习(10)

發(fā)布時(shí)間:2023/12/20 c/c++ 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++学习(10) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1 //設(shè)計(jì)運(yùn)算符重載的復(fù)數(shù)類 2 #include<iostream.h> 3 4 class Complex{ 5 private: 6 double real;//實(shí)部 7 double image;//虛部 8 public: 9 Complex(){ 10 real=0; 11 image=0; 12 } 13 Complex(double real){ 14 this->real=real; 15 image=0; 16 } 17 Complex(double real,double image){ 18 this->real=real; 19 this->image=image; 20 } 21 ~Complex(){} 22 23 Complex operator+(const Complex &x)const; 24 Complex operator-(const Complex &x)const; 25 Complex operator*(const Complex &x)const; 26 Complex operator/(const Complex &x)const; 27 bool operator==(const Complex &x)const; 28 Complex &operator+=(const Complex &x); 29 void Print(); 30 }; 31 32 inline Complex Complex::operator+(const Complex &x)const{ 33 return Complex(this->real+x.real,this->image+x.image); 34 } 35 36 inline Complex Complex::operator-(const Complex &x)const{ 37 return Complex(this->real-x.real,this->image-x.image); 38 } 39 40 inline Complex Complex::operator*(const Complex &x)const{ 41 return Complex(this->real*x.real-this->image*x.image,this->real*x.image+this->image*x.real); 42 } 43 44 inline Complex Complex::operator/(const Complex &x)const{ 45 double m; 46 m=x.real*x.real+x.image*x.image; 47 return Complex((this->real*x.real+this->image*x.image)/m,(this->image*x.real-this->real*x.image)/m); 48 } 49 50 inline bool Complex::operator==(const Complex &x)const{ 51 return bool(this->real==x.real&&this->image==x.image); 52 } 53 54 Complex &Complex::operator+=(const Complex &x){ 55 this->real+=x.real; 56 this->image+=x.image; 57 return *this; 58 } 59 void Complex::Print(){ 60 cout<<"("<<this->real<<","<<this->image<<"i)"<<endl; 61 } 62 63 int main(){ 64 Complex a(3,5),b(2,3),c; 65 c=a+(b*a)/b-b; 66 c.Print(); 67 68 //a=a/b; 69 // a.Print(); 70 return 0; 71 }

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/Tobi/p/9245000.html

總結(jié)

以上是生活随笔為你收集整理的C++学习(10)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。