Question

In: Computer Science

Write a C++ program to calculate the time to drain a cylindrical water tank for an...

Write a C++ program to calculate the time to drain a cylindrical water tank for an initial water height ranging from 1 to 10 feet (specifically for 1, 2, 4, 6, 8, and 10 ft). The tank has a radius (rt) of 2 feet and the drain radius (rd) is 0.3 inch. The gravitational constant (g) is 32.2 feet/sec2.

The formula for time to drain the tank is

time=(rtrd)2h/vavg

where, average velocity, vavg=0.5(2gh).5

In your program, assign the values to the variables rt, rd, and g. Prompt user to enter the value of h. The program should calculate the value of vavg, and then display time in hours.

Using MS Visual Studio, create a project folder called tank and a source code file tank.cpp.

Use the function pow() in the formulas and NOT sqrt().

Set up the output statements (cout) such that the one line display looks like the following:

Initial water height (ft.) = 1; Time to drain (hrs.) = 0.44

STEP 1: Analyze the Problem –

There is only one required output (time in hour of data type double) and one input (initial water height in ft of data type int). All intermediate variables will be assigned a data type of double.

STEP 2: Develop a Solution –

Pseudo code is shown below.

Convert all input data to the same unit (ft)

Display a prompt to enter initial height of water

Read a value for the height

Calculate average velocity, using the given formulas

Display the calculated time

Hand calculation for h = 1 ft, rt = 2 ft, rd = 0.3 inch, and g = 32.2 ft/sec2:

time = ?

STEP 3: Code the Solution -

You can start the program as shown below:

// Filename:

// C++ program to calculate time to drain water tank

// Written by: Your Name   ON: Date

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

int main()

{

     int h;

     double rt = 2.0, rd = 0.3, g = 32.2;

     double vavg, time;

// Input initial water height (h)

//---

// Set output formats

     cout << setiosflags(ios::fixed)

           << setiosflags(ios::showpoint)

           << setprecision(2);// Calculate average velocity in ft/hr

//---

// Calculate time in hrs to drain

// NOTE: The function pow(double a, int n) returns an

//---

// Display results in the specified format

//---

     return 0;

}

STEP 4: Test and Correct the Program -

If the program shows the correct output, copy and paste the output into MS Word. Also copy and paste the source code to the word processor as well. To copy the display window contents, click on the small black box in the upper left corner, select Edit -> Select All, then click again on the box and select Edit -> Copy.

Test the code by changing initial heights to 2, 4, 6, 8, and 10 feet.

Solutions

Expert Solution

Below is the code in C++:

#include<bits/stdc++.h>
using namespace std;

int main()
{
        int h;
        double rt = 2.0, rd = 0.3, g = 32.2;
        double vavg, time;

        // Input initial water height (h)
        cout << "Enter the initial water height (h) : ";
        cin >> h;

        // Set output formats
        cout << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(2);

        // Calculate average velocity in ft/hr
        // multiplied by 3600 to convert speed from ft/sec to ft/hr
        vavg = 0.5 * pow(2 * g * h, 0.5) * 3600.0;

        // Calculate time in hrs to drain
        time = pow((rt * 12 / rd), 2) * h / vavg;

        // Display results in the specified format
        cout << "Initial water height (ft.) = " << h << "; Time to drain (hrs.) = " << time << "\n";

        return 0;
}

Screenshot of the code for proper indentation:

OUTPUT:

Enter the initial water height (h) : 1
Initial water height (ft.) = 1; Time to drain (hrs.) = 0.44

Screenshot of the output:

**NOTE: If you understood the solution, please upvote the solution as it means a lot. If you have any doubt feel free to ask in the comment section below. Thanks!!


Related Solutions

- A cylindrical tank is being filled simultaneously with water and sugar. The input of water...
- A cylindrical tank is being filled simultaneously with water and sugar. The input of water and sugar is carefully adjusted so that the concentration of sugar in the water is held constant at 5 grams per cubic meter. The tank has a radius of 5 meters and a height of 10 meters. At a particular point in time, the water level is 3 meters high and rising at a rate of .5 meters per second. At this time, how...
An 800-gallon, 1.2 m wide cylindrical water tank is filled to the brim. The tank has...
An 800-gallon, 1.2 m wide cylindrical water tank is filled to the brim. The tank has a hole formed at 13.3 cm above the ground. It is observed that water leaks out of the reservoir at a speed that reduces by 3.2 m.s-1 in 1 minute 39 seconds. If the tank was initially filled to the brim how much water leaked out of the tank, and 8.2 by how much shall the point, at which water lands, change? (1 gallon...
You are assigned the design of a cylindrical, pressurized water tank for a future colony on...
You are assigned the design of a cylindrical, pressurized water tank for a future colony on Mars, where the acceleration due to gravity is 3.71 m/s2. The pressure at the surface of the water will be 110 kPa , and the depth of the water will be 13.7 m . The pressure of the air outside the tank, which is elevated above the ground, will be 85.0 kPa . Find the net downward force on the tank's flat bottom, of...
Use any C program without using PTHREADS calculate time taken to execute program. Write same program...
Use any C program without using PTHREADS calculate time taken to execute program. Write same program of question 1 using PTHREADS. Calculate time taken to execute program.(1 mark) Identify data races in above program and explain why this situation occurred with an example (1 mark) Rewrite the code to avoid data races should use any of the THREE techniques.(1.5 marks) please I need the c code.. critical section mutex solution semaphore functions Barriers Read-Write Locks Run program using 1, 2,...
1)A cylindrical water-tank has a small hole 60cm above the floor on which the tank stands....
1)A cylindrical water-tank has a small hole 60cm above the floor on which the tank stands. The depth of water in the tank is 1.8m.Assume the diameter of the tank to be greater than that of the hole. 1a) Find the horizontal distance from the side of the tank to the point on the floor where the stream of water lands. 1b) At what other height from the base of the tank would a second hole be drilled for water...
(Write a program in C++) A local instructor wants you to write a program to calculate...
(Write a program in C++) A local instructor wants you to write a program to calculate the average score made on exams by her students. For simplicity, she always has only 12 students in each course she teaches. She teaches multiple subjects so she would like to enter the name of the exam. She wants the program to also determine the highest and lowest scores and the number of students who passed and failed the exam. A score of 60...
A closed and elevated vertical cylindrical tank with diameter 2.00m contains water to a depth of...
A closed and elevated vertical cylindrical tank with diameter 2.00m contains water to a depth of 0.900m . A worker accidently pokes a circular hole with diameter 0.0190m in the bottom of the tank. As the water drains from the tank, compressed air above the water in the tank maintains a gauge pressure of5.00�103Pa at the surface of the water. Ignore any effects of viscosity. A. Just after the hole is made, what is the speed of the water as...
A closed and elevated vertical cylindrical tank with diameter 2.10 m contains water to a depth...
A closed and elevated vertical cylindrical tank with diameter 2.10 m contains water to a depth of 0.500 m . A worker accidently pokes a circular hole with diameter 0.0170 m in the bottom of the tank. As the water drains from the tank, compressed air above the water in the tank maintains a gauge pressure of 5.00×103 Pa at the surface of the water. Ignore any effects of viscosity. A)Just after the hole is made, what is the speed...
A water tank consists of a cylindrical part of radius r and height h and a hemispherical top. The tank is to be constructed to hold 600 m3
A water tank consists of a cylindrical part of radius r and height h and a hemispherical top. The tank is to be constructed to hold 600 m3 when filled. The surface area of the cylindrical part is 2πrh, and its volume is πr2h. The surface area of the hemispherical top is given by 2πr2, and its volume is given by 2πr3/3. The cost to construct the cylindrical part of the tank is $400 per square meter of surface area;...
Write a program in C++ that solves this problem Calculate the area and volume of a...
Write a program in C++ that solves this problem Calculate the area and volume of a sphere problem. Inside a for loop, vary the radius from 10 to 40  with a step or increment of 5 and calculate the area and volume Your radius will be equal to your loop counter. All calculations should have 2 decimal places, but the radius should have zero decimal places and any number of 1,000 or more should have a comma. Print the radius, area,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT