# 第八周任务一（2）

#include <iostream>

using namespace std;
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
friend Complex operator+(Complex &c1,Complex &c2);
friend Complex operator-(Complex &c1,Complex &c2);
friend Complex operator*(Complex &c1,Complex &c2);
friend Complex operator/(Complex &c1,Complex &c2);
void display();
private:
double real;
double imag;
};
//下面定义成员函数
Complex operator+(Complex &c1,Complex &c2)
{
return Complex (c1.real + c2.real,c1.imag + c2.imag);
}
Complex operator-(Complex &c1,Complex &c2)
{
return Complex (c1.real - c2.real,c1.imag - c2.imag);
}
Complex operator*(Complex &c1,Complex &c2)
{
Complex c;

c.real = c1.real * c2.real - c1.imag * c2.imag;
c.imag = c1.real * c2.imag + c1.imag * c2.real;

return c;
}
Complex operator/(Complex &c1,Complex &c2)
{
Complex c;

c.real = (c1.real * c2.real + c1.imag * c2.imag)/(c2.imag * c2.imag + c2.real * c2.real);
c.imag = (c1.imag * c2.real - c1.real * c2.imag)/(c2.imag * c2.imag + c2.real * c2.real);

return c;
}

void Complex::display()
{
cout << "(" << real << "," << imag << "i)" << endl;
}
int main()
{
Complex c1(3,4),c2(5,-10),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();
system("pause");
return 0;
}


#### coursera Machine Learning 第八周 测验quiz2答案解析 Principal Component Analysis

2017-12-23 16:27:08

#### mooc c语言第八周编程

2017-06-01 09:36:39

#### coursera机器学习课程第八周——课程笔记（一）

2017-11-30 18:42:14

#### Coursera Machine Learning 第八周 quiz Unsupervised Learning

2016-11-12 19:46:25

#### Coursera机器学习-第八周-Unsupervised Learning(K-Means)

2016-06-12 09:30:10

#### Coursera Machine Learning 第八周 quiz Programming Exercise 7 K-means Clustering and Principal Component

2016-11-13 00:13:23

#### 斯坦福公开课machine learning机器学习第八周编程作业ex7

2015年11月04日 10.86MB 下载

#### Coursera机器学习第8周作业

2016-04-26 09:52:36

#### Coursera—machine learning(Andrew Ng)第八周编程作业

2017-12-08 17:42:36

#### 第八周任务一2

2012-04-09 19:09:52