swimmingpool

so i made this program recently i am stuck and need help it
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, and add or drain water for a specific amount of time.

The UML diagram and header file are supplied.

Write the class implementation file. Write a test program for your class. Your test program should produce the following output:

my question is i have most of the program done but my addwater and drainwater function are completely wrong im lost on how to fix them i need some adavance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void swimmpool::addWater(double time, double rate)
{
   if((time * rate) + amountOfWaterInPool > poolTotalWaterCapacity())
   {
       
       amountOfWaterInPool = time * rate;
   }
   else
   {
       amountOfWaterInPool = (time * rate) +  poolTotalWaterCapacity();
   }

}
void  swimmpool::drainWater(double time, double rate)
{
    if(amountOfWaterInPool - time *rate < 0)
    {
        
        amountOfWaterInPool = 0;
    }



}
Last edited on
i meant to say advice excuse the misspelling =]
I recommend you do your calculation before the if() statements, break the calculation into the individual parts so you can print each par to the calculation to help determine the cause of the problem. Do the same with the calculations in the bodies of your if() statements. Then you may be able to determine if your calculation is correct. For example is (time * rate) actually in gallons per minute? Do you really want to use the total capacity figure in these calculations? Shouldn't you have some kind of information about the amount of water in the pool?
what do you mean by break them down?
1
2
3
4
5
6
7
8
9
void swimmpool::addWater(double time, double rate)
{
    double amount_added = rate*time ;

    amountOfWaterInPool += amount_added ;

    if (amountOfWaterInPool > poolTotalWaterCapacity())
        amountOfWaterInPool = poolTotalWaterCapacity();
}


Don't overthink it.
so that how addwater would go? yes i have been overthinking all this week wow
also @cire would drain be the same way ,but a little bit different
Topic archived. No new replies allowed.