设计并测试一个名为Rectangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,根据坐标能计算矩形的面积。
#include <iostream>
using namespace std;
class rectanglebcwp
thisafternoon{
public:
rectangle(float top,float bottom,float left,float right);
日语考试资料~rectangle( ) { }
float gettop( ) const { return itstop; }
float getbottom( ) const { return itsbottom; }
float getleft( ) const { return itsleft; }
float getright( ) const { return itsright; }
void ttop(float top) { itstop=top; }
void tbottom(float bottom) { itsbottom=bottom; }
void tleft(float left) { itsleft=left; }
仁爱版英语citicvoid tright(float right) { itsright=right; }英语说课稿
float getarea( )const;
private:
float itstop;
float itsbottom;
float itsleft;
float itsright;
};
rectangle::rectangle(float top,float bottom,float left,float right)
{
itstop=top;
2011年江苏高考作文
itsbottom=bottom;
itsleft=left;
itsright=right;
}
float rectangle::getarea( ) const
{
float width=itsright-itsleft;
charmantfloat height=itstop-itsbottom;
return(width*height);
}
float main( )
{
float top,bottom,left,right;
cout<<"请输入参数top,bottom,left,right: "<<endl;
cutoutcin>>top;
cin>>bottom;
六级成绩分布cin>>left;
cin>>right;
rectangle myrectangle(top,bottom,left,right);
float area( );
cout<<"左下角的坐标是:("<<left<<","<<bottom<<")"<<endl;
cout<<"右上角角的坐标是:("<<right<<","<<top<<")"<<endl;
cout<<"area:"<<area<<"\n";
return 0;
}