Question

In: Computer Science

In this program, there are 3 bugs and 2 syntax errors. Please identify them! The source...

In this program, there are 3 bugs and 2 syntax errors. Please identify them! The source code is below.

The source code is in C:

/*------------------------------------------------------------------

File:  CylinderVolume.c  (Lab 3)

Author: Gilbert Arbez, Fall 2018

Description: Calculates how the volume changes for different depths

              in a horizontal cylinder.

------------------------------------------------------------------*/

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

// Define symbolic constant

#define N       50    // number of points to compute

#define TRUE    1

#define FALSE   0

// Prototypes

void computeDisplayVolume(double, double);

/*--------------------------------------------------------------------

Function: main

Description:  Gets from the user the radius and length of the cylinder,

              calls computeDisplayVolume to compute and display a table

              of how the volume changes with depth of a liquid in

              the cylinder.

----------------------------------------------------------------------*/

void main()

{

    // Variable declarations

    double radius;  // cylinder radius

    double length;  // cylinder length

    int flag;   // sentinelle for controlling data input

    // Get input from user, the cylinder radius and length

    do

    {

        flag = TRUE;

        printf("Please give cylider radius and length: ");

        scanf("%lf %lf",&radius, &length);

        if(radius <= 0.0 || length <= 0.0)

          {

              printf("Both values must be greater than zero.\n");

              flag = FALSE;

          }

    } while(flag == TRUE)

    // Compute/display depth/volume data

    computeDisplayVolume(radius, length);

}

/*------------------------------------------------------------------------

Function: computeDisplayVolume

Parameter

    radius - radius of the horizontal cylinder

    length - length of the horizontal cylinder

Description: Computes and displays depth/volume data points in a table

             that varies the depth of the liquid from 0 to the cylinder diameter.

             N such data points are computed (i.e. the increment in the

                                              value of h is 2r/N).

------------------------------------------------------------------------*/

void computeDisplayVolume(double radius, double length)

{

    // Declaration of variables

    double increment;   // how to increment the depth

    double h;           // depth value

    double volume;      // volume value

    int i ;             // loop counter

    // setup the variables

    increment = radius/N;

    h = 0.0;

    // Table Header

    printf("The change in liquid volume of the cylinder with radius %.2f \nand length %.2f as depth changes is as follows.\n",

            radius, length);

    printf("%10s    %10s\n","Depth", "Volume");

    printf("------------------------\n");

    // Loop for calculating each of the n depth/volume points.

    for(i = 0 i < N; i = i + 1)

    {

       volume = pow(radius,2)*acos((radius-h)/radius);

       volume = volume - (radius - h)*sqrt(2.0*radius*h - pow(h,2));

       volume = volume*length;

       // Display the row with ocmputed values

       printf("%10.2f    %10.2f\n", h, volume);

    }

}

Solutions

Expert Solution

C PROGRAM ===>

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

// Define symbolic constant

#define N 50 // number of points to compute

#define TRUE 1

#define FALSE 0

// Prototypes

void computeDisplayVolume(double, double);

/*--------------------------------------------------------------------

Function: main

Description: Gets from the user the radius and length of the cylinder,

calls computeDisplayVolume to compute and display a table

of how the volume changes with depth of a liquid in

the cylinder.

----------------------------------------------------------------------*/

void main()

{

// Variable declarations

double radius; // cylinder radius

double length; // cylinder length

int flag; // sentinelle for controlling data input

// Get input from user, the cylinder radius and length

do

{

flag = TRUE;

printf("Please give cylider radius and length: ");

scanf("%lf %lf",&radius, &length);

if(radius <= 0.0 || length <= 0.0)

{

printf("Both values must be greater than zero.\n");

flag = FALSE;

}
else
{
// Compute/display depth/volume data

computeDisplayVolume(radius, length);

}


} while(flag == TRUE);

}

/*------------------------------------------------------------------------

Function: computeDisplayVolume

Parameter

radius - radius of the horizontal cylinder

length - length of the horizontal cylinder

Description: Computes and displays depth/volume data points in a table

that varies the depth of the liquid from 0 to the cylinder diameter.

N such data points are computed (i.e. the increment in the

value of h is 2r/N).

------------------------------------------------------------------------*/

void computeDisplayVolume(double radius, double length)

{

// Declaration of variables

double increment; // how to increment the depth

double h; // depth value

double volume; // volume value

int i ; // loop counter

// setup the variables

increment = 2*radius/N;

h = 0.0;

// Table Header

printf("The change in liquid volume of the cylinder with radius %.2f \nand length %.2f as depth changes is as follows.\n",

radius, length);

printf("%10s %10s\n","Depth", "Volume");

printf("------------------------\n");

// Loop for calculating each of the n depth/volume points.

for(i = 0 ; i < N; i = i + 1)

{

volume = pow(radius,2)*acos((radius-h)/radius);

volume = volume - (radius - h)*sqrt(2.0*radius*h - pow(h,2));
volume = volume*length;
h = h+increment;

// Display the row with ocmputed values

printf("%10.2f %10.2f\n", h, volume);

}
printf("\n");
}

OUTPUT SCREENSHOT ===>


Related Solutions

Identify errors and correct them of the following Java program : 1. import java.utility.Random; 2. 3....
Identify errors and correct them of the following Java program : 1. import java.utility.Random; 2. 3. public class Sequen 4. 5. private int stand 6. private int calc; 7. 8. public Sequen(int numStand) 9. { 10. stand = numStand; 11. skip; 12. } 13. 14. public void skip() 15. { 16. Random sit = new Random(); 17. calc = sit.nextInt(stand) + 1; 18. } 19. 20. public getStand() 21. { 22. return stand; 23. } 24. 25. int getCalc() 26....
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public class Sequen 4.   5. private int stand   6. private int calc;   7.   8. public Sequen(int numStand) 9. { 10.         stand = numStand; 11.         skip; 12.         } 13.           14.         public void skip() 15.         { 16.         Random sit = new Random(); 17.         calc = sit.nextInt(stand) + 1; 18.         } 19.           20.         public getStand() 21.         { 22.         return stand; 23.         } 24.           25.         int getCalc() 26.         { 27.         return calc; 28.         } 29.         } Identify 5 other errors and give their Line Number, Error...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public class Sequen 4.   5. private int stand   6. private int calc;   7.   8. public Sequen(int numStand) 9. { 10.         stand = numStand; 11.         skip; 12.         } 13.           14.         public void skip() 15.         { 16.         Random sit = new Random(); 17.         calc = sit.nextInt(stand) + 1; 18.         } 19.           20.         public getStand() 21.         { 22.         return stand; 23.         } 24.           25.         int getCalc() 26.         { 27.         return calc; 28.         } 29.         } One error is already identified for you as shown below:...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public class Sequen 4.   5. private int stand   6. private int calc;   7.   8. public Sequen(int numStand) 9. { 10.         stand = numStand; 11.         skip; 12.         } 13.           14.         public void skip() 15.         { 16.         Random sit = new Random(); 17.         calc = sit.nextInt(stand) + 1; 18.         } 19.           20.         public getStand() 21.         { 22.         return stand; 23.         } 24.           25.         int getCalc() 26.         { 27.         return calc; 28.         } 29.         } One error is already identified for you as shown below:...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2. 3. public...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2. 3. public class Sequen 4. 5. private int stand 6. private int calc; 7. 8. public Sequen(int numStand) 9. { 10. stand = numStand; 11. skip; 12. } 13. 14. public void skip() 15. { 16. Random sit = new Random(); 17. calc = sit.nextInt(stand) + 1; 18. } 19. 20. public getStand() 21. { 22. return stand; 23. } 24. 25. int getCalc() 26. {...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public class Sequen 4.   5. private int stand   6. private int calc;   7.   8. public Sequen(int numStand) 9. { 10.         stand = numStand; 11.         skip; 12.         } 13.           14.         public void skip() 15.         { 16.         Random sit = new Random(); 17.         calc = sit.nextInt(stand) + 1; 18.         } 19.           20.         public getStand() 21.         { 22.         return stand; 23.         } 24.           25.         int getCalc() 26.         { 27.         return calc; 28.         } 29.         } One error is already identified for you as shown below:...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public class Sequen 4.   5. private int stand   6. private int calc;   7.   8. public Sequen(int numStand) 9. { 10.         stand = numStand; 11.         skip; 12.         } 13.           14.         public void skip() 15.         { 16.         Random sit = new Random(); 17.         calc = sit.nextInt(stand) + 1; 18.         } 19.           20.         public getStand() 21.         { 22.         return stand; 23.         } 24.           25.         int getCalc() 26.         { 27.         return calc; 28.         } 29.         } One error is already identified for you as shown below:...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public class Sequen 4.   5. private int stand   6. private int calc;   7.   8. public Sequen(int numStand) 9. { 10.         stand = numStand; 11.         skip; 12.         } 13.           14.         public void skip() 15.         { 16.         Random sit = new Random(); 17.         calc = sit.nextInt(stand) + 1; 18.         } 19.           20.         public getStand() 21.         { 22.         return stand; 23.         } 24.           25.         int getCalc() 26.         { 27.         return calc; 28.         } 29.         } One error is already identified for you as shown below:...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2. 3. public...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2. 3. public class Sequen 4. 5. private int stand 6. private int calc; 7. 8. public Sequen(int numStand) 9. { 10. stand = numStand; 11. skip; 12. } 13. 14. public void skip() 15. { 16. Random sit = new Random(); 17. calc = sit.nextInt(stand) + 1; 18. } 19. 20. public getStand() 21. { 22. return stand; 23. } 24. 25. int getCalc() 26. {...
identify the syntax errors in the following code:             public class Hello {                    &
identify the syntax errors in the following code:             public class Hello {                         private static int main(String [] args) {                                     string Msg=”Hello, Wrld!;                                     Sytem.out.println(msg+ “Ken")
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT