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; } };

#include using namespace std;

// You can submit your code here

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; }

C++ Complex Number Class Implementation

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

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