📄 shiyan9_1.cpp
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -