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

发布时间:2021-02-25 10:00:00

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

网友回答

#include stdafx.h
#include<iostream>
using namespace std;
class plex
{protected:
double real;
double image;
public:
plex(double r=0,double i=0);
plex(const plex&other);
void print();
plex operator-(const plex&other);
};plex::plex(double r,double i)
{real=r;
image=i;
}plex::plex(const plex &other)
{real=other.real;
image=other.image;
}void plex::print()
{cout<<real;
if(image>0)
{cout<<+<<image<<i<<endl;
}else{cout<<image<<i<<endl;
}cout<<--------------<<endl;
}plex plex::operator-(const plex &other)
{plex temp;
temp.real=real-other.real;
temp.image=image-other.image;
return temp;
}void main()
{plex c1(1.1,2.2);
plex c2(3,-4);
c1.print();
c2.print();
plex c3;
c3=c1-c2;
c3.print();
}另外,虚机团上产品团购,超级便宜
以上问题属网友观点,不代表本站立场,仅供参考!