Question: Write a C++ program to compute the side area and volume of a cylinder and the area and volume of a sphere, depending on the

Write a C++ program to compute the side area and volume of a cylinder and the area and volume of a sphere, depending on the choice that the user makes. Your program should ask users to enter 1 to choose cylinder or 2 for sphere, and display an invalid choice error for other values.

For a cylinder, we want to compute: Side area: (2r)h, Volume: (r2 )h, where r is the radius of the cylinder and h is the height of the cylinder.

For a sphere, we want to compute: Surface area: 4r2 , Volume: (4.0/3.0)r3 , where r is the radius of the sphere. It is required to use overloading functions to write the program for the above problem.

Sample Input/Output: Test Case 1: Enter 1 for cylinder and 2 for sphere: 2 Enter the radius of a sphere: 5 The surface area of the sphere is 314.159 The volume of the sphere is 523.598

Test Case 2: Enter 1 for cylinder and 2 for sphere: 1 Enter the radius and the height of a cylinder: 4 5 The side area of the cylinder is 125.664 The volume of the cylinder is 251.327

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!