shiyan9_1.cpp

来自「学习c++的一些实例程序」· C++ 代码 · 共 41 行

CPP
41
字号
#include<iostream.h>
class Rect
{
public:
	int Area_int();
	double Area_double();
	Rect(double l,double w);
	Rect(int l,int w);
	virtual ~Rect();
	int nLength;
	int nWidth;
	double dLength;
	double dWidth;
};
Rect::Rect(int l,int w)
{
	nLength=l;
	nWidth=w;
	cout<<"I am the constructor to build a INT rect."<<endl;
}
Rect::Rect(double l,double w)
{
	dLength=l;
	dWidth=w;
	cout<<"I am the constructor to build a DOUBLE rect."<<endl;
}
Rect::~Rect()
{ cout<<"I am the destructor."<<endl;}
int Rect::Area_int()
{ return nLength *nWidth;}
double Rect::Area_double()
{ return dLength *dWidth;}
void main()
{
	Rect r(5,9);
	Rect *pr;
	pr=new Rect(2.0,16.78);
	cout<<"The int rect's area is"<<r.Area_int()<<endl;
	cout<<"The double rect's area is"<<pr->Area_double()<<endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?