用类实现一个复数类。
#include<iostream>
using namespace std;
class Complex{
private:
double real;
double image;
public:
void set_complex(double Real,double Image){
real=Real;
image=Image;
}
void display(){
if(image>0){
cout<<real<<"+"<<image<<"i"<<endl;
}
else{
cout<<real<<image<<"i"<<endl;
}
}
};
int main(){
double x,y;
Complex a;
cin>>x>>y;
while(x!=0&&y!=0){
a.set_complex(x,y);
a.display();
cin>>x>>y;
}
}