Write the definition of a class, swimmingPool, to implement the properties of a
ID: 3548369 • 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; the time needed to completely or partially fill the pool, or empty the pool; add water or drain for a specific amount of time.
***Need to define methods in the SwimmingPool class as instance methods, not static methods.***
Explanation / Answer
#include
// Main function not needed as this function only asks for the definition of a class
class swimmingPool
{
private:
double length, width, depth, rateIn, rateOut;
double gallons;
double timeToFill, timeToEmpty;
double partialTimeToFill, partialTimeToEmpty;
double gallonsPartial;
public:
swimmingPool(double l, double w, double d, double ri, double ro);
void fillTime(int, double);// these two functions are for the case then the pool is completely empty or full
void emptyTime(int, double);
void fillPartialTime(double, double); // the pool is partially empty/fool during these runs
void emptyPartialTime(double, double);
void addTime(int, int); // add water for a specific amount of time
void drainTime(int, int);//drain water for a specific amount of time
};
swimmingPool::swimmingPool(double l, double w, double d, double ri, double ro)
{
length=l;
width=w;
depth=d;
rateIn=ri;
rateOut=ro;
// from the capacity in gallons formula, the total capacity for a rectangular swimming pool
//its all of them multiplied by each other then multiplied by 7.5
gallons=(length*width*depth*7.5);
}
void swimmingPool::fillTime(int timeToFill, double gallons)
{
timeToFill=gallons/rateIn;
}
void swimmingPool::emptyTime(int timeToEmpty, double gallons)
{
timeToEmpty=gallons/rateOut;
}
void swimmingPool::fillPartialTime(double difference, double gallons)
{
cout
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.