Question
Hello I need help with this C++ assignment. Modify the code to implement in two separate files: in a header file Rectangle.h - A complete
Hello I need help with this C++ assignment. Modify the code to implement in two separate files: in a header file Rectangle.h - A complete Rectangle Class including both declaration and definition and a .cpp file. The code should run like this. Thanks.
Code needed to be modified:
#include
#include
using namespace std;
// Rectangle class declaration.
class Rectangle
{
private:
double width;
double length;
public:
void setWidth(double);
void setLength(double);
double getWidth() const;
double getLength() const;
double getArea() const;
};
//**************************************************
// setWidth assigns a value to the width member. *
//**************************************************
void Rectangle::setWidth(double w)
{
width = w;
}
//**************************************************
// setLength assigns a value to the length member. *
//**************************************************
void Rectangle::setLength(double len)
{
length = len;
}
//**************************************************
// getWidth returns the value in the width member. *
//**************************************************
double Rectangle::getWidth() const
{
return width;
}
//****************************************************
// getLength returns the value in the length member. *
//****************************************************
double Rectangle::getLength() const
{
return length;
}
//*****************************************************
// getArea returns the product of width times length. *
//*****************************************************
double Rectangle::getArea() const
{
return width * length;
}
//*****************************************************
// Function main *
//*****************************************************
int main()
{
double number; // To hold a number
double totalArea; // The total area
// Dynamically allocate the objects.
unique_ptr kitchen(new Rectangle);
unique_ptr bedroom(new Rectangle);
unique_ptr den(new Rectangle);
// Get the kitchen dimensions.
cout
cin >> number; // Get the length
kitchen->setLength(number); // Store in kitchen object
cout
cin >> number; // Get the width
kitchen->setWidth(number); // Store in kitchen object
// Get the bedroom dimensions.
cout
cin >> number; // Get the length
bedroom->setLength(number); // Store in bedroom object
cout
cin >> number; // Get the width
bedroom->setWidth(number); // Store in bedroom object
// Get the den dimensions.
cout
cin >> number; // Get the length
den->setLength(number); // Store in den object
cout
cin >> number; // Get the width
den->setWidth(number); // Store in den object
// Calculate the total area of the three rooms.
totalArea = kitchen->getArea() + bedroom->getArea() +
den->getArea();
// Display the total area of the three rooms.
cout
return 0;
}
This program will calculate the area of a rectangle. What is the width? 3 What is the length? 4 Here is the rectangle's data: Width: 3 Length: 4 Area: 12 Process returned 0 (0x0) execution time : 4.500 s Press any key to continueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started