Question
Debug the following C Code The C code to debug: /*------------------------------------------------------------------ File: CylinderVolume.c (Lab 5) Author: Gilbert Arbez, Fall 2016 Description: Calculates how the volume
Debug the following C Code
The C code to debug:
/*------------------------------------------------------------------ File: CylinderVolume.c (Lab 5) Author: Gilbert Arbez, Fall 2016 Description: Calculates how the volume changes for different depths in a horizontal cylinder. ------------------------------------------------------------------*/ #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; } }
C. Exercise: Revisiting the Free Falling Parachutist - Using Loops to work with Arrays (60 marks) It's time to revisit again the program that computes how the velocity of a parachutist changes between t- 0 and time t-(where t-0 is when the parachutist jumped out of a hot air balloon and his or her velocity is zero. The parachute is open immediately). You shall use a loop to update the contents of arrays with time/velocity data points and a table is used to display the results. The program is very similar to the one in exercise A, but there are some differences. Recall that the velocity as a function of time, v(t), is calculated as gm 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 GNG1106LabSTestCases.xls). The velocity is computed using the above equation. Weight Drag Coefficient Final Time Time t Velocity TimetVelocity 0.00 0.00 6.24 2.306.48 6.72 6.96 36.41 0.48 0.72 0.96 4.50 37.84 38.51 39.15 39.76 40.35 40.91 8.63 0.55 12.40 7.44 7.68 7.92 1.44 15.86 17.48 19.02 20.50 21.92 23.28 24.58 8.40 8.64 8.88 41.97 42.46 42.93 43.38 43.81 44.22 44.62 45.00 45.36 45.71 46.04 46.35 46.66 46.95 47.22 47.49 2.88 68.1 12.5 12.0 9.36 9.60 9.84 27.0110.08 3.84 4.08 4.32 4.56 4.80 5.04 5.28 5.52 5.76 6.00 29.23 10.56 32.22 11.28 33.13 11.52 34.84 12.00 35.64 artially completed program A project containing a p Here are a few notes/guidelines is provided. Your task is to complete the program. The program's tasks are divided into three functions, one for getting user input (getInput), one for computing data points (computeVelocity) and one for displaying the table of results (displayTable). A single structure contains all data related to the parachutist including the input data (weight, drag and final time) as well as output data (an array with time values and an array with velocity values). You must add the members to this structureStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started