Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c coding question For this question, repeat question 2 from assignment 4, but this time, you will use a number of functions to separate well

c coding question

For this question, repeat question 2 from assignment 4, but this time, you will use a number of functions to separate well the various tasks of the program. Recall the question from assignment 4.

The average velocity of water in a rectangular open channel can be calculated using the following Mannings equation.

where U is the average velocity of the water (m/s),

S is the channel slope

n is the roughness coefficient (s/m1/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 new guidelines to develop your program.

  • Definitions
    • 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.
    • Use a symbolic constant to determine the number of lines to display in the table on the console. Use 25 lines in the table to display. Use other symbolic constants to eliminate magic numbers in your program.
  • In the main function:
    • Declare a variable of type CHANNEL which will contain channel characteristics.
    • Declare either a two dimensional (2D) array or two one dimensional (1D) array which shall contain values of type double. In the case of the 2D array, the first row contains the water depth values and the second row contains average water velocity values. In the case of two 1D arrays, one array contains the water depth values and the other contains average water velocity values.
    • Get from the user values to initialize all the members of the structure variable of type CHANNEL by calling the function getInput.
    • Fill the 2D array (or the two 1D arrays) by calling the function fillArray.
    • Display on the console the desired output by calling the function displayTable.
    • Thus the main function contains only 3 calls to functions (in addition to declaring variables). Address of the structure variable and arrays are passed to the called functions.
  • In the function getInput:
    • This function has only a single parameter, a pointer to a value 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 CylinderVolumeLab5 project to ensure that a positive value is stored in each of these members. Be sure to use the getPostiveValue function from lab 5 and not the version from lab 4.
    • This function DOES NOT return any value.
  • In the function fillArray:
    • This function has a pointer parameter to a value of type CHANNEL. It also has the necessary parameters to fill the 2D array (or the 1D arrays) declared in the main function.
    • The function shall fill in the array(s) with the values of depth and average velocity. It obtains the values of average velocity by calling the function computeVelocity. Note that Mannings 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.
  • In the function displayTable:
    • This function has a pointer parameter to a value of type CHANNEL. It also has the necessary parameters to fill the 2D array (or the 1D arrays) declared in the main function.
    • 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.
  • Function computeVelocity
    • This function has two parameters, one of type double which gives the depth of the water, and the second of type pointer to a value of type CHANNEL which contains the characteristics of the channel.
    • It computes the average velocity of the water using Mannings equation and returns this value.image text in transcribed
The average velocity of water in a rectangular open channel can be calculated using the following Manning's equation. 1106Fall2018 Assi... e channe l: roughness ive the slope: ive the channel width: 10 ive the maximum depth of the channel: 4.2 data for "Channel 1" lcien roughness: 0.0350 10 Maximum depth: 4.20 Pth Average velocity 0. 9180 0.67 84 01 0.342 0.2894 8 142 03 0731 Process returned (0xO) execution time: Press any key to cont i nue Name Name Roughness n (s/m 1/3) 0035 Roughness (Sm1/3)0.17 e (m) 0.0001 Width(m) 10 Max. Depth 0.0032 Width Max. Depth Width (nm Average verage Velocity th (m 0.1680 0.917961 0.3360 0.56607 0.5040 0.423161 0.6720 0.342380 0.8400 0.289368 7 0.4600 56.740241 0.920029.778691 1.380019.693713 1.8400 14.450211 000 11.266883 7600 9.146052 3.2200 7.641631 3.6300 I 6.524830 5.666601 4.6000 4.933857 5.06004.441703 0.0600 7.75606 0.1200 4.876297 0.2400 3.059721 0.30002.631589 1.17600.222759 1.34400.200172 0.4200 2.094561 1.6800 0.166669 2.0160 0.142843 2.1840 0.133301 0.60001.641663 0.6600 1537612 7200 1.448154 0.78001.370260 0.8400 1.301702 40806 0.9600 1.186282 5.5200 .98003.616268 6.9000 0.9000 2.6880 0.110939 0240 0.09967 3.3600 0.090410 3.6960 0.082644 4.0320 0.076040 7.36002.791958 1.0800 1.092530 1400051856 1.20001.014577 1.2600 0.980258 1.3200 0.943540 8.7400 2.248630 9.6600 1.980655 0.12001.866844 11.0400 1.670711 1.4400 0.891740

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

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions