【问题描述】
编写程序求长方形的周长和面积
【样例输入输出】
Input the Length and Width: 12 23 The Area is:276 The Premeter:70
要求补全程序
class Rectangle
{
public:
Rectangle(void);
Rectangle(float length,float width);
~Rectangle(void);
float getArea();
float getGirth();
private:
float mLength;
float mWidth;
};
......
int main()
{
float m, n;
cout << "Input the Length and Width: ";
cin >> m >> n;
Rectangle r1(m,n);
cout<<"The Area is: "<<r1.getArea()<<endl;
Rectangle r2(m,n);
cout<<"The Perimeter: "<<r2.getGirth()<<endl;
}
#include <iostream>
using namespace std;
Rectangle::Rectangle(float length, float width)
{
mLength = length;
mWidth = width;
}
float Rectangle::getArea()
{
return mLength * mWidth;
}
float Rectangle::getGirth()
{
return 2 * (mLength + mWidth);
}
Rectangle::~Rectangle(void) {}