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

Write the definition of a class, swimmingPool, to implement the properties of a

ID: 3644571 • Letter: W

Question

Write the definition of a class, swimmingPool, to implement the
properties of a swimming pool. Your class should have the instance
variables to store the length (in feet), width (in feet), depth (in feet), the
rate (in gallons per minute) at which the water is filling the pool, and the
rate (in gallons per minute) at which the water is draining from the pool.
Add appropriate constructors to initialize the instance variables. Also 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; add or drain water for a
specific amount of time.

Explanation / Answer

swimmingPool.h

class swimmingPool
{
    private:

        double length;          // in feet
        double width;           // in feet
        double depth;           // in feet
        double fillRate;        // in us gallons per min
        double drainageRate;    // in us gallons per min

    public:

        swimmingPool(double length, double width, double depth, double fillRate = 0, double drainageRate = 0);

                                                                // length, width, depth in feet, fillRate, drainageRate in us gallons per min
        double WaterRequiredToFill(double initialVolume = 0);

                                                               // initialVolume in gallons, returns us gallons
        double TimeRequiredToFill(double initialVolume = 0, double finalVolume = -1);

                                                              // initialVolume, finalVolume in us gallons, returns min
        double TimeRequiredToEmpty(double initialVolume = -1);

                                                             // initialVolume in us gallons, returns min
};

swimmingPoollmp.cpp

#include "swimmingPool.h"

swimmingPool::swimmingPool(double length, double width, double depth, double fillRate, double drainageRate)
{
    this->length = length;
    this->width = width;
    this->depth = depth;
    this->fillRate = fillRate;
    this->drainageRate = drainageRate;
}

double
swimmingPool::WaterRequiredToFill(double initialVolume)
{
    return (7.4805*length*width*depth - initialVolume);
}

double
swimmingPool::TimeRequiredToFill(double initialVolume, double finalVolume)
{
    if(finalVolume == -1)
    {
        finalVolume = length*width*depth;
    }

    return ((finalVolume-initialVolume)/(fillRate-drainageRate));
}

double
swimmingPool::TimeRequiredToEmpty(double initialVolume)
{
    if(initialVolume == -1)
    {
        initialVolume = length*width*depth;
    }
    return (initialVolume/(drainageRate-fillRate));
}

Ch10_Ex12_MainProgram.cpp

#include "swimmingPoollmp.cpp"
#include <iostream>

int main()
{
    swimmingPool* swimmingPool1 = new swimmingPool(100, 200, 500, 5, 3);
    swimmingPool* swimmingPool2 = new swimmingPool(100, 200, 500, 3, 5);

    std::cout << "WaterRequired To Fill Swimming Pool 1 = " << swimmingPool1->WaterRequiredToFill()

                    << " gallons" << std::endl;
    std::cout << "Time Required To Fill Swimming Pool 1 = " << swimmingPool1->TimeRequiredToFill()

                     << " min" << std::endl;
    std::cout << "Time Required To Empty Swimming Pool 2 = " << swimmingPool2->TimeRequiredToEmpty()

                     << " min" << std::endl;

    return 0;
}