【C++】實現一個複數類(complex)(帶有預設引數的建構函式 )
阿新 • • 發佈:2019-01-29
/*實現一個複數類(complex) class complex { private: double _real; double _image; }; */ #include <iostream> using namespace std; class complex{ public: complex(double real=10,double image=5); //帶有預設引數的建構函式 void print(); ~complex(); private: double _real; double _image; }; complex::complex(double real,double image) { _real = real; _image = image; } void complex::print() { cout << "該複數為:" << _real << "+" << "(" << _image << ")" << "i" << endl; } complex::~complex() { } int main() { complex com1; complex com2(5.2); complex com3(4.3, 2.1); com1.print(); com2.print(); com3.print(); return 0; }