Thank you for visiting C program that creates three rectangle objects 1 The first rectangle with no width or height specified 2 The second rectangle with a width of. This page is designed to guide you through key points and clear explanations related to the topic at hand. We aim to make your learning experience smooth, insightful, and informative. Dive in and discover the answers you're looking for!
Answer :
Answer:
#include
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;
}
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.
Thank you for reading the article C program that creates three rectangle objects 1 The first rectangle with no width or height specified 2 The second rectangle with a width of. We hope the information provided is useful and helps you understand this topic better. Feel free to explore more helpful content on our website!
- You are operating a recreational vessel less than 39 4 feet long on federally controlled waters Which of the following is a legal sound device
- Which step should a food worker complete to prevent cross contact when preparing and serving an allergen free meal A Clean and sanitize all surfaces
- For one month Siera calculated her hometown s average high temperature in degrees Fahrenheit She wants to convert that temperature from degrees Fahrenheit to degrees
Rewritten by : Jeany