Question: In this lab, you create a programmer - defined class and then use it in a C + + program. The program should create two

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.
// 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;
}
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
}
}

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!