Question
Write a short C++ program that gets the side of a cube and the radius of a sphere from the keyboard and writes to a
Write a short C++ program that gets the side of a cube and the radius of a sphere from the keyboard and writes to a file the surfaces of these shapes.
To accomplish this task, your program will have to take the following steps:
- Declare a named constant PI that holds value 3.141592.
- Declare variables named side, radius, s_cube, and s_sphere that hold real numbers.
- Prompt the user to Enter side of cube: .
- Prompt the user to Enter radius of sphere: .
- Calculate the surface of the cube using the formula 6 * s 2 (where s is the side of the cube) and assign the rounded result to s_cube.
- Calculate the surface of the sphere using the formula 4 * pi* r 2 (where r is the radius of the sphere) and assign the rounded result to s_sphere.
- Format the output to display the numbers in fixed format with two decimal digits.
- Output the message
The surface of a cube of sides ,side, is , s_cube.
The surface of a sphere of radius ,radius, is ,s_sphere.
- Cube_surf and sphere_surf rounds off the value to the nearest one hundredths (second decimal digit) before returning it.
- Instead of calculating the surfaces in main( ) you use a couple of value_returning functions named cube_surf( ) and sphere_surf( ) to do it. The former must receive the side of the cube while the latter must receive the radius of the sphere
- To calculate the squares of a number you must define a value-returning function named square( ) that receives a real number and returns its square as a real number. Then use it to calculate the squares of side and radius. Do NOT use pow() in your program.
------------------------------------------------------------------------------------------------------------------------
Example:
Enter side of cube: 2.123456789 (entered by the user at the keyboard)
Enter radius of sphere: 3.987654321 (entered by the user at the keyboard)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started