In: Computer Science
C language
A manufacturer wishes to determine the cose of producing open-top cylindrical containers. The surface area of the container is the sum of the area of the circular base plus the are of the outside the circumference of the base times the height of the container). Write a program to take the radius of the base, the height of the container, the cost per square centimeter of the material (cost), and the number of containers to be produced (quantity). Calculate the cost of each container and the total cost of producing all the containers.
Program must include a function that displays the welcome message to the user and a function that computes surface area. Costs are to be rounded to hundreths (i.e. 2 decimal places) at output.
Welcome Message:
Cost Calculator
Computes cost of materials to produce cylindrical containers.
#include
int welcome(){
printf(“Cost calculator\n”);
printf(“—————————“);
printf(“Computes cost of materials to produce cylindrical materials”);
return 0;} //welcome function ends
float surface(r,h){
#define pi = 3.1415
float area=2*pi*r*h+pi*r*r;
return area;} //surface function ends
int main(){
float r,h,c;
int n;
printf(“Enter the radius”);
scanf(“%f”,& r);
printf(“Enter the height”);
scanf(“%f”,&h);
printf(“Enter the cost per square centimetre of the material”);
scanf(“%f”,&c);
printf(“Enter the number of containers to be produced”);
scanf(“%d”,&n);
welcome(); // calling welcome function.
float surface_area=surface(r,h); //calling surface function and passing the values of radius and height.
float cost_per_container=surface_area*c; //calculating cost of each container.
float total_cost=cost_per_container*n; //calculating the total cost of all containers.
printf(“Cost of each container is %0.2f”,cost_per_container); //%0.2f will round off the cost to two decimal places.
printf(“Total cost of all container is %0.2f”,total_cost);
return 0;
}