#include <iostream>
using namespace std;
class Rectangle
{
public:
Rectangle(int w,int l);
int getArea();
int getPerimeter();
private:
int width;
int length;
};
Rectangle::Rectangle(int w,int l)
{
width=w;//一定注意不要把私有成员跟你main里面的对象顺序错了;
length=l;
}
int Rectangle::getArea()
{
return width*length;
}
int Rectangle::getPerimeter()
{
return 2*(width+length);
}
int main()
{
int width,length;
cin>>width>>length;
Rectangle r(width,length);
cout<<"Area="<<r.getArea()<<endl;
cout<<"Perimeter="<<r.getPerimeter()<<endl;
return 0;
}
using namespace std;
class Rectangle
{
public:
Rectangle(int w,int l);
int getArea();
int getPerimeter();
private:
int width;
int length;
};
Rectangle::Rectangle(int w,int l)
{
width=w;//一定注意不要把私有成员跟你main里面的对象顺序错了;
length=l;
}
int Rectangle::getArea()
{
return width*length;
}
int Rectangle::getPerimeter()
{
return 2*(width+length);
}
int main()
{
int width,length;
cin>>width>>length;
Rectangle r(width,length);
cout<<"Area="<<r.getArea()<<endl;
cout<<"Perimeter="<<r.getPerimeter()<<endl;
return 0;
}