Menu

[Solved]C Chapter 10 Defined Class Circletype Implement Basic Properties Circle Add Function Print Q37128403

C++

Chapter 10 defined the class circleType to implement the basicproperties of a circle. (Add the function print to this class tooutput the radius, area, and circumference of a circle.) Now everycylinder has a base and height, where the base is a circle. Designa class cylinderType that can capture the properties of a cylinderand perform the usual operations on the cylinder. Derive this classfrom the class circleType designed in chapter 10.   Someof the operations that can be performed on a cylinder are asfollows: Some of the operations that can be performed on a cylinderare as follows: calculate and print the volume, calculate and printthe surface area, set the height and set the radius of thebase.

You will use circleType header file and implementation file fromChapter 10 in Example 10-8 for this exercise.

You will create your own cylinderType header file andimplementation file (this will inherit from the circleTypeclass).

  • HINT: the calculation for the area of a cylinder: 2 * 3.1416 *getRadius() * (getRadius() + height)
  • HINT: the calculation for the volume of a cylinder: 3.1416 *getRadius() * getRadius() * height

In your MAIN function (where you test the calls to theimplementation files), create two cylinder objects (of typecylinder)

For one of the cylinder object, use the constructor toinitialize the radius and height. For the second cylinder objectuse methods setRadius and setHeight.

Here is the header file to go off of.

class circleType

{

public:

          void setRadius(double r);

           double getRadius();

           double area();

           double circumference();

           circleType(double r = 0);

private:

          doubleradius;

};

here is the implementation file to go off of.

void circleType::setRadius(double r)

{

          if (r>=0)

                 radius = r;

          else

                 radius = 0;

}

double circleType::getRadius()

{

             return radius;

}

double circleType::area()

{

              return 3.1416 * radius * radius;

}

double circleType::circumference()

{

           return 2 * 3.1416 * radius;

}

circleType::circleType(double r)

{

          setRadius(r);

}

Expert Answer


Answer to C++ Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to th… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *