📄 complex.h
字号:
#include <iostream>
using namespace std;
#ifndef COMPLEX_H
#define COMPLEX_H
class Complex
{
private:
float a,b;
public:
Complex(float x,float y);//构造函数
float Get_a();//获得实部
float Get_b();//获得虚部
void Put_a(float x);//修改实部
void Put_b(float y);//修改虚部
Complex& operator+(Complex& k);
Complex& operator-(Complex& k);
Complex& operator*(Complex& k);//各种运算
friend ostream& operator<<(ostream& out,Complex& p);//重载输出
};
Complex::Complex(float x=0,float y=0):a(x),b(y)
{}
float Complex::Get_a(){
return a;
}
float Complex::Get_b(){
return b;
}
void Complex::Put_a(float x){
a=x;
}
void Complex::Put_b(float y){
b=y;
}
Complex& Complex::operator *(Complex & k)
{
a=a*k.a+-b*k.b;
b=b*k.a+a*k.b;
return *this;
}
Complex& Complex::operator +(Complex & k)
{
a=a+k.a;
b=b+k.b;
return *this;
}
Complex& Complex::operator -(Complex& k)
{
a=a-k.a;
b=b-k.b;
return *this;
}
ostream& operator<<(ostream& out,Complex& p)
{
out<<p.a<<'+'<<p.b<<'i'<<endl;
return out;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -