【问题描述】
编写程序求长方形的周长和面积
【样例输入输出】
Input the Length and Width: 12 23
The Area is:276
The Premeter:70
#include <iostream>
using namespace std;
class Rectangle {
public:
Rectangle(void);
Rectangle(float length, float width);
~Rectangle(void);
float getArea();
float getGirth();
private:
float mLength;
float mWidth;
};
Rectangle::Rectangle(float length, float width) {
mLength = length;
mWidth = width;
}
float Rectangle::getArea() {
int area = mLength * mWidth;
return area;
}
float Rectangle::getGirth() {
int girth;
girth = 2 * (mLength + mWidth);
return girth;
}
Rectangle::Rectangle(void) { }
Rectangle::~Rectangle(void) { }
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;
}