Professional Documents
Culture Documents
Document
Document
Exercise 1:
#include <iostream>
Class Rectangle {
Private:
Double width;
Double height;
Public:
Rectangle(double width, double height) : width(width), height(height) {}
Int main() {
Rectangle rectangle1(4, 40);
Rectangle rectangle2(3.5, 35.9);
Cout << “Rectangle 1:\n”;
Cout << “ Width: “ << rectangle1.width << “\n”;
Cout << “ Height: “ << rectangle1.height << “\n”;
Cout << “ Area: “ << rectangle1.getArea() << “\n”;
Cout << “ Perimeter: “ << rectangle1.getPerimeter() << “\n”;
Return 0;
}
Exercise 2:
#include <iostream>
Class Rectangle {
Private:
Double width;
Double height;
Public:
Rectangle(double width, double height) : width(width), height(height) {}
Double getArea() const {
Return width * height;
}
Int main() {
Rectangle rectangle1(4, 40);
Rectangle rectangle2(3.5, 35.9);
Return 0;
}