Question

Write the definition of a class, swimmingPool, to implement the properties of a swimming pool. Your...

  1. 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.

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 pool; the time needed to completely fill the pool; add water for a specific amount of time.


run:

Pool data:

  Length: 30.0

  Width: 15.0

  Depth: 10.0

  Total water in the pool: 0.0

To completely fill the pool:

  Enter water fill in rate (in gallons per minutes): 100

Time to fill the pool is appriximately: 5 hour(s) and 37 minute(s).

run:

Pool data:

  Length: 30.0

  Width: 15.0

  Depth: 10.0

  Total water in the pool: 0.0

To completely fill the pool:

  Enter water fill in rate (in gallons per minutes): 10

  Time to fill the pool is appriximately: 56 hour(s) and 6 minute(s).

BUILD SUCCESSFUL (total time: 14 seconds)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SwimmingPool.h

#ifndef SWIMMINGPOOL_H
#define SWIMMINGPOOL_H

class SwimmingPool
{
public:
SwimmingPool();
SwimmingPool(double, double, double,double);
double waterAmountNeeded();
double calculateTime();
double addWater();
private:
double length;
double height;
double depth;
double rate;
};

#endif // SWIMMINGPOOL_H

SwimmingPool.cpp

#include "SwimmingPool.h"

// Default Constructor
SwimmingPool::SwimmingPool(){
length = 0;
height = 0;
depth = 0;
rate =0 ;
}

// Parameterized constructor
SwimmingPool::SwimmingPool(double length,double height,double depth,double rate):length(length),height(height),depth(depth),rate(rate){}

// Calculate and return water needed in gallons
double SwimmingPool::waterAmountNeeded()
{
return length*height*depth*7.5;
}

// Calculate time in minutes and convert into
double SwimmingPool::calculateTime(){
double minutes = waterAmountNeeded()/rate;
return minutes;
}

// Add water
double SwimmingPool::addWater(){
return rate*calculateTime();
}

main.cpp

#include <iostream>
#include<SwimmingPool.h>
using namespace std;

int main()
{
double length, depth, height, rate;
// Take inputs
cout<<"Pool data:"<<endl;
cout<<"\tLength: ";
cin>>length;
cout<<"\tHeight: ";
cin>>height;
cout<<"\tDepth: ";
cin>>depth;
cout<<"\tTotal Water in the pool: 0.0"<<endl;
cout<<"To completely fill the pool:"<<endl;
cout<<"\tEnter water fill in rate (in gallons per minutes):";
cin>>rate;

// Create object of swimming pool
SwimmingPool s(length,height,depth,rate);

// Calculate time and convert into minutes and hours
double time = s.calculateTime();
int minutes = (int)time;
int hours = minutes/60;
minutes = minutes - hours*60;
cout<<"Time to fill the pool is approximately: "<<hours<<" hour(s) and "<<minutes<<" minute(s)."<<endl;
return 0;

}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
Write the definition of a class, swimmingPool, to implement the properties of a swimming pool. Your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write the definition of a class, Swimming Pool, to implement its properties and methods. Your class...

    Write the definition of a class, Swimming Pool, to implement its properties and methods. Your class should have the instance variables to store: length (in meters), width (in meters), depth (in meters), rate (in liters per minute) at which the water is filling the pool, and rate (in liters per minute) at which the water is draining from the pool. This class’s functions are expected to do the following: determine the amount of water needed to fill an empty or...

  • A closer look at functions - C++ C option: (The best grade is a 79%) Write...

    A closer look at functions - C++ C option: (The best grade is a 79%) Write a program to calculate the cost and time it takes to fill a swimming pool . Inputs: Length, Width, and Depth of the pool (This is a gross simplification, since pools are not really rectangular cubes.) Fill rate of the pool in Gallons per minute Calculation functions Write a function to calculate the total cubic feet (Length x Width x Depth) and return the...

  • How many gallons of water are wasted each time a swimming pool with a length of...

    How many gallons of water are wasted each time a swimming pool with a length of 12.5 ft, a width of 6.8 ft and an average depth of 5.4 feet is drained?

  • Bucket Management – In this programming exercise you will create a simple bucket management program according...

    Bucket Management – In this programming exercise you will create a simple bucket management program according to the following customer specifications: Write the definition of a class Bucket, to implement the properties and functions of a bucket. The bucket must be Cylinder shaped of any dimension. (20%) The class should have the instant variables to store the height (in feet), radius (in feet), amount (in cubic feet) of water in the bucket, the rate (in gallons / minute), at which...

  • Suppose that water is pouring into a swimming pool in the shape of a right circular cylinder at a constant rate of 9 cubic feet per minute

    Suppose that water is pouring into a swimming pool in the shape of a right circular cylinder at a constant rate of 9 cubic feet per minute. If the pool has radius 3 feet and height 11 feet, what is the rate of change of the height of the water in the pool when the depth of the water in the pool is 9 feet?

  • Write, compile, and test a class that displays your first name on the screen. Save the...

    Write, compile, and test a class that displays your first name on the screen. Save the class as Name. Write, compile, and test a class that displays your full name, street address and city, on three separate lines on the screen. Save the class as Address. Write a java program which add two numbers and print the result on screen. Save the class as Add2. Write a java program which accepts two numbers from user multiply them and print the...

  • In this practical task, you need to implement a class called MyTime, which models a time...

    In this practical task, you need to implement a class called MyTime, which models a time instance. The class must contain three private instance variables: hour, with the domain of values between 0 to 23. minute, with the domain of values between 0 to 59. second, with the domain of values between 0 to 59. For the three variables you are required to perform input validation. The class must provide the following public methods to a user: MyTime() Constructor. Initializes...

  • A pool has a volume of 1000 ?3. At time ? = 0 the pool is...

    A pool has a volume of 1000 ?3. At time ? = 0 the pool is empty. We then fill in water the pool at a constant speed ? = 2.4?3 per minute. At the same time, water is leaking out the pool at a rate that is at all times proportional to the volume of water. The proportionality constant is ? = 3 ∙ 10−3??nute-1. Let ? (?) be the volume of water in the pool t minutes after...

  • Instructions: Refer to the Timel class provided in Figure 8.1 in your Deitel book to complete...

    Instructions: Refer to the Timel class provided in Figure 8.1 in your Deitel book to complete the exercise. Make sure that you follow the Program Style and Readability guidelines found in the Start Here Folder. 1. Write a Point class. The Point class should be written as an abstract data type. 2. Include the following instance variables: a. an integer representing the x coordinate b. an integer representing the y coordinate c. The instance variables in your program should only...

  • Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double...

    Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double variable that holds the rooms length(in feet). Breadth: The double variable that holds the rooms breadth(in feet). Height: Double variable that holds rooms height in feet. Color: String object that holds the color you want the room to be painted with. The class should have a constructor to initialize the fields for a particular instance (or object) of the class as given: All double...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT