Question: ` ` ` Rectanglelmp.cpp > { } Rectanglelmp 1 namespace RectangleImp { / / Rectangle class Rectangle { public: / / Declare public methods here

```
Rectanglelmp.cpp >{} Rectanglelmp
1 namespace RectangleImp {
// Rectangle
class Rectangle
{
public:
// Declare public methods here
private:
// Create length and width here
};
void Rectangle::setLength(double len)
{
// Write setLength here
}
void Rectangle::setwidth(double wid)
{
// write setWidth here
}
double Rectangle::getLength()
{
// write getLength here
}
double Rectangle::getWidth()
{
// write getWidth here
}
double Rectangle::calculateArea()
{
// write calculateArea here
}
double Rectangle::calculatePerimeter()
{
// write calculatePerimeter here
}
}
``````
@+ MyRectangleClassProgram.cpp >%) main()
1// This program uses the programmer-defined Rectangle class.
#include "RectangleImp.cpp"
#include
using namespace std;
using namespace RectangleImp;
int main()
{
// Create Rectangle objects here
// Set the lengths and widths here
// Print the areas and perimeters here
return 0;
}
``` Your Tasks
In this lab, you create a programmer-defined class and then use it in a C++ program. The program should create two Rectangle objects and find their area and perimeter. Use the Circle class that you worked with in Exercise 10-1 as a guide.
Instructions
Open the class file RectangleImp.cpp.
In the Rectangle class, create two private attributes named length and width. Both length and width should be data type double.
Task 1: Write public set and get methods to set and get the values for length.
Task 2: Write public set and get methods to set and get the values for width.
Task 3: Write a public calculateArea() method and a public calculatePerimeter() method to calculate and return the area of the rectangle and the perimeter of the rectangle.
Open the MyRectangleClassProgram.cpp, create two Rectangle objects named rectangle1 and rectangle2 using the default constructor as you saw in MyEmployeeClassProgram.cpp.
Set the length of rectangle1 to \(\mathbf{10.0}\) and the width to \(\mathbf{5.0}\). Set the length of rectangle2 to \(\mathbf{7.0}\) and the width to \(\mathbf{3.0}\). Print the value of rectangle1's perimeter and area, and then print the value of rectangle2's perimeter and area. An example of the program is shown below:
Perimeter of rectangle1 is 30
Area of rectangle1 is 50
Perimeter of rectangle2 is 20
Area of rectangle2 is 21
` ` ` Rectanglelmp.cpp > { } Rectanglelmp 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!