Question: Follow the instruction and Debug the following C program code Debug the following program: /*------------------------------------------------------------------ File: CylinderVolume.c (Lab 5) Author: Gilbert Arbez, Fall 2016 Description:

Follow the instruction and Debug the following C program code

Follow the instruction and Debug the following C program code Debug the

following program: /*------------------------------------------------------------------ File: CylinderVolume.c (Lab 5) Author: Gilbert Arbez, Fall 2016

Debug the following program:

/*------------------------------------------------------------------ File: CylinderVolume.c (Lab 5) Author: Gilbert Arbez, Fall 2016 Description: Calculates how the volume changes for different depths in a horizontal cylinder. ------------------------------------------------------------------*/ #include #include #include

// Define symbolic constant #define N 50 // number of points to compute #define H_IX 0 // Index to row with depth, h, values #define VOL_IX 1 // Index to row with volume values #define NUM_ROWS 2 // number of rows in 2D array #define TRUE 1 #define FALSE 0

// Definition of a structure type for user input typedef struct { double radius; // in m double length; // in m } CYLINDER;

// Prototypes void getDimensions(CYLINDER *); void computeVolume(CYLINDER *, int n, double [][n]); /*-------------------------------------------------------------------- Function: main Description: Calls getDimensions to get cylinder dimensions from the user, computeVolume to fill in the matrix containing depth/volume pairs, and displays the contents of the matrix in a table. ----------------------------------------------------------------------*/ void main() { // Variable declarations CYLINDER cyl; // structure variable fo cylinder double points[NUM_ROWS][N]; // N points of depth/volume int ix; // for indexing the columns in the 2D array // Get input from user, the cylinder radius and length getDimensions(cyl); // Compute depth/volume points computeVolume(&cyl, N, points); // no & for the points array // Display results (could have used a function to display the results) // Setup the start of the table printf("The change in liquid volume of the cylinder with radius %.2f and length %.2f as depth changes is as follows. ", cyl.radius, cyl.length); printf("%10s %10s ","Depth", "Volume"); printf("------------------------ "); // Loop to display each column of the table. for(ix = 0; ix 0. ------------------------------------------------------------------------*/ void getDimensions(CYLINDER *cylPtr) { int flag; do { flag = TRUE; printf("Please enter the values for the cylinder radius and length: "); scanf("%lf %lf",&cylPtr->radius, &cylPtr->length); if( cylPtr.radius length radius; ix = 0; h = 0.0; // Loop for calculating each of the n depth/volume points. while(ix radius,2)*acos((cylPtr->radius-h)/cylPtr->radius); term2 = (cylPtr->radius - h)*sqrt(2.0*cylPtr->radius*h - pow(h,2)); dataPoints[VOL_IX][ix] = (term1 - term2)*cylPtr->length; // increment variables for next point ix = ix +1; } }

A. Exercise: Volume of a Horizontal Cylinder - Using arrays with functions (20 points) Another version of the cylinder problem has been provided in CylinderVolumeLab5.zip (contains a CodeBlocks project). In this new version a table of 50 depth/volume data points is displayed to show how the volume changes as the depth of the liquid in the horizontal cylinder increases. Again there are 3 bugs in this program that you need to discover and also 2 syntax errors that need correction. Recall that the volume of a liquid in a hollow horizontal cylinder with radius r and length L is related to the depth of the liquid, h, as The following table provides a test case that can be used for testing the software (this table was generated using Microsoft Excel, see the file GNG1106Lab5TestCases.xls; note that the Excel file also contains values for each of the terms in the above equation to help with debugging. The volumes were computed using the above equation. Radius (m eng Volume (m De Volume (m 0.000 38.792 40.768 42.740 44.705 46.661 48.605 50.532 52.439 54.324 56.182 58.009 59.802 61556 63.267 64.929 66.538 68.088 69.572 70.983 72.311 73.547 74.677 75.684 76.544 77.214 0.084 0.168 0.252 0.336 2.268 2.352 2.436 4.038 5.274 6.602 8.013 9.497 11.046 12.656 14.318 16.029 17.783 19.576 21.403 23.261 25.146 27.053 28.980 30.924 32.880 34.845 0.504 0.588 2.604 2.688 0.756 2.856 0.924 .008 1.092 1.176 3.024 3.108 3,192 3.276 1.344 3.444 3.528 3.612 3.696 1.596 .764 1.848 1.932 3.864 3.948 4.032 4.116 The following are some features used in this program. A structure is used to store the dimensions of the cylinder that is the radius and length. Note that a reference is passed to functions called by main, which implies that one of the parameters of the called functions is a pointer that references the structure variable declared in the main function. The depth/volume data points are stored in a 2D array. Each column of the array contains 2 values, one for the liquid depth and the other for the liquid's volume. Thus the first row contains

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!