编写一个简单的复数的加减法计算程序
下面是我写的代码,求指点错误。#include<iostream>
using namespace std;
class dlbcomplex
{public:
dlbcomplex(){real=0;imag=0;}
dlbcomplex(int r,int i):real(r),imag(i){}
dlbcomplex operator +(dlbcomplex &);
dlbcomplex operator -(dlbcomplex &);
friend istream& operator >>(istream&,dlbcomplex&);
void display();
private:
int real;
int imag;
};
dlbcomplex dlbcomplex::operator +(dlbcomplex &c2)
{return dlbcomplex(real+c2.real,imag+c2.imag);
}
dlbcomplex dlbcomplex::operator -(dlbcomplex &c2)
{return dlbcomplex(real-c2.real,imag-c2.imag);
}
void dlbcomplex::display()
{
cout<<real<<"+"<<imag<<endl;
}
istream& operator >>(istream &input,dlbcomplex &c3)
{
input<<c3.real<<"+"<<c3.imag<<endl;
return input;
}
int main()
{
dlbcomplex c1,c2,c3;
cout<<输入你要计算的两个复数<<endl;
cin>>c1;
cin>>c2;
char a;
cout<<给出你要的计算方式<<endl;
cin>>a;
if(a=="+")
{c3=c1+c2;
c3.display();
}
else
{c3=c1-c2;
c3.display();
}
return(0);
}