#include <iostream>
using namespace std;
class Complex{
public:
Complex()
{
real=0;
imag=0;
}
Complex(double r,double i)
{
real=r;
imag=i;
}
double getreal()
{
return real;
}
double getimag()
{
return imag;
}
void display()
{
cout<<"("<<real<<"+"<<imag<<"i)"<<endl;
}
private:
double real;
double imag;
};
Complex operator +(Complex &c1,Complex &c2)
{
return Complex(c1.getreal()+c2.getreal(),c1.getimag()+c2.getimag());
}
int main()
{
Complex c1(1,2),c2(3,4),c3;
c3=c1+c2;
cout<<"c3=";
c3.display();
return 0;
}
4-1
最新推荐文章于 2023-02-22 15:14:19 发布