嵌套类

原创 2013年12月04日 09:55:59
#include <iostream>
using namespace std;
class rectangle
{
  public:
class point
{
public:
void setx(int X){x=X;}
void sety(int Y){y=Y;}
int getx()const{return x;}
int gety()const{return y;}
private:
int x;
int y;
};
point GetUpLeft()const{return upleft;}
point GetLowLeft()const{return lowerleft;}
point GetUpRight()const{return upright;}
point GetLowRight()const{return lowerright;}


rectangle(int top,int left,int bottom,int right);
~rectangle(){}


int GetTop()const{return Top;}
int GetLeft()const{return Left;}
int GetBottom()const{return Bottom;}
int GetRight()const{return Right;}


void SetUpLeft(){upleft.setx(Left);upleft.sety(Top);}
void SetLowLeft(){lowerleft.setx(Left);lowerleft.sety(Bottom);}
void SetUpRight(){upright.setx(Right);upright.sety(Top);}
void SetLowRight(){lowerright.setx(Right);lowerright.sety(Bottom);}
void SetTop(int top){Top=top;}
void SetLeft(int left){Left=left;}
void SetRight(int right){Right=right;}
void SetBottom(int bottom){Bottom=bottom;}
int GetArea()const{int width=Right-Left;int height=Bottom-Top; return(width*height);}


  private:
point upleft;
point lowerleft;
point upright;
point lowerright;


int Top;
int Left;
int Bottom;
int Right;
};


rectangle::rectangle(int top,int left,int bottom,int right)
{
Top=top;
Left=left;
Bottom=bottom;
Right=right;


upleft.setx(Left);
upleft.sety(Top);


upright.setx(Right);
upright.sety(Top);


lowerright.setx(Right);
lowerright.sety(Bottom);


lowerleft.setx(Left);
lowerleft.sety(Bottom);
}
class point 
{
  public:
int GetArea(rectangle &rec){return rec.GetArea();}
};


int main()
{
rectangle data(40,50,60,80);
cout<<"左边为:"<<data.GetLeft()<<endl;
cout<<"下边为:"<<data.GetBottom()<<endl;
cout<<"左下的x坐标为:"<<data.GetLowLeft().getx()<<endl;
cout<<"左下的y坐标为:"<<data.GetLowLeft().gety()<<endl;
cout<<"矩形面积为:"<<data.GetArea()<<endl;
cout<<"重新设置Left和Bottom值"<<endl;
data.SetLeft(0);
data.SetBottom(100);
data.SetLowLeft();
cout<<"左边为:"<<data.GetLeft()<<endl;
cout<<"下边为:"<<data.GetBottom()<<endl;
cout<<"左下的x坐标为:"<<data.GetLowLeft().getx()<<endl;
cout<<"左下的y坐标为:"<<data.GetLowLeft().gety()<<endl;
point pt;
cout<<"矩形面积为:"<<pt.GetArea(data)<<endl;
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

嵌套类的学习

  • 2008-08-21 14:35
  • 14KB
  • 下载

Java进阶07 嵌套类

作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明。谢谢!   到现在为止,我们都是在Java文件中直接定义类。这样的类出现在包(packag...

C类中的各种成员_嵌套类

  • 2013-05-20 14:49
  • 308KB
  • 下载

c++ 嵌套类

c++嵌套类c++嵌套类等同于内部类的概念,定义嵌套类的目的是为了隐藏信息,提高代码的抽象能力,相当与在内部为外部类提供了一种新的类型。 嵌套类仅仅只是语法上的嵌入,平行的关系,相互独立,相互没有访...

嵌套类(Nested Class)

嵌套类 静态嵌套类 非静态嵌套类(内部类【inner class】) class OuterClass{ //... class NestedClass{ //... ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)