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

Please help me on this question in C++: Carol has written a class called Rectang

ID: 3808739 • Letter: P

Question

Please help me on this question in C++:

Carol has written a class called Rectangle with member functions getLength(), getWidth(), and calcArea() to return the associated data members. Regina has written a program to use the Rectangle class and has enhanced her program by adding a displayRectangle function to display the rectangle objects's data members length. width and area. Regina's funtion has a Rectangle object parameter named rect that is passed by reference. Show the code for Regina's function using the information given.

Thank you so much

Explanation / Answer

Code:

#include<iostream>
using namespace std;

class Rectangle
{
int l,b;

public:
Rectangle(){l=b=0;}

Rectangle(int x,int y){l=x;b=y;}

int getLength(){ return l;}
int getWidth(){ return b;}

int calcArea(){ return l*b;}

//To set length and breadth of a rectangle
int setSides(int x,int y){ l=x;b=y;}

};


//rect is passed by reference
void displayRectangle(Rectangle & rect)
{

cout<<"The length of the rectange is:"<<rect.getLength()<<endl;
cout<<"The width of the rectange is:"<<rect.getWidth()<<endl;

cout<<"The area of the rectange is:"<<rect.calcArea()<<endl;
}

int main(void)
{
Rectangle r(8,4);

displayRectangle(r);

return 0;
}

Output:

The length of the rectange is:8
The width of the rectange is:4
The area of the rectange is:32