Question

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 the water is draining from the bucket.
  • Must add the Bucket Constructor(s) and Destructor member functions. (10%)
  • Add appropriate accessor and mutator member functions.(10%)
  • Add member functions to do the following: (40%)
    • determine the amount of water needed to fill up an empty or partially filled bucket: void fillUpFull()
    • determine the time to fill the bucket: timeToFillTheBucket()
    • Allow adding or subtracting one or more buckets (add by adding height and radius, rates and amount – subtract by subtracting height, and radius, rates and amount): add(Bucket &other) andsubtract(Bucket &other)
  • Add a static property (data member) to count the number of buckets created and static member function to report this count.(20%)
  • NOTE: The amount of gallons in a cubic feet is 7.4

Please use the following driver program to test your class:

//Main program

//Main program

#include <iostream>

#include "bucket.h"

using namespace std;

int main()

{

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

              Bucket::getNumberOfBuckets() << endl;

       const int NUM_OF_BUCKETS = 3;

       Bucket buckets[NUM_OF_BUCKETS];

       buckets[0] = Bucket(3.0, 15.0);

       buckets[1] = Bucket(6.0, 25.0);

       buckets[2] = Bucket(3.5, 20.0);

       int waterFRate;

       int time;

       //Fill buckets[0] and buckets[1]

       buckets[0].fillUpFull();

       buckets[1].fillUpFull();

       cout << "Bucket data: " << endl;

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

       {

              cout << "\n\n";

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

              cout << " Height: " << buckets[i].getHeight() << endl;

              cout << " Radius: " << buckets[i].getRadius() << endl;

              cout << " Total water in the bucket (cubic feet): " <<

                     buckets[i].getTotalWaterInBucket() << endl;

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

              cout << " Enter water fill in rate (Gallons Per Minute): ";

              cin >> waterFRate;

              cout << endl;

              buckets[i].setWaterFlowRateIn(waterFRate);

              time = (int)buckets[i].timeToFillTheBucket();

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

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

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

       }

       //Add: Bucket[0] + Bucket[1] to create the addedBucket

       cout << "\n\nThe total after adding first two Buckets (cubic feet): " << endl;

       Bucket addedBucket = buckets[0].add(buckets[1]);

       cout << " Height: " << addedBucket.getHeight() << endl;

       cout << " Radius: " << addedBucket.getRadius() << endl;

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

              addedBucket.getTotalWaterInBucket() << endl;

       //Subtract: Bucket[1] - Bucket[2] to create the subBucket

       cout << "\n\nThe Total after Subtracting last two Buckets (cubic feet): " << endl;

       Bucket subBucket = buckets[1].subtract(buckets[2]);

       cout << " Height: " << subBucket.getHeight() << endl;

       cout << " Radius: " << subBucket.getRadius() << endl;

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

              subBucket.getTotalWaterInBucket() << endl;

       Bucket extraBucket(2.0, 10);

       cout << "\n\n\nThe total number of buckets created in this program is "

              << extraBucket.getNumberOfBuckets() << endl;

       system("pause");

       return 0;

}

//In your Bucket class, add the following Copy Constructor and operator= member functions to your class. (No modification is required to dthese function):

//Copy Constructor – Topic covered in chapter 11.

Bucket(const Bucket &copy) : RATE(copy.RATE)

       {

              height = copy.height;

              radius = copy.radius;

              waterFlowInRate = copy.waterFlowInRate;

              amountOfWaterInBucket = copy.amountOfWaterInBucket;

              numOfBuckets++;

       }

//Operator=(..) – assignment operator function

       Bucket & operator=(const Bucket &other)

       {

              if (this != &other)

              {

                     height = other.height;

                     radius = other.radius;

                     waterFlowInRate = other.waterFlowInRate;

                     amountOfWaterInBucket = other.amountOfWaterInBucket;

              }

              return *this;

       }

SAMPLE OUTPUT:

The initial total number of buckets in this program is 0

Bucket data:

BUCKET # 1:

Height: 15

Radius: 3

Total water in the bucket (cubic feet): 424.102

To completely fill the bucket:

Enter water fill in rate (Gallons Per Minute): 10

Time to fill the bucket is approximately: 0 hour(s) and 56 minute(s).

BUCKET # 2:

Height: 25

Radius: 6

Total water in the bucket (cubic feet): 2827.35

To completely fill the bucket:

Enter water fill in rate (Gallons Per Minute): 10

Time to fill the bucket is approximately: 6 hour(s) and 17 minute(s).

BUCKET # 3:

Height: 20

Radius: 3.5

Total water in the bucket (cubic feet): 0

To completely fill the bucket:

Enter water fill in rate (Gallons Per Minute): 10

Time to fill the bucket is approximately: 1 hour(s) and 42 minute(s).

The total after adding first two Buckets (cubic feet):

Height: 40

Radius: 9

Total water in the bucket: 3251.45

The Total after subtracting last two Buckets (cubic feet):

Water overflowed and bucket is now full. Height: 5

Radius: 2.5

Total water in the bucket: 98.1719

The total number of buckets created in this program is 6

Press any key to continue . . .

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

Answer:-

#include <iostream>

#include <cmath>

using namespace std;

class Bucket

{

private:

               double height, radius, amountOfWaterInBucket;

               int waterFlowInRate;

               static int numOfBuckets;

public:

               Bucket()

               {

                              radius = 0;

                              height = 0;

                              amountOfWaterInBucket = 0;

                              waterFlowInRate = 0;

                              //numOfBuckets++;

               }

               Bucket(double radius, double height)

               {

                              this->radius = radius;

                              this->height = height;

                              amountOfWaterInBucket = 0;

                              waterFlowInRate = 0;

                              numOfBuckets++;

               }

               Bucket(const Bucket &copy)

               {

                              height = copy.height;

                              radius = copy.radius;

                              waterFlowInRate = copy.waterFlowInRate;

                              amountOfWaterInBucket = copy.amountOfWaterInBucket;

                              numOfBuckets++;

               }

               Bucket & operator=(const Bucket &other)

               {

                              if (this != &other)

                              {

                                             height = other.height;

                                             radius = other.radius;

                                             waterFlowInRate = other.waterFlowInRate;

                                             amountOfWaterInBucket = other.amountOfWaterInBucket;

                              }

                              return *this;

               }

               void setHeight(double height)

               {

                              this->height = height;

               }

               void setRadius(double radius)

               {

                              this->radius = radius;

               }

               void setAmountOfWater(double amountOfWater)

               {

                              this->amountOfWaterInBucket = amountOfWater;

               }

               void setWaterFlowRateIn(int waterFlowRate)

               {

                              this->waterFlowInRate = waterFlowRate;

               }

               double getHeight()

               {

                              return height;

               }

               double getRadius()

               {

                              return radius;

               }

               double getTotalWaterInBucket()

               {

                              return amountOfWaterInBucket;

               }

               int getWaterFlowRateIn()

               {

                              return waterFlowInRate;

               }

               static int getNumberOfBuckets()

               {

                              return numOfBuckets;

               }

               void fillUpFull()

               {

                              amountOfWaterInBucket = (3.1415*radius*radius*height);

               }

               double timeToFillTheBucket()

               {

                              double total = (3.1415*radius*radius*height);

                              return(total/7.48);

               }

               Bucket add(const Bucket&other)

               {

                              double r = radius+other.radius;

                              double h = height+other.height;

                              Bucket added_bucket(r,h);

                              added_bucket.setAmountOfWater(amountOfWaterInBucket+other.amountOfWaterInBucket);

                              added_bucket.setWaterFlowRateIn(waterFlowInRate+other.waterFlowInRate);

                              return added_bucket;

               }

               Bucket subtract(const Bucket &other)

               {

                              double r = radius-other.radius;

                              double h = height-other.height;

                              Bucket sub_bucket(r,h);

                              double amountOfWater =amountOfWaterInBucket - other.amountOfWaterInBucket;

                              double volume = 3.1415*r*r*h;

                              if(amountOfWater > volume)

                              {

                                             cout<<"Water overflowed and bucket is now full."<<endl;

                                             sub_bucket.setAmountOfWater(volume);

                              }else

                                             sub_bucket.setAmountOfWater(amountOfWater);

                              sub_bucket.setWaterFlowRateIn(waterFlowInRate-other.waterFlowInRate);

                              return sub_bucket;

               }

};

int Bucket::numOfBuckets = 0;

//end of bucket.h

// main.cpp

//Main program

//Main program

#include <iostream>

#include "bucket.h"

using namespace std;

int main()

{

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

                             Bucket::getNumberOfBuckets() << endl;

                      const int NUM_OF_BUCKETS = 3;

                      Bucket buckets[NUM_OF_BUCKETS];

                      buckets[0] = Bucket(3.0, 15.0);

                      buckets[1] = Bucket(6.0, 25.0);

                      buckets[2] = Bucket(3.5, 20.0);

                      int waterFRate;

                      int time;

                      //Fill buckets[0] and buckets[1]

                      buckets[0].fillUpFull();

                      buckets[1].fillUpFull();

                      cout << "Bucket data: " << endl;

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

                            {

                                   cout << "\n\n";

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

                                   cout << " Height: " << buckets[i].getHeight() << endl;

                                   cout << " Radius: " << buckets[i].getRadius() << endl;

                                   cout << " Total water in the bucket (cubic feet): " <<

                                          buckets[i].getTotalWaterInBucket() << endl;

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

                                   cout << " Enter water fill in rate (Gallons Per Minute): ";

                                   cin >> waterFRate;

                                   cout << endl;

                                   buckets[i].setWaterFlowRateIn(waterFRate);

                                   time = (int)buckets[i].timeToFillTheBucket();

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

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

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

                            }

                      //Add: Bucket[0] + Bucket[1] to create the addedBucket

                             cout << "\n\nThe total after adding first two Buckets (cubic feet): " << endl;

                             Bucket addedBucket = buckets[0].add(buckets[1]);

                             cout << " Height: " << addedBucket.getHeight() << endl;

                             cout << " Radius: " << addedBucket.getRadius() << endl;

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

                                    addedBucket.getTotalWaterInBucket() << endl;

                             //Subtract: Bucket[1] - Bucket[2] to create the subBucket

                             cout << "\n\nThe Total after Subtracting last two Buckets (cubic feet): " << endl;

                             Bucket subBucket = buckets[1].subtract(buckets[2]);

                             cout << " Height: " << subBucket.getHeight() << endl;

                             cout << " Radius: " << subBucket.getRadius() << endl;

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

                                    subBucket.getTotalWaterInBucket() << endl;

                             Bucket extraBucket(2.0, 10);

                             cout << "\nThe total number of buckets created in this program is "

                                    << extraBucket.getNumberOfBuckets() << endl;

                             system("pause");

                             return 0;

}

Add a comment
Know the answer?
Add Answer to:
Bucket Management – In this programming exercise you will create a simple bucket management program according...
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
  • A) One of the problems that have been discussed in the class is to write a simple C++ program to ...

    C++ programming question will upvote A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following int main //the radius of the...

  • please do the program in simple programming it is for my first c++ computer class i...

    please do the program in simple programming it is for my first c++ computer class i posted the example on pic 2,3 which is how this should be done Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of services: regular and premium. Its rates vary depending on the type of service. The rates are computed as follows: Regular service: $10.00 plus the first 50 minutes are free. Charges for...

  • C++ programming language: In this program you will create a simplified bag that acts like a...

    C++ programming language: In this program you will create a simplified bag that acts like a stack meaning that the Last item inserted is the First Item that comes out. Your backend implementation must use a linked list. The code should pass the test (there's only 1) and there should be no memory leaks. Note that passing the test does not ensure full credit! The functions are listed in the suggested order of implementation but you may implement them in...

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

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

  • C++ Create a program that finds the dot product of two vectors. I'm currently trying to...

    C++ Create a program that finds the dot product of two vectors. I'm currently trying to display the dot product by calling the dotProduct member function however I am confused as to how to do this. What would be the proper way to display the dot product? I don't believe my dotProduct member function is set up correctly to access the proper data. Feel free to modify the dotProduct member function to allow for it to work with the other...

  • A) One of the problems that have been discussed in the class is to write a...

    A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following: int main() { double radius; double area; double circumference; //the radius...

  • C++ Object Oriented assignment Can you please check the program written below if it has appropriately...

    C++ Object Oriented assignment Can you please check the program written below if it has appropriately fulfilled the instructions provided below. Please do the necessary change that this program may need. I am expecting to get a full credit for this assignment so put your effort to correct and help the program have the most efficient algorithm within the scope of the instruction given. INSTRUCTIONS Create a fraction class and add your Name to the name fraction and use this...

  • Write a C++ program to display workers schedule for a company. To accomplish this (1) Write...

    Write a C++ program to display workers schedule for a company. To accomplish this (1) Write a struct Time with attributes (at least) : hours, minutes and seconds. Add other functions or attributes you need to get the job done (2) Write a class Schedule with attributes : Day of week, start_time, end_time and activity. Schedule should have at least (a) Display to display the schedule (b) Length to return the duration of the schedule (ie end_time - start_time), (c)...

  • THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #inclu...

    THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #include "pch.h" #include #include using namespace std; // Function prototype void displayMessage(void); void totalFees(void); double calculateFees(int); double calculateFees(int bags) {    return bags * 30.0; } void displayMessage(void) {    cout << "This program calculates the total amount of checked bag fees." << endl; } void totalFees() {    double bags = 0;    cout << "Enter the amount of checked bags you have." << endl;    cout <<...

  • C++ Programming Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member fu...

    C++ Programming Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member functions inside Date.h and Date.cpp. Step 2. Design another ADT that implements a class named Watch, add 3 private member variables hour, minute, second, along with their appropriate public constructor / getter / setter member functions inside Watch.h and Watch.cpp. Step 3. Next, implement the additional SmartWatch...

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
ADVERTISEMENT