#include "stdafx.h"
#include<iostream>
using namespace std;
class Complex
{
private:
double real;
double imag;
public:
Complex()//构造函数
{
real = 0; imag = 0;
}
Complex(double r, double i)//构造函数重载
{
real = r;
imag = i;
}
Complex operator+(Complex &c2);//加法
Complex operator-(Complex &c2);//减法
Complex operator*(Complex &c2);//乘法
Complex operator/(Complex &c2);//除法
void dis();//输出
};
Complex::Complex(double r, double i)
{
real = r;
imag = i;
}
Complex Complex::operator+(Complex &c2) //加法
{
Complex c;
c.real = real + c2.real;
c.imag = imag + c2.imag;
return c;
}
Complex Complex::operator-(Complex &c2)//减法
{
Complex c;
c.real = real - c2.real;
c.imag = imag - c2.imag;
return c;
}
Complex Complex::operator*(Complex &c2)//乘法
{
Complex c;
c.real = real*c2.real - imag*c2.imag;
c.imag = imag*c2.real + real*c2.imag;
return
复数的加减乘除实现
最新推荐文章于 2023-04-19 22:55:08 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)