I need this C++ Program, it\'s not a java program JAVA PROJECT 4.DOCX Project IV
ID: 3710791 • Letter: I
Question
I need this C++ Program, it's not a java program
JAVA PROJECT 4.DOCX
Project IV [After Chapter 6]
Add a date last modified note to include the date you made changes:
Add lines the menu as follows
“ Enter 5 to find the volume and area of a box.”
“Enter 6 to find the volume and area of a sphere.”
Change the validation check to allow 5 and 6 to be valid.
Define double variables length, width, height for use in the calculations for a box.
Define double boxVolume and boxArea for use in the calculations for a box.
Define double variables radius, sphereVolume, and sphereArea for use in the calculations for a sphere.
Enter code to test for choice = 5 and execute code similar to choices 1 and 2 for C to F and cm to inches that does this:
Ask for a length for a box
Ask for a height for a box
Ask for a width for a box
boxVolume = box ( 1, length, width, height); 1à calculate volume of box using the length, width, height of the box.
Call the same function box with these parameters boxArea = box(2, length, width, height),
The 2 à that the total area of the box is to be calculated.
Display to the user a message similar to this “A box “ + length + ”by “ + width
“by ” height + “ has a volume of“ + boxVolume);
Display to the user a message similar to this “”A box “ +length + “by “ + width + “by “ +height + “ has an area of “ + boxArea);
Enter code to test for choice = 6 and execute code similar to choices 1, 2 and 3 for C to F and cm to inches and radians to degrees that does this:
Ask for the radius of the sphere.
sphereVolume = sphere (1, radius); 1 à indicates that a volume is to be calculated.
sphereArea = sphere (2, radius); 2 àindicates that area is to be calculated.
Display to the user a message similar to this “ A sphere of radius = “ + radius
+ “ has a volume = “ + sphereVolume);
Display to the user a message similar to this “A sphere of radius = “ + radius
+ “ has an area = “ + sphereArea );
Create the function double box (int what, double len, double wid, double ht)
Define double result;
If what == 1)
If (what == 2)
Return result
End function.
Create a function double sphere ( int what, double radius)
Define double result;
If what == 1)
result = 4.0/3.0 * 3.14159 * Math.pow(radius,3) ; // calculate the volume of the sphere.
If (what ==2)
result = 4* 3.14159 *Math.pow( radius,2);// Calculate the area of the sphere
Return result
End function.
Explanation / Answer
#include <iostream>
#include <cmath>
using namespace std;
double sphere( int what,double radius)
{
double result;
if (what == 1)
result = 4.0/3.0 * 3.14159 * pow(radius,3) ; // calculate the volume of the sphere.
else if (what ==2)
result = 4* 3.14159 *pow( radius,2);// Calculate the area of the sphere
return result;
}
double box (int what, double len, double wid, double ht)
{
double result;
if (what == 1) result = len*wid*ht;
if (what == 2) result = 2*(len*wid+wid*ht+ht*len);
return result;
}
int main() {
double length, width, height;
double boxVolume, boxArea ;
double radius, sphereVolume, sphereArea;
cout<<"Enter length of box : ";
cin>>length;
cout<<" Enter height of box : ";
cin>>height;
cout<<" Enter width of a box : ";
cin>>width;
boxVolume = box(1, length, width, height);
boxArea = box(2, length, width, height),
cout<<" A box " << length << " by " << width <<" by "<< height << " has a volume of " << boxVolume;
cout<<" A box " <<length << " by " << width << " by " <<height << " has an area of " << boxArea;
cout<<" Enter radius of the sphere";
cin>>radius;
sphereVolume = sphere (1, radius);
sphereArea = sphere (2, radius);
cout<<" A sphere of radius = " << radius << " has a volume = " << sphereVolume;
cout<<" A sphere of radius = " << radius<< " has an area = " << sphereArea ;
return 0;
}
Output:
Enter length of box :3.5
Enter height of box :6.7
Enter width of a box :7.2
A box 3.5 by 7.2 by 6.7 has a volume of 168.84
A box 3.5 by 7.2 by 6.7 has an area of 193.78
Enter radius of the sphere 5.5
A sphere of radius = 5.5 has a volume = 696.909
A sphere of radius = 5.5 has an area = 380.132
Do ask if any doubt. Please upvote.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.