Question: In the Rectangle class, create two private attributes named length and width. Both length and width should be data type double. Task 1 : Write

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;
}
Set thelengthofrectangle1to10.0and thewidthto5.0. Set thelengthofrectangle2to7.0and thewidthto3.0.
Print the value of rectangle1s perimeter and area, and then print the value of rectangle2s perimeter and area.
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!