The assignment is :
Write a C++ program that calculates the volume of 3 different geometric shapes. Your
program should give the user a menu like the following and repeat until the user wants to stop.
Volume Calculation Program
Select the Number of Your Chosen Object
1. Dumbbell
2. Axle
3. Spear
When the user selects one of the 3 objects, the program should then request the appropriate measurements (in inches) and then calculate and display the volume of that object. The result should be printed showing cubic-inch units with 3 decimals of precision.
Axle: 2 cylinders and a rod
Dumbbell: two spheres and a rod
Spears: two cones and a rod
Program requirements and Assumptions
Formulas and Abbr.
II P1 = 3.141 59
r radius
= height (or length)
Vol. of a sphere = 4I3flr3
Area of a circle = flr2
Vol. of a cylinder fl9b
Vol. of a cone = 1/3fJr2h
1. The rod-end fits against the dumbbell ball snugly; there is no “air-gap’. You may assume that there is no loss of volume of the ball when the rod is fitted against it.
2. The radius of the dumbbell and axle center rods cannot be larger than half the radius of the ball or wheel. Do not make calculations if the rod radius is more than half of the ball or wheel radius. Give the user an error message instead. For example, if the user enters a radius of 5 inches for the ball or wheel, the rod radius must be no larger than 2.5 inches.
3. The spear’s cone base has exactly the same radius as the connecting rod.
4. Output is to both the monitor and the printer.
This is so crazy, here is what I've got so far:
#include <cstring>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <string>
#include <ctime>
using namespace std;
int main()
{
string Dumbell = '1';
string Axel = '2';
string Spear = '3';
double radius, height, length, width, ball, rod, wheel, cone, vol;
double pie = 3.14159;
cout<<"Which shape are you working with"<<endl;
cin>>'1' || '2' || '3';
if (cin == 1)
{
cout<<"Please enter the radius (of ball), height, length of object & radius of rod"<<endl;
cin>>radius>>height>>length>>rod;
cout<<"Dumbell: "<<endl;
cout<<"Radius of the ball: "<<radius<<endl;
cout<<"Radius of the rod: "<<rod<<endl;
cout<<"Length of rod: "<<heigth<<endl;
vol = (4/3) * 3.142 * radius * radius * radius:
cout<<"The volume of the dumbbell is "<<vol<<" "<<"cubic inches"<<endl;
}
else if (cin == 2)
{
cout<<"Please enter the radius of the wheel, radius of the rod, length of the rod, width of the wheel"<<endl;
cin>>radius>>rod>>length>>width;
cout<<"Axle: "<<endl;
cout<<"Radius of the wheel: "<<radius<<endl;
cout<<"Radius of the rod: "<<rod<<endl;
cout<<"Length of the rod: "<<length<<endl;
cout<<"Width of the wheel: "<<width<<endl;
vol = ((pie * (radius *radius) * length) * 2)
cout<<"The volume of the axel is "<<vol<<" "<<"cubic inches"<<endl;
}
else if (cin==3)
{
cout<<"Please enter the radius (of rod), the length of the rod & heigth of the cone"<<endl;
cin>>radius>>length>>heigth;
cout<<"Spear: "<<endl;
cout<<"Radius of the rod: "<<radius<<endl;
cout<<"Length of the rod: "<<length<<endl;
cout<<"Height of the cone: "<<heigth<<endl;
vol = (1/3 * pie * (radius * radius) * height) * 2;
cout<<"The volume of the spear is "<<vol<<" "<<"cubic inches"<<endl;
return 0;
}
Thx for assistance in advance.