设计一个矩形类,完成计算矩形面积和显示矩形属性的功能。

来源:互联网 发布:淘宝怎样打印电子面单 编辑:程序博客网 时间:2024/05/16 15:16
/

/*
【基本题】设计一个矩形类,完成计算矩形面积和显示矩形属性的功能。

*/


#include<iostream>
using namespace std;
class Retangle
{

public:
 float Area();
 
 void Show();
 Retangle(float w=0,float h=0);
 
private:
 float width;
 float height;
};

Retangle::Retangle(float w,float h):width(w),height(h)
{
}

 

 


float Retangle::Area()
{

 return this->height*this->width;

}
void Retangle::Show()
{
 cout<<"长:"<<this->height<<"宽:"<<this->height<<endl;
}
void main()
{
 Retangle retangle(13,45);
 retangle.Area();
 cout<<retangle.Area()<<endl;
}

 

原创粉丝点击