Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Name: Ali hassan

Exercise 1:
#include <iostream>

Using namespace std;

Class Rectangle {
Private:
Double width;
Double height;

Public:
Rectangle(double width, double height) : width(width), height(height) {}

Double getArea() const {


Return width * height;
}

Double getPerimeter() const {


Return 2 * (width + 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”;

Cout << “\nRectangle 2:\n”;


Cout << “ Width: “ << rectangle2.width << “\n”;
Cout << “ Height: “ << rectangle2.height << “\n”;
Cout << “ Area: “ << rectangle2.getArea() << “\n”;
Cout << “ Perimeter: “ << rectangle2.getPerimeter() << “\n”;

Return 0;
}

Exercise 2:
#include <iostream>

Using namespace std;

Class Rectangle {
Private:
Double width;
Double height;

Public:
Rectangle(double width, double height) : width(width), height(height) {}
Double getArea() const {
Return width * height;
}

Double getPerimeter() const {


Return 2 * (width + 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”;

Cout << “\nRectangle 2:\n”;


Cout << “ Width: “ << rectangle2.width << “\n”;
Cout << “ Height: “ << rectangle2.height << “\n”;
Cout << “ Area: “ << rectangle2.getArea() << “\n”;
Cout << “ Perimeter: “ << rectangle2.getPerimeter() << “\n”;

Return 0;
}

You might also like