Rectangle(c++)

时间:2017-11-12 10:02:07
【文件属性】:
文件名称:Rectangle(c++)
文件大小:1.56MB
文件格式:ZIP
更新时间:2017-11-12 10:02:07
类与对象 #include #include using namespace std; struct CPoint { int x ; int y ; }; class CRectangle { private: const int id;//常量数据成员 static int total;//静态数据成员 const static string sclass; const static int f=1.0f; CPoint lefttop ; CPoint rightdown ; public: CRectangle( ); CRectangle( CPoint& lt, CPoint& rd ); CPoint GetLefttop() const { return lefttop; } CPoint GetRightdown() const { return rightdown; } void SetLefttop(CPoint & pt) { lefttop=pt; } void SetRightdown(CPoint & pt) { rightdown=pt; } int Getid() const { return id; } static int Gettotal() { return total; } int Area( ) const; int Perimeter( ) const; }; int CRectangle::total=0;//静态数据成员必须在类的外部定义(正好一次)。 const string CRectangle::sclass="CRectangle"; CRectangle::CRectangle( ):id(++total) { lefttop.x=0; lefttop.y=0; rightdown.x=1; rightdown.y=1; } CRectangle::CRectangle( CPoint& lt, CPoint& rd ):id(++total) { lefttop = lt ; rightdown = rd ; } int CRectangle::Area( ) const { int wd= rightdown.x - lefttop.x ; int ht= rightdown.y - lefttop.y ; return wd * ht ; } int CRectangle::Perimeter( ) const { int wd= rightdown.x - lefttop.x ; int ht= rightdown.y - lefttop.y ; return 2 * ( wd + ht ) ; } int main() { CPoint lt, rd; cin >> lt.x >> lt.y; cin >> rd.x >> rd.y; CRectangle crt(lt,rd);//调用有参构造函数 CRectangle crt2;//调用默认构造函数 //创建常量对象 const CRectangle crt3(lt,rd); cout<<"当前创建的矩形个数为:"; cout<> lt.x>>lt.y; crt.SetLefttop(lt); lt1=crt.GetLefttop(); //显示修改后矩形的坐标 cout<<"矩形的坐标是:"<<"("< 立即下载

【文件预览】:
Rectangle_const
----bin()
--------Debug()
----obj()
--------Debug()
----Rectangle_const.cbp(1KB)
----main.cpp(2KB)
----Rectangle_const.depend(103B)
----Rectangle_const.layout(323B)
complex_type
----bin()
--------Debug()
----complex_type.cbp(1KB)
----obj()
--------Debug()
----main.cpp(506B)
----complex_type.depend(100B)
----complex_type.layout(322B)
Rectangle_this
----bin()
--------Debug()
----Rectangle_this.layout(323B)
----obj()
--------Debug()
----Rectangle_this.cbp(1KB)
----main.cpp(1KB)
Rectangle_static
----bin()
--------Debug()
----Rectangle_static.cbp(1KB)
----obj()
--------Debug()
----Rectangle_static.depend(104B)
----Rectangle_static.layout(323B)
----main.cpp(3KB)
Rectangle_class_0.zip
Rectangle_1
----bin()
--------Debug()
----Rectangle_1.cbp(1KB)
----obj()
--------Debug()
----main.cpp(2KB)
----Rectangle_1.layout(321B)

网友评论