作业帮 > 综合 > 作业

要求建立复数类,包括复数的实部虚部,和对复数进行加减乘除运算的函数.使用MFC,编写基于对话框的Windo

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/05/25 20:11:17
要求建立复数类,包括复数的实部虚部,和对复数进行加减乘除运算的函数.使用MFC,编写基于对话框的Windo
要求建立复数类,包括复数的实部虚部,和对复数进行加减乘除运算的函数.使用MFC,编写基于对话框的Windo
#include "stdafx.h"
#include<iostream>
using namespace std;
class complex
{
protected:
double real;
double image;
public:
complex(double r=0,double i=0);
complex(const complex&other);
void print();
complex operator-(const complex&other);
};
complex::complex(double r,double i)
{
real=r;
image=i;
}
complex::complex(const complex &other)
{
real=other.real;
image=other.image;
}
void complex::print()
{
cout<<real;
if(image>0)
{
cout<<"+"<<image<<"i"<<endl;
}
else
{
cout<<image<<"i"<<endl;
}
cout<<"--------------"<<endl;
}
complex complex::operator-(const complex &other)
{
complex temp;
temp.real=real-other.real;
temp.image=image-other.image;
return temp;
}
void main()
{
complex c1(1.1,2.2);
complex c2(3,-4);
c1.print();
c2.print();
complex c3;
c3=c1-c2;
c3.print();
}
另外,虚机团上产品团购,超级便宜