#include <iostream>
using namespace std;
class Rectangle {
private:
int width;
int height;
public:
Rectangle();
Rectangle(int, int);
public:
int getArea() const {
return width * height ;
}
int getWidth() const {
return width;
}
int getHeight() const {
return height;
}
};
Rectangle::Rectangle() {
width = 10;
height = 5;
}
Rectangle::Rectangle(int a, int b) {
width = a;
height = b;
}
int main() {
Rectangle rect1(5, 4);
Rectangle rect2;
cout << "rect1:" << endl;
cout << " width: " << rect1.getWidth() << endl;
cout << " height: " << rect1.getHeight() << endl;
cout << " area: " << rect1.getArea() << endl;
cout << "rect2:" << endl;
cout << " width: " << rect2.getWidth() << endl;
cout << " height: " << rect2.getHeight() << endl;
cout << " area: " << rect2.getArea() << endl;
return 0;
}
Comments