C++定义描述复数的结构体类型变量,是想复数的输入输出.设计三个函数实现复数的加法,减法和乘法运算.

问题描述:

C++定义描述复数的结构体类型变量,是想复数的输入输出.设计三个函数实现复数的加法,减法和乘法运算.

#include
using namespace std;
struct plural
{
double real,imaginary;
plural()
{
real=imaginary=0.0;
}
plural operator+(plural& s)
{
plural t;
t.real=s.real+real;
t.imaginary=s.imaginary+imaginary;
return t;
}
plural operator-(plural& s)
{
plural t;
t.real=real-s.real;
t.imaginary=imaginary-s.imaginary;
return t;
}
plural operator*(plural& s)
{
plural t;
t.real=s.real*real-s.imaginary*imaginary;
t.imaginary=real*s.imaginary+imaginary*s.real;
return t;
}
plural()
{
}
};
istream & operator>>(istream & in,plural& s)
{
printf("请输入实部:\n");
scanf("%lf",&s.real);
printf("请输入虚部:\n");
scanf("%lf",&s.imaginary);
return in;
}
ostream & operatora>>b;
c=a+b;
cout