Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C code that meets the following requirements and matches the test cases: Question 2 (25 marks) The average velocity of water in a

Write a C code that meets the following requirements and matches the test cases: image text in transcribed image text in transcribed

Question 2 (25 marks) The average velocity of water in a rectangular open channel can be calculated using the following Manning's equation 2/3 S( BIH where U is the average velocity of the water (m/s), S is the channel slope n is the roughness coefficient (s/ml/3) B is the width (m) H is the depth of the water (m) Develop a program that requests from the user characteristics of the channel and display in table form how the average velocity of the water varies with its depth in the channel. Use the following guidelines in developing your program. Use a C structure type: Define a structure type CHANNEL that contains with members for the values for the open channel, that is, members name that holds a string for the name of the channel, n (roughness coefficient), slope (value of S), width (value of B), and maxDepth that holds the maximum water depth possible in the channel. o In the main function: Obtain from the user the values to fill all members of a structure variable of type CHANNEL. Use the function fgets to initialise the member name (this function will place the complete line typed by the user including spaces as opposed to the scanf function that stops when it encounters a space). For the value of the other members of the structure variable (that are of type double), used the function getPositiveValue from the CylinderVolumeLab4 project to ensure that a positive value is stored irn each of these members. o Call the displayTable function to display a table that shows how the average speed of the water changes with its depth in the channel. The function will also display the characteristics of the channel. o Function displayTable o This function will have one parameter of type CHANNEL Use a symbolic constant to determine the number of lines to display in the table. Use 25 as the value for this constant. Use other symbolic comments where appropriate to avoid magic numbers. o In a first step, the function shall fill one or two arrays with the values of the depth and average velocity to display; you have the option of using one 2D array or two 1D arrays. The function obtains values for the average speed by calling the function computeVelocity. Note that Manning's equation cannot be applied to a depth with value 0. Thus the displayed table does not start at a depth of 0, but at the increment value used to increment the depth of the water. o In a second step, the function displays on the console first the characteristics of the channel followed by a table of 25 lines that shows how the average speed of the water changes with its depth. The following shows an example of the desired output. Be sure to properly format the values. o Function computeVelocity This function has two parameters, one of type double which gives the depth of the water, and the second of type CHANNEL which contains the characteristics of the channel. o

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

3. What are potential solutions?

Answered: 1 week ago