问题及代码:
、
#include <iostream>
using namespace std;
class Rectangle
{
public:
Rectangle(int w,int l);
int getArea();
int getPerimeter();
private:
int width;
int length;
};
//将程序需要的其他成份写在下面,只提交begin到end部分的代码
//******************** begin ********************
Rectangle::Rectangle(int w,int l)
{
width=w;
length=l;
}
int Rectangle::getArea()
{
return width*length;
}
int Rectangle::getPerimeter()
{
return 2*(width+length);
}
//********************* end ********************
int main()
{
int width,length;
cin>>width>>length;
Rectangle r(width,length);
cout<<"Area="<<r.getArea()<<endl;
cout<<"Perimeter="<<r.getPerimeter()<<endl;
return 0;
}
运行结果: