【C++】实现一个复数类(complex)(带有默认参数的构造函数 )

/*实现一个复数类(complex)
class complex
{
private:
double _real;
double _image;
};
*/
#include 
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;
}
【C++】实现一个复数类(complex)(带有默认参数的构造函数 )_第1张图片

 
 

你可能感兴趣的:(带参数,C++,类,复数类,构造函数)