设计复数Complex,提供复数的修改、输入和显示功能。
#include<iostream>
using namespace std;
class Complex {
public:
void display() { cout << real << "+" << image << "i" << endl; }
void inputData() {
cout << "input real:";
cin >> real;
cout << endl << "input image:";
cin >> image;
}
void setImage(double i) { image = i; }
void setReal(double r) { real = r; }
private:
double image;
double real;
};
void main() {
Complex c1;
c1.inputData();
c1.display();
c1.setImage(9.2);
c1.setReal(5.3);
c1.display();
}