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

Swimming Pool Management – In this programming exercise you will create a simple

ID: 3891803 • Letter: S

Question

Swimming Pool Management –

In this programming exercise you will create a simple swimming management program (in C++) according to the following customer specifications:

Write the definition of a class SwimmingPool, to implement the properties and functions of a swimming pool. The pool must be a rectangular shaped of any dimension.

The class should have the instant variables to store the length (in feet), width (in feet), depth (in feet), amount (in cubic feet), of water in the pool, the rate (in gallons / minute), at which the water is draining from the pool.

Must add the SwimmingPool Constructor(s) and Destructor member functions.

Add appropriate accessor and mutator member functions.

Add member functions to do the following:

determine the amount of water needed to fill an empty or partially filled pool,

determine the time needed to completely or partially fill or empty the pool,

and add or drain water for a specific amount of time.

Allow adding or subtracting one or more pools (add by adding lenghs, widths and depths, rates and amount – subtract by subtracting lengths, widths, and depths, rates and amount).

Add a static property (data member) to count the number of swimming pools created and static member function to report this count.

NOTE: The amount of gallons in a cubic feet is 7.48

Please use the following driver program to test your class:

//Main program

#include <iostream>

#include "swimmingPool.h"

using namespace std;

int main()

{

       cout << "The initial total number of pools in this program is "<<

              SwimmingPool::getNumberOfPools() << endl;

       const int NUM_OF_POOLS = 3;

       SwimmingPool pools[NUM_OF_POOLS];

       pools[0] = SwimmingPool(30, 15, 10);

       pools[1] = SwimmingPool(60, 25, 16);

       pools[2] = SwimmingPool(35, 20, 11);

       int waterFRate;

       int time;

       cout << "Pool data: " << endl;

       for (int i = 0; i < 3; i++)

       {

              cout << " ";

              cout << "POOL # " << i + 1 << ": " << endl;

              cout << " Length: " << pools[i].getLength() << endl;

              cout << " Width: " << pools[i].getWidth() << endl;

              cout << " Depth: " << pools[i].getDepth() << endl;

              cout << " Total water in the pool: " <<

                     pools[i].getTotalWaterInPool() << endl;

              cout << "To completely fill the pool: " << endl;

              cout << " Enter water fill in rate: ";

              cin >> waterFRate;

              cout << endl;

              pools[i].setWaterFlowRateIn(waterFRate);

              time = pools[i].timeToFillThePool();

              cout << " Time to fill the pool is approximately: "

                     << time / 60 << " hour(s) and " << time % 60

                     << " minute(s)." << endl;

       }

       //Add 2nd Pool to 3rd Pool

       cout << " The Added Pool Data: " << endl;

       SwimmingPool addedPool = pools[2].add(pools[1]);

       cout << " Length: " << addedPool.getLength() << endl;

       cout << " Width: " << addedPool.getWidth() << endl;

       cout << " Depth: " << addedPool.getDepth() << endl;

       cout << " Total water in the pool: " <<

              addedPool.getTotalWaterInPool() << endl;

       //Subtract the the 3rd Pool from the 2nd Pool

       cout << " The Subtracted Pool Data: " << endl;

       SwimmingPool subPool = pools[1].subtract(pools[2]);

       cout << " Length: " << subPool.getLength() << endl;

       cout << " Width: " << subPool.getWidth() << endl;

       cout << " Depth: " << subPool.getDepth() << endl;

       cout << " Total water in the pool: " <<

              subPool.getTotalWaterInPool() << endl;

       SwimmingPool extraPool(20, 10, 5);

       cout << " The total number of pools created in this program is "

              << extraPool.getNumberOfPools() << endl;

      

       system("pause");

       return 0;

}

//In your SwimmingPool class, add the following Copy Constructor member function to your class. (No modification is required to this function):

//Copy Constructor

SwimmingPool::SwimmingPool(const SwimmingPool &copy)

{

       length = copy.length;

       width = copy.width;

       depth = copy.depth;

       waterFlowInRate = copy.waterFlowInRate;

       waterFlowOutRate = copy.waterFlowOutRate;

       amountOfWaterInPool = copy.amountOfWaterInPool;

       numOfPools++;

}

Explanation / Answer

//main program .cpp file

#include <iostream>

#include "swimmingPool.h"

using namespace std;

int main()

{

//User input has a place to stay

double length, width, depth;

double rateWater, rateDrain;

cout << "Pool Data " << endl;

cout << "Length: ";

cin >> length;

cout << "Width: ";

cin >> width;

cout << "Depth: ";

cin >> depth;

cout << "Enter the rate in which water fills the pool: ";

cin >> rateWater;

cout << "Enter the rate in which water drains the pool: ";

cin >> rateDrain;

//Data from user gets stored into class. Then computes the info

//into the algorithm which determines the time to drain the pool.

swimmingPool poolInfo(length, width, depth, rateWater, rateDrain);

double waterFill = poolInfo.poolWater();

cout << "Time it will take to drain the pool: " << waterFill;

//Takes the users data and determines how long it will

//take to fill the pool.

double timeToFillPool = poolInfo.timeToFill();

cout << "Time it will take to fill the pool: " << timeToFillPool;

return 0;

}

//swimmingPool.h class file

#define GALLONS_IN_A_CUBIC_FEET 7.48;

class swimmingPool

{

public:

swimmingPool();

swimmingPool(double l, double w, double d, double rateFill, double rateDrain);

double amountWaterNeeded();

double timeToFill();

double addWater(double time);

double drainWater(double time);

double poolWater();

private:

double length;

double width;

double depth;

double rateWaterFillsPool;

double rateWaterDrainsPool;

};

//swimmingPoolImp.cpp file that has all the algorithms

#include "swimmingPool.h"

swimmingPool::swimmingPool()

{

//initializes the variables to 0.

length = 0;

width = 0;

depth = 0;

rateWaterDrainsPool = 0;

rateWaterFillsPool = 0;

}

//Data from user(swimmingpool.h) gets categorized into specific varibles for easy computing

swimmingPool::swimmingPool(double l, double w, double d, double rateFill, double rateDrain)

{

length = l;

width = w;

depth = d;

rateWaterFillsPool = rateFill;

rateWaterDrainsPool = rateDrain;

}

//Below are the algorithms for each specific request.

double swimmingPool::amountWaterNeeded()

{

return (length * width * depth) * GALLONS_IN_A_CUBIC_FEET;

}

double swimmingPool::timeToFill()

{

return poolWater() / rateWaterDrainsPool;

}

double swimmingPool::addWater(double time)

{

return rateWaterDrainsPool * time;

}

double swimmingPool::drainWater(double time)

{

return rateWaterDrainsPool * time;

}

double swimmingPool::poolWater()

{

return (length*width*depth)*GALLONS_IN_A_CUBIC_FEET;

}