The surface area of a sphere is 4 pi r2 the surface are of c

The surface area of a sphere is 4 pi r^2, the surface are of cone is 2 pi R 2 pi R^2, and the surface area of a cube is 6L^2, where R is the radius of the shape, h is the height of the cone, and L is the length of a side of the cube. Construct a small library for these functions so that a user can your functions so calculate surface area if they have the dimensions. Make the code clear and easy to use.

Solution

STEPS FOR ADDING OUR OWN FUNCTIONS IN C LIBRARY:

STEP 1:

Create file “surfaceArea.c” and add the below code in it.

#define PI (3.141592653589793)

using namespace std;

float surfaceAreaOfSphere(int R){

    return 4*PI*R*R;

}

float surfaceAreaOfCone(int R, int H){

    return 2*PI*R*(H+R);

}

float surfaceAreaOfCube(int L){

    return 6*L*L;

}

STEP 2:

Compile “surfaceArea.c”

STEP 3:

“surfaceArea.obj” file would be created which is the compiled form of “surfaceArea.c” file.

STEP 4:

Use the below command to add this function to library (in turbo C).
c:\\> tlib math.lib + c:\\surfaceArea.obj

+ means adding c:\\surfaceArea.obj file in the math library.
We can delete this file using – (minus).

STEP 5:        

Create a file “surfaceArea.h” & declare prototype of the three functions like below.

float surfaceAreaOfSphere(int R);

float surfaceAreaOfCone(int R, int H);

float surfaceAreaOfCube(int L);

Now, surfaceArea.h file contains prototype of the three function.

Note: Please create, compile and add files in the respective directory as directory name may change for each IDE.

STEP 6:

Use our newly added library function in a C program.

# include <stdio.h>

// Including our user defined function.

# include “c:\\\\ surfaceArea.h”   // Path where you have saved surfaceArea.h file

int main()

{

   cout << \"Hello Humans\"

   << endl << surfaceAreaOfSphere(10) << endl

   << surfaceAreaOfCone(10) << endl

   << surfaceAreaOfCube(10) << endl;

  

   return 0;

}

---------------------------------------------------------------------THE END---------------------------------------------------------------------------

 The surface area of a sphere is 4 pi r^2, the surface are of cone is 2 pi R 2 pi R^2, and the surface area of a cube is 6L^2, where R is the radius of the shap
 The surface area of a sphere is 4 pi r^2, the surface are of cone is 2 pi R 2 pi R^2, and the surface area of a cube is 6L^2, where R is the radius of the shap

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site