(C++) A local scientific lab stores hazardous chemicals for local manufacturing
ID: 3604424 • Letter: #
Question
(C++) A local scientific lab stores hazardous chemicals for local manufacturing companies until they can be properly disposed of. The lab would like for you to write a C++ program to calculate the storage charges based on the volume of the shape required for the particular material being stored.
a)The user will enter the name of the company requesting the storage, the desired shape for the chemical being stored via a menu option, and the dimensions of the shape.
Build an appropriate menu for the user that displays the three choices of shapes available with an option to also quit the program. Prompt the user for the desired menu choice. If the menu choice is invalid, display an error message.
Read the dimensions of the desired shape from the user.
b)Calculate the volume of the desired shape, the handling charge, and the storage charge based on the volume. Also calculate the total charges.
c)Display the name of the company requesting the service, the name of the chosen storage shape, the dimension of the shape, the calculated volume to a tenth of a decimal point, the handling charge, the storage charge, and the total charges based on the following criteria table. (Use symbolic constants where appropriate. Use 3.1416 to represent the value of PI.)
The formulas for the volumes are:
Volume of a cylinder = pi * r2 * h
Volume of a sphere = 4/3 * pi * r3
Volume of a cone = 1/3 * pi * r2 * h
The Storage and Handling charges are based on the following criteria:
Volume (x cubic inches)
Handling Charge
Storage Charge based on Volume
0 < x <= 150
$2.35
$0.15 per cubic inch
150 < x <= 250
$5.75
$0.25 for each cubic inch > 150
250 < x <= 350
$10.50
$0.35 for each cubic inch > 250
x > 350
$15.25
$0.45 for each cubic inch > 350
Sample Input #1:
Enter the company name: Ward Bus Company
Please enter your choice of shape from the following menu:
1. Cylinder
2. Sphere
3. Cone
4. Quit
Enter Menu Choice:? 3
Enter the radius of the cone: ? 5.3
Enter the height of the cone: ? 9.4
Sample Output:
Storage Bill for Ward Bus Company
Dimensions of the cone:
Radius: 5.3 inches
Height: 9.4 inches
Volume: 276.5 cubic inches
Handling Charge………………..$10.50
Storage Charge………………… $9.28
Total Charges…………………... $19.78
Sample Input #2:
Enter the company name: X-Ray Chemicals
Please enter your choice of shape from the following menu:
1. Cylinder
2. Sphere
3. Cone
4. Quit
Enter Menu Choice:? 2
Enter the radius of the sphere: ? 7.5
Sample Output:
Storage Bill for X-Ray Chemicals
Dimensions of the sphere:
Radius: 7.5 inches
Volume: 1767.1 cubic inches
Handling Charge………………..$15.25
Storage Charge………………… $637.72
Total Charges…………………... $652.97
Sample Input 3#:
Enter the company name: None
Please enter your choice of shape from the following menu:
1. Cylinder
2. Sphere
3. Cone
4. Quit
Enter Menu Choice:? 4
Sample Output:
Thanks for using this program!!!
Sample Input #4:
Enter the company name: Arkansas Industries
Please enter your choice of shape from the following menu:
1. Cylinder
2. Sphere
3. Cone
4. Quit
Enter Menu Choice:? 5
Sample Output:
Invalid menu choice – Run program again.
Volume (x cubic inches)
Handling Charge
Storage Charge based on Volume
0 < x <= 150
$2.35
$0.15 per cubic inch
150 < x <= 250
$5.75
$0.25 for each cubic inch > 150
250 < x <= 350
$10.50
$0.35 for each cubic inch > 250
x > 350
$15.25
$0.45 for each cubic inch > 350
Explanation / Answer
Hi,
Below is the C++ code for the question-
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
string comp;
int ch;
double r,h;
double cyllin_vol,sphere_vol,cone_vol;
cout << "Enter the company name" << endl;
cin>>comp;
cout<<"Enter the choice of menu";
cout<<" 1. Cylinder";
cout<<" 2. Sphere";
cout<<" 3. Cone";
cout<<" 4. Quit";
cout<<" Enter the choice of menu";
cin>>ch;
switch(ch)
{
case 1: cout<<" Enter the radius of the cyllinder: ?";
cin>>r;
cout<<" Enter the height of the cyllinder";
cin>>h;
cyllin_vol=(3.14*pow(r,2)*h);
cout<<" Storage Bill for "<<comp;
cout<<" Dimensions of the Cyllinder:";
cout<<" Radius: "<<r<<"inches";
cout<<" Height: "<<h<<"inches";
cout<<" Volume: "<<cyllin_vol<<"cubic inches";
if((cyllin_vol>0)||(cyllin_vol<=150))
{
cout<<" Handling Charge………………..$2.35";
cout<<" Storage Charge………………… $"<<cyllin_vol*0.15;
cout<<" Total Charges…………………... $"<<2.35+cyllin_vol*0.15;
}
else if((cyllin_vol>150)||(cyllin_vol<=250))
{
cout<<" Handling Charge………………..$.5.75";
cout<<" Storage Charge………………… $"<<(cyllin_vol-150)*0.25;
cout<<" Total Charges…………………... $"<<5.75+((cyllin_vol-150)*0.25);
}
else if((cyllin_vol>250)||(cyllin_vol<=350))
{
cout<<" Handling Charge………………..$10.50";
cout<<" Storage Charge………………… $"<<(cyllin_vol-250)*0.35;
cout<<" Total Charges…………………... $"<<10.50+((cyllin_vol-250)*0.35);
}
else if(cyllin_vol>350)
{
cout<<" Handling Charge………………..$15.25";
cout<<" Storage Charge………………… $"<<(cyllin_vol-350)*0.45;
cout<<" Total Charges…………………... $"<<15.25+((cyllin_vol-250)*0.45);
}
break;
case 2: cout<<" Enter the radius of the sphere: ?";
cin>>r;
sphere_vol=((4/3)*3.14*pow(r,3));
cout<<" Storage Bill for "<<comp;
cout<<" Dimensions of the Sphere:";
cout<<" Radius: "<<r<<"inches";
cout<<" Volume: "<<sphere_vol<<"cubic inches";
if((sphere_vol>0)||(sphere_vol<=150))
{
cout<<" Handling Charge………………..$2.35";
cout<<" Storage Charge………………… $"<<sphere_vol*0.15;
cout<<" Total Charges…………………... $"<<2.35+sphere_vol*0.15;
}
else if((sphere_vol>150)||(sphere_vol<=250))
{
cout<<"Handling Charge………………..$.5.75";
cout<<"Storage Charge………………… $"<<(sphere_vol-150)*0.25;
cout<<"Total Charges…………………... $"<<5.75+((sphere_vol-150)*0.25);
}
else if((sphere_vol>250)||(sphere_vol<=350))
{
cout<<"Handling Charge………………..$10.50";
cout<<"Storage Charge………………… $"<<(sphere_vol-250)*0.35;
cout<<"Total Charges…………………... $"<<10.50+((sphere_vol-250)*0.35);
}
else if(sphere_vol>350)
{
cout<<"Handling Charge………………..$15.25";
cout<<"Storage Charge………………… $"<<(sphere_vol-350)*0.45;
cout<<"Total Charges…………………... $"<<15.25+((sphere_vol-250)*0.45);
}
break;
case 3: cout<<" Enter the radius of the Cone: ?";
cin>>r;
cout<<" Enter the height of the Cone";
cin>>h;
cone_vol=((0.333)*3.14*pow(r,2)*h);
cout<<" Storage Bill for "<<comp;
cout<<" Dimensions of the Cone:";
cout<<" Radius: "<<r<<"inches";
cout<<" Height: "<<h<<"inches";
cout<<" Volume: "<<cone_vol<<"cubic inches";
if((cone_vol>0)||(cone_vol<=150))
{
cout<<" Handling Charge………………..$2.35";
cout<<" Storage Charge………………… $"<<cone_vol*0.15;
cout<<" Total Charges…………………... $"<<2.35+cone_vol*0.15;
}
else if((cone_vol>150)||(cone_vol<=250))
{
cout<<"Handling Charge………………..$.5.75";
cout<<"Storage Charge………………… $"<<(cone_vol-150)*0.25;
cout<<"Total Charges…………………... $"<<5.75+((cone_vol-150)*0.25);
}
else if((cone_vol>250)||(cone_vol<=350))
{
cout<<"Handling Charge………………..$10.50";
cout<<"Storage Charge………………… $"<<(cone_vol-250)*0.35;
cout<<"Total Charges…………………... $"<<10.50+((cone_vol-250)*0.35);
}
else if(cone_vol>350)
{
cout<<"Handling Charge………………..$15.25";
cout<<"Storage Charge………………… $"<<(cone_vol-350)*0.45;
cout<<"Total Charges…………………... $"<<15.25+((cone_vol-250)*0.45);
}
break;
default: cout<<"Invalid menu choice – Run program again.";
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.