#include using namespace std;

class Complex{ private: double real; double imag; public: Complex(){ real = 0; imag = 0; } Complex(double r, double i){ real = r; imag = i; } void Set(double r, double i){ real = r; imag = i; } void Show(){ cout<<real<<"+"<<imag<<"i"<<endl; } };

int main() { Complex c1; cout<<"Show object c1:"; c1.Show(); double real,imag; cin>>real>>imag; Complex c2(real,imag); cout<<"Show object c2:"; c2.Show(); cin>>real>>imag; cout<<"Reset and Show object c1:"; c1.Set(real,imag); c1.Show(); return 0;

设计复数类Complex成员数据包括实部real和虚部imag类型都是double。根据给定的main函数设计必要的成员函数。main函数已给定提交时只需要提交main函数外的代码部分#includeiostreamusing namespace std;你提交的代码在这里int main Complex c1; coutShow object c1; c1Show; do

原文地址: http://www.cveoy.top/t/topic/gTXI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录