#include<iostream>
using namespace std;
class Rectangle{
private:
int width, height, area, perimeter;
public:
Rectangle(){
width = 0;
height = 0;
area = 0;
perimeter= 0;
}
Rectangle(int w, int h){
width = w;
height = h;
area = 0;
perimeter = 0;
}
void setWidth(int w){
width = w;
}
void setHeight(int h){
height = h;
}
int getArea(){
return area;
}
int getPerimeter(){
return perimeter;
}
void computeArea(){
area = height * width;
}
void computePerimeter(){
perimeter = 2 * (width + height);
}
};
int main(){
Rectangle rect1;
Rectangle rect2(5,10);
rect1.setWidth(100);
rect1.setHeight(25);
rect1.computeArea();
rect1.computePerimeter();
rect2.computeArea();
rect2.computePerimeter();
cout<<"Rectangle rect1\n";
cout<<"The area of the rectangle: "<<rect1.getArea()<<endl;
cout<<"The perimeter of the rectangle: "<<rect1.getPerimeter()<<endl;
cout<<"Rectangle rect2\n";
cout<<"The area of the rectangle: "<<rect2.getArea()<<endl;
cout<<"The perimeter of the rectangle: "<<rect2.getPerimeter()<<endl;
}
Comments
Leave a comment