Homework 5 

Assigned in Laboratory 6, Due at Start of Laboratory 7

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.

Water Flow in a Channel

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:

where

For rectangular channels, the hydraulic radius is:

where

Your  Problem

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.

High-Level Solution Design

  1. Print out a text message that explains what the program computes and what the user is required to do.
  2. 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).
  3. 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.
  4. Compute, as a function of the depth, the flow Q, the difference between Q and 1,000, and the error percentage.
  5. 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

Detailed Design

  1. Print appropriate text that describes the problem. An example output would be:
  2. Prompt the user to input a guess for the depth. An example prompt might be
  3. Input the userís guess for the depth.
  4. Compute the flow Q, the absolute difference between Q and 1,000, and the percentage error.
  5. 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. 

Requirements