多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內(nèi)最全I(xiàn)T社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php開源 > php教程 > 第八周項目-1.3

第八周項目-1.3

來源:程序員人生   發(fā)布時間:2015-05-27 08:22:56 閱讀次數(shù):2441次
#include<iostream>
using namespace std;
class Complex
{
public:
Complex(){ real = 0; imag = 0; }
Complex(double r, double i){ real = r; imag = i; }
Complex operator+(const Complex &c2);
Complex operator-(const Complex &c2);
Complex operator*(const Complex &c2);
Complex operator/(const Complex &c2);
friend Complex operator+(const double &c1,const Complex &c2);
friend  Complex operator-(const double &c1,const Complex &c2);
friend Complex operator*(const double &c1,const Complex &c2);
friend Complex operator/(const double &c1,const Complex &c2);
friend Complex operator+(const Complex &c1,const double &c2);
friend  Complex operator-(const Complex &c1,const double &c2);
friend Complex operator*(const Complex &c1,const double &c2);
friend Complex operator/(const Complex &c1,const double &c2);
void display();
private:
double real;
double imag;
};
//下面定義成員函數(shù)
Complex Complex::operator+(const Complex &c2)
{
return Complex(real + c2.real, imag + c2.imag);
}
Complex Complex::operator-(const Complex &c2)
{
return Complex(real - c2.real, imag - c2.imag);
}
Complex Complex::operator*(const Complex &c2)
{
return Complex(real*c2.real - imag*c2.imag, real*c2.imag + imag*c2.real);
}
Complex Complex::operator/(const Complex &c2)//(ac+bd)/(c^2+d^2)+〔(bc-ad)/(c^2+d^2)〕i
{
return Complex((real*c2.real + imag*c2.imag) / (c2.real*c2.real + c2.imag*c2.imag), (imag*c2.real - real*c2.imag) / (c2.real*c2.real + c2.imag*c2.imag));
}
Complex operator+(const double &c1, const Complex &c2)
{
return Complex(c1 + c2.real, c2.imag);
}
Complex operator-(const double &c1, const Complex &c2)
{
return Complex(c1 - c2.real, c2.imag);
}
Complex operator*(const double &c1, const Complex &c2)
{
return Complex(c1 * c2.real, c2.imag);
}
Complex operator/(const double &c1, const Complex &c2)
{
return Complex(c1 / c2.real, c2.imag);
}
Complex operator+(const Complex &c1, const double &c2)
{
return Complex(c1.real + c2, c1.imag);
}
Complex operator-(const Complex &c1, const double &c2)
{
return Complex(c1.real - c2, c1.imag);
}
Complex operator*(const Complex &c1, const double &c2)
{
return Complex(c1.real * c2, c1.imag);
}
Complex operator/(const Complex &c1, const double &c2)
{
return Complex(c1.real / c2, c1.imag);
}
void Complex::display()
{
if (imag == 0)
cout << real << endl;
else if (imag < 0)
cout << real << " - " << -imag << "i" << endl;
else
cout << real << " + " << imag << "i" << endl;
}
//下面定義用于測試的main()函數(shù)
int main()
{
Complex c1(3, 4), c2(5, ⑴0), c3;
cout << "c1=";
c1.display();
cout << "c2=";
c2.display();
c3 = c1 + c2;
cout << "c1+c2=";
c3.display();
c3 = c1 - c2;
cout << "c1-c2=";
c3.display();
c3 = c1*c2;
cout << "c1*c2=";
c3.display();
c3 = c1 / c2;
cout << "c1/c2=";
c3.display();
c3 = c1 + 3;
cout << "c1 + 3=";
c3.display();
c3 = ⑸ + c2;
cout << "⑸ + c2=";
c3.display();//-----------------------  +
c3 = c1 - 3;
cout << "c1 - 3=";
c3.display();
c3 = ⑸ - c2;
cout << "⑸ - c2=";
c3.display();//----------------------  -
c3 = c1 * 3;
cout << "c1 * 3=";
c3.display();
c3 = ⑸ * c2;
cout << "⑸ * c2=";
c3.display();//----------------------  *
c3 = c1 / 3;
cout << "c1 / 3=";
c3.display();
c3 = ⑸ / c2;
cout << "⑸ / c2=";
c3.display();//---------------------  /
while (1){}
return 0;
}
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 亚洲欧美色综合自拍 | 亚洲你xx我xx网站 | 久久手机看片 | 日本免费一区二区三区最新vr | 久操网在线 | 久久77777 | 欧美日韩亚洲一区二区精品 | 国产中文字幕第一页 | 97久久精品国产成人影院 | 亚洲第一视频在线观看 | 精品国产福利在线观看网址2022 | 国产精品久久久亚洲 | 亚洲成人偷拍自拍 | 在线亚洲小视频 | 国产精品嫩草影院99av视频 | 毛片传媒| 国产成人精品本亚洲 | 一区二区三区四区 | 中文字幕欧美日韩 | 成人自拍小视频 | 国产中文字幕视频在线观看 | 欧美成人看片一区二区三区 | 韩国女主播一区二区三区视频 | 最好的中文字幕2018免费视频 | 男女一区二区三区免费 | 午夜成人免费视频 | 羞羞视频免费观看网站 | 亚洲精品一区91 | 美国一级毛片片aa免 | 亚欧成人一区二区 | 69国产成人精品视频软件 | 一级日韩| 2020亚洲天堂 | 福利国产| 国产综合在线观看视频 | 日本爱爱视频 | 国产一区欧美二区 | 亚洲欧美日韩中文字幕一区二区三区 | 亚洲综合图片 | 好好的日视频www | 精品久久久久国产免费 |