5.8上机

#include<iostream>
using namespace std;
class Complex
{
double a;
double b;
public:
Complex(double w=0,double d=0):a(w),b(d){}
double GetA(){return a;}
double GetB(){return b;}
Complex operator + (Complex &);
Complex operator + (double d);
Complex operator - (Complex &);
Complex operator - (double t1);
Complex operator * (Complex &);
Complex operator * (double t2);
Complex operator / (Complex &);
Complex operator / (double t3);
Complex operator = (Complex);
};


Complex Complex::operator + (Complex &s)
{
Complex temp;
temp.a=a+s.a;
temp.b=b+s.b;
return temp;
}


Complex Complex::operator + (double d)
{
Complex temp;
temp.a=a+d;
temp.b=b;
return temp;
}
Complex Complex::operator - (Complex &s)
{
Complex temp;
temp.a=a-s.a;
temp.b=b-s.b;
return temp;
}
Complex Complex::operator - (double t1)
{
Complex temp;
temp.a=a-t1;
temp.b=b;
return temp;
}
Complex Complex::operator * (double t2)
{
Complex temp;
temp.a=a*t2;
temp.b=b*t2;
return temp;
}
Complex Complex::operator * (Complex &s)
{
Complex temp;
temp.a=a*s.a;
temp.b=b*s.b;
return temp;
}


Complex Complex::operator / (double t3)
{
Complex temp;
temp.a=a/t3;
temp.b=b;
return temp;
}
Complex Complex::operator / (Complex &s)
{
Complex temp;
temp.a=a/s.a;
temp.b=b/s.b;
return temp;
}
Complex Complex::operator = (Complex c)
{
a=c.a;
b=c.a;
return *this;
}
int main()
{
double  t1,t2,t3,t4,d,f;;
cin>>t1>>t2>>t3>>t4;
Complex c1(t1,t2),c2(t3,t4),c3,c4,c5,c6;
cout<<c1.GetA()<<" "<<c1.GetB()<<endl;
cout<<c2.GetA()<<" "<<c2.GetB()<<endl;
c3=c1+c2;
cout<<c3.GetA()<<" "<<c3.GetB()<<endl;
c4=c1-c2;
cout<<c4.GetA()<<" "<<c3.GetB()<<endl;
cin>>d;
c5=c1*d;
cout<<c5.GetA()<<" "<<c5.GetB()<<endl;
cin>>f;
c6=c1/f;
cout<<c6.GetA()<<" "<<c6.GetB()<<endl;
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值