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

a default constructor that sets the radius to 3
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 method 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.

After creating this class, write a second class, TestCylinder, that creates an object with a radius of 10. It should also create a second Cylinder object that uses the radius set by the default constructor. Once the objects have been created, write code to display the surface area of both cylinders in an attractive fashion.

Submit both the Cylinder file and the TestCylinder.

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 PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#ifndef CYLINDER_H
#define CYLINDER_H
const double pi = 3.14;

class Cylinder {
    Cylinder(int = 3); // default constructor
    void setRadius(double radius);
    void setHeight(double height);
    double getRadius()const;
    double getHeight()const;
    double SurfaceArea();
    friend class TestCylinder; // make TestCylinder a friend
    double radius;
    double height ;
}; // end class

#endif /* CYLINDER_H */...
$25.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats