For the following program, you should run each of them using Dev-C++. You answer
ID: 3847114 • Letter: F
Question
For the following program, you should run each of them using Dev-C++. You answer should include screen shots of your code and program outputs and the codes as a TEXT so I can copy them and test them by myself. Your programs should be properly commented. Write a program (USE C Language NOT C++) that asks the user to input the height and radius of a cone (both of type double) and calls 4 individual functions to calculate the base area of the cone, the surface area of the cone (Conic Area), the total area of the cone, and the volume of the cone. The main function then prints these values with appropriate messages.Explanation / Answer
#include <stdio.h>
#include <math.h>
#define PI 3.14
double getSurfaceArea(double h, double r) {
return PI * r * (r +sqrt(h * h + r * r) );
}
double getVolume(double h, double r) {
return ( PI * r * r * h)/3;
}
double getBaseArea(double h, double r) {
return PI * r * r ;
}
double getTotalArea(double h, double r) {
return PI * r *(sqrt(h * h + r * r) );
}
int main()
{
double h,r;
printf("Enter the height: ");
scanf("%lf", &h);
printf("Enter the radius: ");
scanf("%lf", &r);
printf("Surface Area: %lf ", getSurfaceArea(h,r));
printf("Volumn: %lf ", getVolume(h,r));
printf("Base Area: %lf ", getBaseArea(h,r));
printf("Total Area: %lf ", getTotalArea(h,r));
return 0;
}
OUtput:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter the height: 2
Enter the radius: 4
Surface Area: 106.410028
Volumn: 33.493333
Base Area: 50.240000
Total Area: 56.170028
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.