定义一个名为complex的复数类,其属性数据为复数的实部和虚部,
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/09 06:44:07
定义一个名为complex的复数类,其属性数据为复数的实部和虚部,
要求构造函数和拷贝构造函数使用,并定义成员函数打印复数的值
要求构造函数和拷贝构造函数使用,并定义成员函数打印复数的值
//Complex.h
class Complex
{
private:
float Real;
float Imag;
public:
Complex();
Complex(float Rl,float Im);
Complex operator +(Complex &c);
Complex operator -(Complex &c);
Complex operator *(Complex &c);
Complex operator /(Complex &c);
void GetValue();
};
//Complex.cpp
#include
#include "Complex.h"
void main()
{
Complex c1(1,1);
Complex c2(1,-1);
Complex c3;
c3 = c1+c2;
c3.GetValue();
c3 = c1-c2;
c3.GetValue();
c3 = c1*c2;
c3.GetValue();
c3 = c1/c2;
c3.GetValue();
return;
}
////////////////////////////////////////////////////////
Complex::Complex()
{
Real = 0;
Imag = 0;
}
/////////////////////////////////////////////////////////
Complex::Complex(float Rl,float Im)
{
Real = Rl;
Imag = Im;
}
////////////////////////////////////////////////////////
inline Complex Complex::operator +(Complex &c)
{
Complex x;
x.Real = Real+c.Real;
x.Imag = Imag+c.Imag;
return x;
}
///////////////////////////////////////////////////////
inline Complex Complex::operator -(Complex &c)
{
Complex x;
x.Real = Real-c.Real;
x.Imag = Imag-c.Imag;
return x;
}
///////////////////////////////////////////////////////
inline Complex Complex::operator *(Complex &c)
{
Complex x;
x.Real = Real*c.Real-Imag*c.Imag;
x.Imag = Imag*c.Real+c.Imag*Real;
return x;
}
///////////////////////////////////////////////////////
inline Complex Complex::operator /(Complex &c)
{
/*(a+bi)/(c+di)
=(a+bi)*(c-di)/(c+di)*(c-di)
=(ac+adi+bci+bd)/(c*c+d*d)
*/
Complex x;
x.Real = (Real*c.Real-Imag*(-c.Imag))/(c.Real*c.Real+c.Imag*c.Imag);
x.Imag = (Real*(-c.Imag)+Imag*c.Real)/(c.Real*c.Real+c.Imag*c.Imag);
return x;
}
///////////////////////////////////////////////////////
void Complex::GetValue()
{
cout
class Complex
{
private:
float Real;
float Imag;
public:
Complex();
Complex(float Rl,float Im);
Complex operator +(Complex &c);
Complex operator -(Complex &c);
Complex operator *(Complex &c);
Complex operator /(Complex &c);
void GetValue();
};
//Complex.cpp
#include
#include "Complex.h"
void main()
{
Complex c1(1,1);
Complex c2(1,-1);
Complex c3;
c3 = c1+c2;
c3.GetValue();
c3 = c1-c2;
c3.GetValue();
c3 = c1*c2;
c3.GetValue();
c3 = c1/c2;
c3.GetValue();
return;
}
////////////////////////////////////////////////////////
Complex::Complex()
{
Real = 0;
Imag = 0;
}
/////////////////////////////////////////////////////////
Complex::Complex(float Rl,float Im)
{
Real = Rl;
Imag = Im;
}
////////////////////////////////////////////////////////
inline Complex Complex::operator +(Complex &c)
{
Complex x;
x.Real = Real+c.Real;
x.Imag = Imag+c.Imag;
return x;
}
///////////////////////////////////////////////////////
inline Complex Complex::operator -(Complex &c)
{
Complex x;
x.Real = Real-c.Real;
x.Imag = Imag-c.Imag;
return x;
}
///////////////////////////////////////////////////////
inline Complex Complex::operator *(Complex &c)
{
Complex x;
x.Real = Real*c.Real-Imag*c.Imag;
x.Imag = Imag*c.Real+c.Imag*Real;
return x;
}
///////////////////////////////////////////////////////
inline Complex Complex::operator /(Complex &c)
{
/*(a+bi)/(c+di)
=(a+bi)*(c-di)/(c+di)*(c-di)
=(ac+adi+bci+bd)/(c*c+d*d)
*/
Complex x;
x.Real = (Real*c.Real-Imag*(-c.Imag))/(c.Real*c.Real+c.Imag*c.Imag);
x.Imag = (Real*(-c.Imag)+Imag*c.Real)/(c.Real*c.Real+c.Imag*c.Imag);
return x;
}
///////////////////////////////////////////////////////
void Complex::GetValue()
{
cout
定义一个名为complex的复数类,其属性数据为复数的实部和虚部,
定义一个名为complex 的复数类,其属性数据为复数的实部和虚部,要求构造函数和拷贝构造函数,并能打印复数
定义一个复数类,其属性为复数的实部和虚部
c++ 定义饼实现一个复数类 有实部和虚部两个属性用成员函数实现复数的模
定义这个复数类,复数的实部与虚部定义为私有数据成员.用复数类定义两个复数对象,
用Java定义一个复数类complex,它的内部具有两个实例变量:realPart和imagPart,分别代表复数的实部
定义一个描述复数的类,数据成员包括实部和虚部;成员函数包括:输出复数、置实部、
实现复数类Complex的定义,包括实部m_Real和虚部m_Image;必须包括如下成员函数:
c++问题: 定义一个名为rectangle的矩形类,其属性数据为矩形左上角和右下角的点的坐标,能计算矩形的面积
1、 设计一个复数类Complex,包括实部real和虚部image,设计3个友元函数,实现两个复数的加、减和乘法运算
定义一个描述复数的类,数据成员包括实部和虚部;成员函数包括输出复数以及构造函数的初始化.
定义一个复数类COMPLEX,重载运算符“+”使之用于复数的加减运算