用C++编写复数计算器的程序【基本要求】为复数定义一个类,设计一个小型复数计算器,实现复数的设置和现实;实现附属加减乘除功能;实现用运算符==进行复数的相等比较,并显示比较结果.
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 10:04:40
用C++编写复数计算器的程序【基本要求】为复数定义一个类,设计一个小型复数计算器,实现复数的设置和现实;实现附属加减乘除功能;实现用运算符==进行复数的相等比较,并显示比较结果.
用C++编写复数计算器的程序
【基本要求】
为复数定义一个类,设计一个小型复数计算器,实现复数的设置和现实;实现附属加减乘除功能;实现用运算符==进行复数的相等比较,并显示比较结果.
【测试数据】
2,2+3i,2-3i,5i,-8i,i,-i
要有注释的更好哦
用C++编写复数计算器的程序【基本要求】为复数定义一个类,设计一个小型复数计算器,实现复数的设置和现实;实现附属加减乘除功能;实现用运算符==进行复数的相等比较,并显示比较结果.
#include
#include
using namespace std;
class Complex{
private:
double m_real;
double m_complex;
public://各个函数的定义.
Complex(double real=0.0,double complex=0.0);
void Setnumber();
Complex operator+(Complex &object);
Complex operator-(Complex&);
Complex operator*(Complex &);
Complex operator/(Complex &);
bool operator==(Complex &);
void Display();
};
Complex::Complex(double real,double complex)
{
m_real=real;
m_complex=complex;
}
void Complex::Setnumber()//定义设置函数.
{
/*coutm_real;
coutm_complex;*/
string s;
int i=1,flag=2,flag1=0;
m_real=m_complex=0;
couts;
while(im_real+object.m_real ;
temp.m_complex=this->m_complex+object.m_complex;
return temp;
}
Complex Complex::operator-(Complex &object)
{
Complex temp;
temp.m_real=this->m_real +object.m_real ;
temp.m_complex=this->m_complex +object.m_complex ;
return temp;
}
Complex Complex::operator *(Complex &object)
{
Complex temp;
temp.m_real=this->m_real *object.m_real -this->m_complex *object.m_complex ;
temp.m_complex =this->m_complex*object.m_real +this->m_real *object.m_complex ;
return temp;
}
Complex Complex::operator /(Complex &object)
{
Complex temp;
temp.m_real =this->m_real *object.m_real +this->m_complex *object.m_complex ;
temp.m_complex =this->m_complex*object.m_real -this->m_real *object.m_complex ;
temp.m_real /=object.m_real *object.m_real +object.m_complex *object.m_complex ;
temp.m_complex/=object.m_real *object.m_real +object.m_complex *object.m_complex ;
return temp;
}
bool Complex::operator ==(Complex &object)
{
if(this->m_real==object.m_real &&this->m_complex ==object.m_complex )
return (cout