Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer the following question based on the C programming language Question 2 (10 marks) For this question, repeat question 2 from assignment 4, but

Please answer the following question based on the C programming language

image text in transcribed

image text in transcribed

image text in transcribed

Question 2 (10 marks) For this question, repeat question 2 from assignment 4, but this time, you will use a number of functions to separate w ell the various tasks of the program. Recall the question from assi program. The average velocity of water in a rectangular open channel can be calculated using the following Manning's e tion. where U is the average velocity of the water (m/s), S is the channel slope n is the roughness coefficient (s/m13) 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. o o o 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 o o o o Fill the 2D array (or the two 1D arrays) by calling the function fillArray o Display on the console the desired output by calling the function displayTable o 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 . o This function has only a single parameter, a pointer to a value of type CHANNEL. o 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 o 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 o array (or the 1 D arrays) declared in the main function. o 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 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 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

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions

Question

What are the role of supervisors ?

Answered: 1 week ago