Pledge: You may on this pledged assignment work in groups of two or three. Your partners must be from your same lab section. If you violate the section rule, your grade on the assignment will be cut in half. Your group may discuss the content of this assignment and your approach with anyone, but your group must do all if its own work. The group must create the logic of the solution, type the code, and compile, execute, and debug its own program. Your group may not use any code developed by anyone else. Your group's source code submitted electronically must match exactly the code you deliver in your lab section. Only one member of the group should submit the program electronically and only one printed copy should be handed in. The header comment section of your program should identify all members of the group. A person cannot be added to a group retroactively. So make sure your name is listed as part of your group's submission.

When engineers build a storm drain, they have to know how deep the water will be when a known volume of water is running through it. Manning’s equation describes the flow of water through a channel:

*Q*= (1.49*A**R*^{2/3}*S*^{1/2})/*N*

where

*Q*is the flow of water in units of cubic feet per second;*N*is the roughness coefficient (unitless);*A*is the area of a channel flow cross-section (square feet);*S*is the slope of the channel (feet/foot);*R*is the hydraulic radius (feet). The hydraulic radius is the cross-sectional area divided by the wetted perimeter.

For rectangular channels, the hydraulic radius is:

- R = (D*W) /(2D + W)

where

- D is the depth of the channel flow
- W is the width of the channel

You are given a rectangular channel that is 16 feet wide and has walls that are 8 feet high. It has a slope of 0.0014 feet/foot and its roughness coefficient is 0.015. How deep will the water be when the water flow is 1,000 cubic feet per second?

To answer that question, you are to design and implement a program that reacts to a user iteratively guessing a depth. For each depth guessed, the program should display the corresponding flow. The process of guessing a depth should continue until the depth guessed results in a computed flow that is within 0.1% of the target flow of 1,000 cubic feet per second.

To make your task easier we have done some of the algorithmic design for you.

- Print out a text message that explains what the program computes and what the user is required to do.
- Prompt the user for a guess of water depth. The range of legitimate guesses is bounded by 0 feet (channel empty) and by 8 feet (channel full).
- Extract the user’s guess for the depth. If the user enters a number less than zero or greater than 8, print out an appropriate message and prompt again for a legitimate guess.
- Compute, as a function of the depth, the flow Q, the difference between Q and 1,000, and the error percentage.
- If the computed flow is within 0.1% of the target flow (1,000 cubic feet per second), print a message indicating that the user’s guess was correct; if the error exceeds 0.1%, return to step two.

Using this high-level design, we can produce the following more detailed design of the individual steps

- Print appropriate text that describes the problem. An example output would be:
This program computes the flow rate in units of cfs (cubic feet per second) of water in a rectangular channel with a width of 16 feet, a slope of 0.0014feet/foot, and a roughness coefficient of 0.015 for a given depth of water (in feet) input by the user (0 <= depth <= 8). The user should input an estimate of the water depth that will result in a desired flow of 1,000 cubic feet per second. If the computed flow rate is too low, guess a higher depth; if too large, guess a lower depth. The program terminates when the depth guessed results in a calculated flow rate that is within 0.1% of the target flow rate.

- Prompt the user to input a guess for the depth. An example prompt might
be
Input a guess of the water depth (0 <= depth <= 8) that will result in a flow of 1,000 cubic feet per second:

- Input the user’s guess for the depth.
- If the user inputs a number outside the valid range, issue an appropriate message and repeat step two. If the user does not provide a guess, exit the program; otherwise continue at step
four.

- If the user inputs a number outside the valid range, issue an appropriate message and repeat step two. If the user does not provide a guess, exit the program; otherwise continue at step
four.
- Compute the flow
*Q*, the absolute difference between*Q*and 1,000, and the percentage error.- Computing
*Q*and the absolute difference are straightforward - The percentage error is given by: 100.0 |
*Desired Flow*-*Q*| /*Desired Flow*

- Computing
- Print the depth, the computed flow, the target flow, the absolute difference between the computed and target flows, and the percentage error between the computed and target flows.
An example output in which you need to go back to step 2 because the error
is greater than 0.1%
Depth: 4.5000 feet Flow: 541.6929 cfs Target: 1000.0000 cfs Difference: 458.3071 cfs Error: 45.8307%

An example final output could be

At a water depth of 6.9900 feet the desired flow is obtained.

- Print each of the values using four decimal places of precision. To get such output requires the use of the iomanip library. You may find manipulators setprecision() and fixed helpful.
- Compute R
^{2/3}using the pow() function. Computer S^{1/2}using the sqrt() function. Compute the absolute value using the fabs() function. These three functions can be found in the cmath library. - For those values that are numerical constants, use appropriately named constants. We might test your program on a different collection of values. In this regard, make sure your problem description displayed in step 1 uses the named constants. Output statements are ones in which programmers often forget to use their named constants.
- All variables and constants should be of type double.
- You must provide both an electronic and a printed copy of your program. Submit
an electronic copy using the name
*flow.cpp*. The electronic copy must be submitted prior to the beginning of lab 7. A submission under the wrong name will loose 10% of the grade. Attach a copy of the grading criteria to your solution when you hand it in. - The printed copy must be an exact duplicate of the electronic copy. It is to be submitted at the start of lab 7.
- The assignment is pledged. You may receive help only from the CS101 teaching assistants, the ITC consultants, and the CS101 professors.
- Late homework assignments are not accepted.