Make a class named cylinder with a field for the radius and


Make a class named Cylinder with a field for the radius and a field for the height. Be sure to include the following:

  • a default constructor that sets the radius to 3 and height to 8
  • a setter function to set the value of the radius
  • a setter function to set the value of the height
  • a getter function to return the value of the radius
  • a getter function to return the value of the height
  • a function to compute and return the cylinder's surface area

Be aware that the surface area of a cylinder is 2 * pi * radius * radius + 2 * pi * radius * height. Feel free to use the value of 3.14 for pi.

Next, provide an appropriate main function (driver code) to test this class. Create an object with a radius of 10. make a second Cylinder object that uses the radius set by the default constructor. Once the objects have been created, add code to change the values of the first Cylinder object and display the surface area of both cylinders in an attractive fashion.

Sample Session:

Please enter the radius: 5

Please enter the height: 8

The cylinder with a radius of 3 and height of 8 has a surface area of:  207.24

The cylinder with a radius of 5 and height of 8 has a surface area of:  408.20

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Make a class named cylinder with a field for the radius and
Reference No:- TGS02754972

Now Priced at $10 (50% Discount)

Recommended (90%)

Rated (4.3/5)