复数类

//// 实现一个复数类,实现以下成员函数
//class Complex
//{
//public:
//	// 带缺省值的构造函数
//	Complex(double real = 0, double image = 0);
//	// 析构函数
//	~Complex();
//	// 拷贝构造函数
//	Complex(const Complex& d);
//	// 赋值运算符重载
//	Complex& operator= (const Complex& d);
//	void Display();
//
//public:
//	Complex& operator++();
//	Complex operator++(int);
//	Complex& operator--();
//	Complex operator--(int); //后置--
//
//	Complex operator+(const Complex& c);
//	Complex operator-(const Complex& c);
//
//	Complex& operator-=(const Complex& c);
//	Complex& operator+=(const Complex& c);
//
//	Complex operator*(const Complex& c);
//	Complex operator/(const Complex& c);
//
//private:
//	double _real;		// 实部
//	double _image;		// 虚部
//};
//
//void TestComplex()
//{
//	Complex c1(2.2, 1.1);
//}




#include<iostream>
using namespace std;
class Complex
{
public:
	Complex(double real = 0, double image = 0);
	~Complex();
	Complex(const Complex& d);
	Complex& operator++();
	Complex operator++(int);
	Complex& operator--();
	Complex operator--(int); //后置--
	Complex& operator= (const Complex& d);
	Complex operator+(const Complex& c);
	Complex operator-(const Complex& c);
	Complex& operator+=(const Complex& c);
	Complex& operator-=(const Complex& c);
	Complex operator*(const Complex& c);
	Complex operator/(const Complex& c);
	void Display();
private:
	double _real;		// 实部
	double _image;		// 虚部
};

Complex::Complex(double real, double image)
{
	cout << "构造函数:" << endl;
	_real = real;
	_image = image;
}
Complex::~Complex()
{
	cout << "析构函数:" << endl;
}
Complex::Complex(const Complex& d)
{
	cout << "拷贝构造函数:" << endl;
	_real = d._real;
	_image = d._image;
}
Complex& Complex::operator= (const Complex& d)
{
	cout << "赋值运算符:" << endl;
	_real = d._real;
	_image = d._image;
	return *this;
}
void Complex::Display()  //显示
{
	cout << _real;
	if (_image > 0)
	{
		cout << "+";
	}
	cout<< _image << "i" << endl;
}
Complex& Complex::operator++()
{
	cout << "前置++:" << endl;
	++_real;
	++_image;
	return *this;
}
Complex Complex::operator++(int)
{
	cout << "后置++:" << endl;
	Complex tmp(*this);
	_real++;
	_image++;
	return tmp;
}
Complex& Complex::operator--()
{
	cout << "前置--:" << endl;
	--_real;
	--_image;
	return *this;
}
Complex Complex::operator--(int)
{
	cout << "后置--:" << endl;
	Complex tmp(*this);
	_real--;
	_image--;
	return tmp;
}

Complex Complex::operator+(const Complex& c)
{
	cout << "加法运算符重载:" << endl;
	Complex tmp;
	tmp._real = _real + c._real;
	tmp._image = _image + c._image;
	return tmp;
}
Complex Complex::operator-(const Complex& c)
{
	cout << "减法运算符重载:" << endl;
	Complex tmp;
	tmp._real = _real -c._real;
	tmp._image = _image - c._image;
	return tmp;
}
Complex& Complex::operator+=(const Complex& c)
{
	cout << "+=运算符重载:" << endl;
	/*_real = _real + c._real;
	_image = _image + c._image;
	return *this;*/
	return (*this) = (*this + c);
}
Complex& Complex::operator-=(const Complex& c)
{
	cout << "-=运算符重载:" << endl;
	/*_real = _real - c._real;
	_image = _image - c._image;
	return *this;*/
	return (*this) = (*this - c);
}
Complex Complex::operator*(const Complex& c)
{
	cout << "*运算符重载:" << endl;
	Complex tmp;
	tmp._real = _real*c._real - _image*c._image;
	tmp._image = _image*c._real + _real*c._image;
	return tmp;
}
Complex Complex::operator/(const Complex& c)
{
	cout << "/运算符重载:" << endl;
	Complex tmp;
	double t = c._real*c._real + c._image*c._image;
	tmp._real = (_real*c._real+ _image*c._image)/t;
	tmp._image = (_image*c._real - _real*c._image)/t;
	return tmp;
}
int main()
{
	Complex op1(2.2, 1.1);
	Complex op2(1.5, 2.6);
	op1.Display();
	op1 += op2;
	op1.Display();
	/*op1.Display();
	Complex op2(op1);
	op2.Display();
	Complex op3;
	op3 = op1;
	op3.Display();
	Complex op4;
	op4=op1.operator+(op1);
	op4.Display();
	Complex op5;
	op5 = op4.operator-(op1);
	op5.Display();
	Complex op6;
	Complex op7(5.2, 3.6);
	op1 = op1.operator-=(op7);
	op1.Display();
	Complex op8(2.3, 4.6);
	Complex op9(3.6,2.8);
	Complex op10;
	op10 = op8.operator*(op9);
	op10.Display();
	op10 = op8.operator/(op9);
	op10.Display();*/
	//op1 = op1.operator--();
	/*op1.Display();
	Complex op2;
	op2 = op1++;
	op2.Display();
	op1.Display();*/
	system("pause");
	return 0;
}

【博士论文复现】【阻抗建模、验证扫频法】光伏并网逆变器扫频与稳定性分析(包含锁相环电流环)(Simulink仿真实现)内容概要:本文档围绕“博士论文复现”主题,重点介绍了光伏并网逆变器的阻抗建模与扫频法稳定性分析,涵盖锁相环和电流环的Simulink仿真实现。文档旨在通过完整的仿真资源和代码帮助科研人员复现相关技术细节,提升对新能源并网系统动态特性和稳定机制的理解。此外,文档还提供了大量其他科研方向的复现资源,包括微电网优化、机器学习、路径规划、信号处理、电力系统分析等,配套MATLAB/Simulink代码与模型,服务于多领域科研需求。; 适合人群:具备一定电力电子、自动控制或新能源背景的研究生、博士生及科研人员,熟悉MATLAB/Simulink环境,有志于复现高水平论文成果并开展创新研究。; 使用场景及目标:①复现光伏并网逆变器的阻抗建模与扫频分析过程,掌握其稳定性判据与仿真方法;②借鉴提供的丰富案例资源,支撑博士论文或期刊论文的仿真实验部分;③结合团队提供的算法与模型,快速搭建实验平台,提升科研效率。; 阅读建议:建议按文档目录顺序浏览,优先下载并运行配套仿真文件,结合理论学习与代码调试加深理解;重点关注锁相环与电流环的建模细节,同时可拓展学习其他复现案例以拓宽研究视野。
评论 6
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值