Please help me with this in C++: Add another two functions to DISPLAY 4.12 to ca
ID: 3760396 • Letter: P
Question
Please help me with this in C++:
Add another two functions to DISPLAY 4.12 to calculate:
The volume of the smallest cube around the sphere
The area of the smallest cube around the sphere
The volume of the biggest cube that can fit inside the sphere
//DISPLAY 4.12 A Global Named Constant
//Computes the area of a circle and the volume of a sphere.
//Uses the same radius for both calculations.
#include <iostream>
#include <cmath>
using namespace std;
const double PI = 3.14159;
double area(double radius);
//Returns the area of a circle with the specified radius.
double volume(double radius);
//Returns the volume of a sphere with the specified radius.
int main( )
{
double radius_of_both, area_of_circle, volume_of_sphere;
cout << "Enter a radius to use for both a circle "
<< "and a sphere (in inches): ";
cin >> radius_of_both;
area_of_circle = area(radius_of_both);
volume_of_sphere = volume(radius_of_both);
cout << "Radius = " << radius_of_both << " inches "
<< "Area of circle = " << area_of_circle
<< " square inches "
<< "Volume of sphere = " << volume_of_sphere
<< " cubic inches ";
return 0;
}
double area(double radius)
{
return (PI * pow(radius, 2));
}
double volume(double radius)
{
return ((4.0/3.0) * PI * pow(radius, 3));
}
Explanation / Answer
so we will use these 2 values in our program:
int main( )
{
double radius_of_both, area_of_circle, volume_of_sphere;
cout << "Enter a radius to use for both a circle "
<< "and a sphere (in inches): ";
cin >> radius_of_both;
area_of_circle = area(radius_of_both);
volume_of_sphere = volume(radius_of_both);
volume _of _smallest _cube=volume_Smallest_cube(radius_both;
volume_of_largest_cube=volume_largest_cube(radius_both);
cout << "Radius = " << radius_of_both << " inches "
<< "Area of circle = " << area_of_circle
<< " square inches "
<< "Volume of sphere = " << volume_of_sphere
<< " cubic inches ";
cout<< volume_of_smallest_cube;
cout<<volume of largest cube;
return 0;
}
double area(double radius)
{
return (PI * pow(radius, 2));
}
double volume(double radius)
{
return ((4.0/3.0) * PI * pow(radius, 3));
}
double volume_smallest_cube( double radius)
{ return( 8 * pow(radius,3));
}
double volume_largest_cube(double radius)
{ return ( 4.19 * pow (radius,3));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.