Answer:
#include <iostream>
using namespace std;
class Rectangle{
public:
double width, height;
public:
Rectangle();
Rectangle(double, double);
double perimeter() { return 2 * (width + height); }
};
Rectangle::Rectangle () {
width = 1.0;
height = 1.0;
}
Rectangle::Rectangle (double a, double b) {
width = a;
height = b;
}
int main()
{
Rectangle obj_rectangle1;
Rectangle obj_rectangle2(4,40);
Rectangle obj_rectangle3(3.5,35.9);
cout << "Rectangle1's width: " << obj_rectangle1.width << ", height: "<< obj_rectangle1.height << ", perimeter: " << obj_rectangle1.perimeter() << endl;
cout << "Rectangle2's width: " << obj_rectangle2.width << ", height: "<< obj_rectangle2.height << ", perimeter: " << obj_rectangle2.perimeter() << endl;
cout << "Rectangle3's width: " << obj_rectangle3.width << ", height: "<< obj_rectangle3.height << ", perimeter: " << obj_rectangle3.perimeter() << endl;
return 0;
}
Step-by-step explanation:
Declare two variables for width and height.
Specify the constructors and a function to calculate the perimeter.
Initialize the constructors (one with no parameter, and one with two parameters).
In the main, create the required objects and print the required values.