Question: please debug the following C code program: Correct the syntax errors and debug the program to find 3 bugs. code to debug: /*------------------------------------------------------------------ File: cylinderVolume.c

please debug the following C code program: Correct the syntax errors and debug the program to find 3 bugs.

please debug the following C code program: Correct the syntax errors and

debug the program to find 3 bugs. code to debug: /*------------------------------------------------------------------ File:

code to debug:

/*------------------------------------------------------------------ File: cylinderVolume.c (Lab 5) Description: Calculates how the volume changes w.r.t the depth of a liquid in a cylinder. ------------------------------------------------------------------*/ #include #include // Define symbolic constant #define TRUE 1 #define FALSE 0 #define NUM_VALUES 20 // Number of time/velocity values to display #define NUM_ROWS 2 // Number of rows in 2D array - one for depth and one for volume #define D_IX 0 // Index for elements containing depth values (row 0) #define V_IX 1 // Index for elements containing volume values (row 0) // Definition of a structure type for user input typedef struct { char orientation; // h for horizontal and v for vertical double radius; // in m double length; // in m } CYLINDER; // Prototypes void getInput(CYLINDER *); double getPositiveValue(char *); void fillArray(CYLINDER *, int n, double[][n]); double computeVolume(CYLINDER *, double); void displayTable(CYLINDER *, int n, double *, double *); /*-------------------------------------------------------------------- Function: main Description: Gets from the user values for the radius and length of the cylinder as well as it orientation. Fills an array with depth/volume values and then displays in a table these values. ----------------------------------------------------------------------*/ int main() { // Variable declarations CYLINDER cyl; // structure variable fo cylinder // Note in the following 2D array // points[D_IX] is a 1D array that contains the depth values // points[V_IX] is a 1D array that contains the volume values double values[NUM_ROWS][NUM_VALUES]; // NUM_VALUES depth/volume value pair // Get user input getInput(&cyl); // Fill in the array with depth/volume values fillArray(&cyl, NUM_VALUES, values); // Display table on console displayTable(&cyl, NUM_VALUES, values[D_IX], values[V_IX]); return(0); } /*----------------------------------------------------------------------- Function: getOrientation Description: Requests from the user the orientation of the cylinder: v for vertical and h for horizontal ------------------------------------------------------------------------*/ void getInput(CYLINDER *cylPtr) { int flag; // Get the cylinder radius and length cylPtr.radius = getPositiveValue("Please enter the value for the cylinder radius: "); cylPtr->length = getPositiveValue("Please enter the value for the cylinder length: "); // Get the orientation of the cylinder do { flag = FALSE; printf("Give the cylinder's orientation, v for vertical, h for horizontal: "); fflush(stdin); scanf("%c", &cylPtr->orientation); if(cylPtr->orientation != 'v' && cylPtr->orientation != 'h') { printf("Bad input. "); flag = TRUE; } } while(flag); } /*------------------------------------------------------------------------ Function: getPositiveValue Parameter: prompt: reference to a prompt message to the user Returns: A value strictly positive (>0) Description: Prompts for and reads a real value from the user, checks that it is strickly positive, and returns the value. ------------------------------------------------------------------------*/ double getPositiveValue(char *prompt) { double value; do { printf(&prompt); scanf("%lf",&value); if(value orientation == 'v') inc = cyl->length/(NUM_VALUES-1); else inc = cyl->radius/(NUM_VALUES-1); for(cix = 0; cix orientation == 'v') vol = M_PI*cyl->radius*cyl->radius*depth; else { // Utilise plusieurs intructions pour faire le calcule // Les valeurs intermdiaires sont accumules dans vol vol = sqrt(2*cyl->radius*depth - depth*depth); vol = (cyl->radius - depth)*vol; vol = (pow(cyl->radius,2)*acos((cyl->radius - depth)/cyl->radius)) - vol; vol = vol*cyl->length; } return(vol); } /*----------------------------------------------------------------------- Function: displayTable Parameters: cyl - pointer to a variable structure that gives the cylinder characteristics. int n - nnumber of elements in the referenced arrays depth - pointer to an array that contains the depth values volume - pointer to an array that contains the volume values Description: Displays the characteristics of the cylinder followed by a table that shows how the volume varies the depth of a liquide in the cylinder. The data is given in the arrays referenced by the parameters. ------------------------------------------------------------------------*/ void displayTable(CYLINDER *cyl, int n, double *depth, double *volume) { // Declaration of variables int ix; // Index into arrays. // Display results printf(" The change in liquid volume of the cylinder with radius %.2f and length %.2f as depth changes when ", cyl->radius, cyl->length); if(cyl->orientation == 'v') printf("vertical "); else printf("horizontal "); printf("%10s %10s ","Depth", "Volume"); printf("------------------------ "); for(ix = 1; ix

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!