面向对象思想
#include <iostream>
using namespace std;
class Rectangle {
public:
Rectangle(int width, int height): _width(width), _height(height){}
// 求周长
int perimeter() {
return (_width + _height) * 2;
}
// 求面积
int area() {
return _width * _height;
}
private:
int _width;
int _height;
};
int main() {
int width = 0, height = 0;
cin >> width >> height;
Rectangle rectangle(width, height);
cout << rectangle.perimeter() << endl;
cout << rectangle.area() << endl;
}