1. Create a file named geometry.h that will contain the following functions: Vol
ID: 3772597 • Letter: 1
Question
1. Create a file named geometry.h that will contain the following functions:
VolSphere()
AreaSphere()
VolCone()
AreaCone()
VolCylinder()
AreaCylinder()
VolDonut()
Today's diet will consist of the following junk food:
An ice cream cone 4.5" high with a diameter of 2.5" on top. The cone is filled with ice cream.
On top of the cone sits two scoops (spheres) of chocolate ice cream, each with a diameter of 3".
For desert, you will eat a half dozen Krispy Kreme donuts (toruses). Each 4" diameter donut has a 2" diameter hole.
Write a program that will calculate the approximate total volume of junk food you will eat today. Use any necessary functions from your geometry.lib file. Hint: You may need to convert the numbers used above to the types of numbers used by your functions.
Please turn in both the geometry.h file and your main program, along with the output.
Explanation / Answer
Geometry.h
#include <iostream>
#include <math.h>
float VolSphere(float r)
{
return 4.0/3.0* 3.14 * r * r * r;
}
float AreaSphere(float r,float h)
{
return (sqrt(r * r + h * h));
}
float VolCone(float b, float h)
{
return 1/3 * b * h;
}
float AreaCone(float r,float h)
{
return 3.14 * r * (sqrt(r * r + h * h));
}
float VolCylinder(float r,float h)
{
return 0.3333 * 3.14 * r * r * h;
}
float AreaCylinder(float r,float h)
{
return 2 * 3.14 * r * ( h + r);
}
float VolDonut(float r)
{
return 2 * 3.14 * 3.14 * r * r * r;
}
Main.Cpp
#include <iostream>
using namespace std;
#include "geometry.h"
#include "math.h"
main ()
{
cout << "An ice cream cone" << endl;
cout << "the volume is "<< 2 * VolSphere(1.5) + VolCone(1.25,4.5) + 6 * VolDonut (1.25,0.5);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.