#include<iostream>
using namespace std;
class Rectangle
{
private:int itsTop;
int itsLeft;
int itsBotton;
int itsRight;
public:
Rectangle(int=0,int=0,int=0,int=0);
~Rectangle(){};
int GetTop(){return itsTop;}
int GetLeft(){return itsLeft;}
int GetBotton(){return itsBotton;}
int GetRight(){return itsRight;}
void SetTop(int top){itsTop=top;}
void SetLeft(int left){itsLeft=left;}
void SetBotton(int botton){itsBotton=botton;}
void SetRight(int right){itsRight=right;}
int GetArea();
};
Rectangle::Rectangle(int top,int left,int botton,int right)
{
itsTop=top;
itsLeft=left;
itsBotton=botton;
itsRight=right;
}
int Rectangle::GetArea()
{
int Width=itsRight=itsLeft;
int Height=itsTop-itsBotton;
return Width*Height;
}
void main()
{
Rectangle MyRectangle(100,20,50,80);
int Area=MyRectangle.GetArea();
cout<<"Top:"<<MyRectangle.GetTop()<<endl;
cout<<"Left:"<<MyRectangle.GetLeft()<<endl;
cout<<"Botton:"<<MyRectangle.GetBotton()<<endl;
cout<<"Right:"<<MyRectangle.GetRight()<<endl;
cout<<"Area:"<<Area<<endl;
}
1在类定义完了之后一定要有;
2在类中写函数体的时候 void set(){return left;}括号外面没有;
3如果用#include<iostream>
一定要加using namespace std;