Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. Declare a named constant PI that holds value 3.141592.
  2. Declare variables named side, radius, s_cube, and s_sphere that hold real numbers.
  3. Prompt the user to Enter side of cube: .
  4. Prompt the user to Enter radius of sphere: .
  5. 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.
  6. 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.
  7. Format the output to display the numbers in fixed format with two decimal digits.
  8. 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.

  1. Cube_surf and sphere_surf rounds off the value to the nearest one hundredths (second decimal digit) before returning it.
  2. 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

  1. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions

Question

4. Describe cultural differences that influence perception

Answered: 1 week ago