Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, please modify the codes below following the guidelines, and please code in C thank you. Here is the codes from assignment 4: # include

Hi, please modify the codes below following the guidelines, and please code in C thank you.

Here is the codes from assignment 4:

#include

#include

#define max 25

struct CHANNEL

{

char name[50];

double n;

double slope;

double width;

double maxDepth;

};

double getPositiveValue()

{

double a;

scanf("%lf",&a);

while(a

{

printf("Enter a positive value: ");

scanf("%lf",&a);

}

return a;

}

void computeVelocity(double depth[max],double velocity[max],struct CHANNEL c)

{

int i;

double constant;

double exp=2.0/3.0;

constant=sqrt(c.slope)/c.n;

for(i=0;i

{

velocity[i]=(c.width/depth[i])/(c.width+2*depth[i]);

velocity[i]=pow(velocity[i],exp);

velocity[i]=velocity[i]*constant;

}

}

void displayTable(struct CHANNEL c)

{

double depth[max],velocity[max];

int i;

printf(" Channel data for Channel %s",c.name);

printf(" Coefficient for roughness: %0.4lf ",c.n);

printf(" Slope: %0.5lf ",c.slope);

printf(" Width: %0.2lf ",c.width);

printf(" Maximum depth: %0.2lf ",c.maxDepth);

printf("\tDepth\t\tAverage velocity ");

printf("------------------------------------------- ");

for(i=1;i

{

depth[i-1]=(i*c.maxDepth)/max;

}

computeVelocity(depth,velocity,c);

for(i=0;i

{

printf("\t%0.2lf\t\t%0.4lf ",depth[i],velocity[i]);

}

}

int main()

{

struct CHANNEL c;

printf("Give the name of the channel: ");

fgets(c.name,50,stdin);

printf("Give the coefficient of roughness: ");

c.n=getPositiveValue();

printf("Give the slope: ");

c.slope=getPositiveValue();

printf("Give the channel width: ");

c.width=getPositiveValue();

printf("Give the maximum depth to the channel: ");

c.maxDepth=getPositiveValue();

displayTable(c);

return 0;

}

Question 2

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

o 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 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: o Declare a variable of type CHANNEL which will contain channel characteristics. o 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.

o Get from the user values to initialize all the members of the structure variable of type CHANNEL by calling the function getInput.

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.

o This function DOES NOT return any value.

In the function fillArray: o 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. 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 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: o 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. o 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

o 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.

o It computes the average velocity of the water using Mannings equation and returns this value.

image text in transcribedimage text in transcribed

image text in transcribedimage text in transcribed

D:\Uofo\Courses\CurrentCourses\GNG1106\Fall2018\Assi... Give the name of the channel: Channel 1 Give the coefficient of roughness: 0.035 Give the slope: 0.0001 Give the channel width: 10 Give the maximum depth of the channel: 4.2 Channel data for "Channel 1" Coefficient of roughness: 0.0350 Slope: 0.00010 Width: 10.00 Maximum depth: 4.20 Depth Average velocity 0.17 0.9180 0.34 0.5661 0.50 0.4232 0.67 0.3424 0.84 0.2894 1.01 0.2515 1.18 0.2228 1.34 0.2002 1.51 0.1819 1.68 0.1667 1.85 0.1538 2.02 0.1428 2. 18 0.1333 0.1249 2.52 0.1175 2.69 0.1109 2.86 0. 1050 3.02 0.0997 3. 19 0.0948 3.36 0.0904 3.53 0.0864 3.70 0.0826 3.86 0.0792 4.03 0.0760 4.20 0.0731 Process returned 0 (0x0) execution time : Press any key to continue. 2.35 2/3 S/ B/H U= B+2H n Question 2 (10 marks) . o 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. 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 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 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 output. Be sure to properly format the values. 2/3 n The average velocity of water in a rectangular open channel can be calculated using the following Manning's equation. vs B/H U= B + 2H 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. O O O O O E D:\Uofo\Courses\CurrentCourses\GNG1106\Fall2018\Assi... Give the name of the channel: Channel 1 Give the coefficient of roughness: 0.035 Give the slope: 0.0001 Give the channel width: 10 Give the maximum depth of the channel: 4.2 Channel data for "Channel 1". Coefficient of roughness: 0.0350 Slope: 0.00010 Width: 10.00 Maximum depth: 4.20 Depth Average velocity 0.17 0.9180 0.34 0.5661 0.50 0.4232 0.67 0.3424 0.84 0.2894 1.01 0.2515 1.18 0.2228 1.34 0.2002 1.51 0. 1819 1.68 0.1667 1.85 0. 1538 2. 0.1428 0.1333 0. 1249 0.1175 0.1109 0. 1050 0.0997 0.0948 0.0904 0.0864 0.0826 0.0792 0.0760 4.20 0.0731 Process returned 0 (0x0) execution time: Press any key to continue. 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 get PostiveValue function from lab 5 and not the version from lab 4. This function DOES NOT return any value. O o . O O THI O O 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. o It computes the average velocity of the water using Manning's equation and returns this value. The following table gives three test cases to be used for testing your program. Name Channel 1 Name Channel 2 Name Channel 3 Roughness Roughness Roughness n n (s/m^1/3) 0.035 n (s/m^1/3) 0.0013 (s/m^1/3) 0.17 Slope (m) 0.0001 Slope (m) 0.0032 Slope (m) 0.041 Width(m) 10 Width (m) 2 Width (m) 40 Max. Depth Max. Depth Max. Depth (m) 4.2 11.5 1.5 Average Average Average Velocity Velocity Velocity Depth (m) (m/s) Depth (m) (m/s) Depth (m) (m/s) 0.1680 0.917961 0.4600 56.740241 0.0600 7.756067 0.3360 0.566077 0.9200 29.778691 0.1200 4.876297 0.5040 0.423161 1.3800 19.693713 0.1800 3.713932 0.6720 0.342380 1.8400 14.450211 0.2400 3.059721 0.8400 0.289368 2.3000 11.266883 0.3000 2.631589 1.0080 0.251450 2.7600 9.146052 0.3600 2.325820 1.1760 0.222759 3.2200 7.641631 0.4200 2.094561 1.3440 0.200172 3.6800 6.524830 0.4800 1.912415 1.5120 0.181859 4.1400 5.666601 0.5400 1.764548 1.6800 0.166669 4.6000 4.988857 0.6000 1.641663 1.8480 0.153840 5.0600 4.441703 0.6600 1.537612 2.0160 0.142843 5.5200 3.991847 0.7200 1.448154 2.1840 0.133301 5.9800 3.616268 0.7800 1.370260 2.3520 0.124935 6.4400 3.298570 0.8400 1.301702 2.5200 0.117535 6.9000 3.026780 0.9000 1.240806 2.6880 0.110939 7.3600 2.791958 0.9600 1.186282 2.8560 0.105020 7.8200 2.587308 1.0200 1.137124 3.0240 0.099677 8.2800 2.407573 1.0800 1.092530 3.1920 0.094829 8.7400 2.248630 1.1400 1.051856 3.3600 0.090410 9.2000 2.107203 1.2000 1.014577 3.5280 0.086363 9.6600 1.980655 1.2600 0.980258 3.6960 0.082644 10.1200 1.866844 1.3200 0.948540 3.8640 0.079214 10.5800 1.764015 1.3800 0.919119 4.0320 0.076040 11.0400 1.670711 1.4400 0.891740 4.2000 0.073095 11.5000 1.585720 1.5000 0.866183

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

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

Describe bond pricing as two time value of money problems

Answered: 1 week ago

Question

l Summarize the process of evaluating HR performance.

Answered: 1 week ago