要求建立复数类,包括复数的实部虚部,和对复数进行加减乘除运算的函数.使用MFC,编写基于对话框的Windo
来源:学生作业帮助网 编辑:作业帮 时间:2024/06/21 03:25:21
![要求建立复数类,包括复数的实部虚部,和对复数进行加减乘除运算的函数.使用MFC,编写基于对话框的Windo](/uploads/image/z/12379949-53-9.jpg?t=%E8%A6%81%E6%B1%82%E5%BB%BA%E7%AB%8B%E5%A4%8D%E6%95%B0%E7%B1%BB%2C%E5%8C%85%E6%8B%AC%E5%A4%8D%E6%95%B0%E7%9A%84%E5%AE%9E%E9%83%A8%E8%99%9A%E9%83%A8%2C%E5%92%8C%E5%AF%B9%E5%A4%8D%E6%95%B0%E8%BF%9B%E8%A1%8C%E5%8A%A0%E5%87%8F%E4%B9%98%E9%99%A4%E8%BF%90%E7%AE%97%E7%9A%84%E5%87%BD%E6%95%B0.%E4%BD%BF%E7%94%A8MFC%2C%E7%BC%96%E5%86%99%E5%9F%BA%E4%BA%8E%E5%AF%B9%E8%AF%9D%E6%A1%86%E7%9A%84Windo)
要求建立复数类,包括复数的实部虚部,和对复数进行加减乘除运算的函数.使用MFC,编写基于对话框的Windo
要求建立复数类,包括复数的实部虚部,和对复数进行加减乘除运算的函数.使用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();
}
另外,虚机团上产品团购,超级便宜