Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a library (i.e. a .h header and .c source file) that calculates volume of

ID: 3781015 • Letter: C

Question

Create a library (i.e. a .h header and .c source file) that calculates volume of three geometric shapes: the sphere, the right (untilted) cylinder, and the ellipsoid (look it up!). The user supplies the appropriate parameter such as radius for the sphere in decimal form when calling the function. Your function returns the volume.

All the formulas use p; use a #define statement in the source code to replace _PI_   with 3.14159. Underscores in defined names are used to avoid unwanted substitutions; you wouldn’t want PIE to become 3.14159E for example.

Make sure you name the functions and variables to enhance readability. Add comments for clarity.

If you have main() or printf() in your source code you are not doing what I am asking.

C PROGRAMMING

Explanation / Answer

Header file:VOLUME.H

float volumeSphere(float radius);
float volumeCylinder(float radius,float height);
float volumeEllipsoid(float a,float b, float c);

Source code: VOLUME.C

# define _PI_ 3.14159
float volumeSphere(float radius)
{
    return (4 * _PI_ * radius * radius * radius)/3;
}

float volumeCylinder(float radius,float height)
{
    return _PI_ * radius * radius * height;
}
float volumeEllipsoid(float a,float b, float c)
{
    return (4 * _PI_ * a * b * c)/3;
}

Main code to test:

#include <stdio.h>
#include <stdlib.h>
#include "volume.h"
int main(void){
    float radius,height,a,b,c;
  
     printf(" *******Calculate Volumd of sphere******** ");
    printf("Enter radius: ");
    scanf("%f",&radius);
    printf("Volums of Sphere is %f", volumeSphere(radius));
    printf(" **************************************** ");
  
    printf(" *******Calculate Volumd of Cyclinder******** ");
    printf("Enter radius: ");
    scanf("%f",&radius);
     printf("Enter height: ");
    scanf("%f",&height);
    printf("Volums of Sphere is %f", volumeCylinder(radius,height));
    printf(" **************************************** ");
  
     printf(" *******Calculate Volumd of Ellipsoid******** ");
    printf("Enter side of a: ");
    scanf("%f",&a);
     printf("Enter side of b: ");
    scanf("%f",&b);
     printf("Enter side of c: ");
    scanf("%f",&c);
    printf("Volums of Sphere is %f", volumeEllipsoid(a,b,c));
    printf(" **************************************** ");
    return 0;
}

Sample Output:

*******Calculate Volumd of sphere********                                                                                                                                                                                                      

Enter radius: 7                                                                                                                                                                                                                                

Volums of Sphere is 1436.753784                                                                                                                                                                                                                

****************************************                                                                                                                                                                                                       

                                                                                                                                                                                                                                               

*******Calculate Volumd of Cyclinder********                                                                                                                                                                                                   

Enter radius: 7                                                                                                                                                                                                                                

Enter height: 6                                                                                                                                                                                                                                

Volums of Sphere is 923.627441                                                                                                                                                                                                                 

****************************************                                                                                                                                                                                                       

                                                                                                                                                                                                                                               

*******Calculate Volumd of Ellipsoid********                                                                                                                                                                                                   

Enter side of a: 2                                                                                                                                                                                                                             

Enter side of b: 3                                                                                                                                                                                                                             

Enter side of c: 4                                                                                                                                                                                                                             

Volums of Sphere is 100.530884                                                                                                                                                                                                                 

****************************************

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote