Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a C++ program. Help me complete the program thank you. // Task: To creat

ID: 3733520 • Letter: T

Question

This is a C++ program. Help me complete the program thank you.

// Task: To create a class Rectangle, and calculate the area of rectangle

#include <iostream>

using namespace std;

// Create a class Rectangle with public length and breadth

class Rectangle

{};

int main()

{

// Declare three rectangles of type Rectangle

int area = 0;

//Enter length and breadth for three rectangles

// Rectangle 1 specification

// Rectangle 2 specification

// Rectangle 3 specification

// Calculate and print the area for each rectangle

// Area of Rectangle 1

// Area of Rectangle 2

// Area of Rectangle 3

system("pause");

return 0;

}

Explanation / Answer

#include <iostream>

using namespace std;

// Create a class Rectangle with public length and breadth

class Rectangle

{
private:
int length, breadth;
public:
Rectangle(int l, int b) {
length=l;
breadth = b;
}
int getArea() {
return length * breadth;
}
};

int main()

{

// Declare three rectangles of type Rectangle
int l1,l2,l3,b1,b2,b3;
int area = 0;

//Enter length and breadth for three rectangles
cout<<"Enter the first rectangle length: "<<endl;
cin >> l1;
cout<<"Enter the first rectangle breadth: "<<endl;
cin >> b1;
cout<<"Enter the second rectangle length: "<<endl;
cin >> l2;
cout<<"Enter the second rectangle breadth: "<<endl;
cin >> b2;
cout<<"Enter the third rectangle length: "<<endl;
cin >> l3;
cout<<"Enter the third rectangle breadth: "<<endl;
cin >> b3;

// Rectangle 1 specification
Rectangle r1(l1,b1);
// Rectangle 2 specification
Rectangle r2(l2,b2);
// Rectangle 3 specification
Rectangle r3(l3,b3);
// Calculate and print the area for each rectangle
area = r1.getArea();
// Area of Rectangle 1
cout<<"Rectangle 1 Area: "<<area<<endl;

// Area of Rectangle 2
area = r2.getArea();
cout<<"Rectangle 2 Area: "<<area<<endl;

// Area of Rectangle 3
area = r3.getArea();
cout<<"Rectangle 3 Area: "<<area<<endl;

//system("pause");

return 0;

}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote