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;
}

猜你喜欢

转载自blog.csdn.net/let_life_stop/article/details/80239655
5.8
今日推荐