Question

C++ Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add t...

C++

Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in chapter 10.   Some of the operations that can be performed on a cylinder are as follows: Some of the operations that can be performed on a cylinder are as follows: calculate and print the volume, calculate and print the surface area, set the height and set the radius of the base.

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

You will create your own cylinderType header file and implementation file (this will inherit from the circleType class).

  • 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 the implementation files), create two cylinder objects (of type cylinder)

For one of the cylinder object, use the constructor to initialize the radius and height. For the second cylinder object use 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:

          double radius;

};

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);

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
const double PI = 3.1415926;
class Circle
{
private:
        double radius;
        double x;
        double y;
        double circumference;
        double cArea;
public:
Circle()
{
radius = 0;
x = 0;
y = 0;
circumference = 0;
cArea = 0;
}
        int setRadius()
{
cout << "Enter radius: ";
cin >> radius;
         if (radius < 1)
{
cout << "Please eneter a positive number: ";
cin >> radius;
}
         return radius;
}
        void setX()
{
cout << "Enter X cordinate: ";
cin >> x;
}
        void setY()
{
cout << "Enter y Coirdinate: ";
cin >> y;
}
        void setCircumference()
{
circumference = PI*(radius*radius);
cout << fixed << showpoint << setprecision(2);
cout << " Circumference is: " <<circumference << endl;
}
        void setCArea()
{
cArea = PI*(radius*radius);
cout << fixed << showpoint << setprecision(2);
cout << " Area is: " <<cArea << endl;
}
};
class Cylinder:public Circle
{
private:
        double height;
        double volume;
        double area;
        int rad;
public:
        Cylinder()
        {
                height = 0.0;
                volume = 0.0;
                area = 0.0;
                rad = 0.0;
        }


        void setheight()
        {
                cout << "What is the height: " << endl;
                cin >> height;
        }

        void setrad()
        {
                cout << "Please enter the radius" << endl;
                cin >> rad;
        }

        void setvolume()
        {
                volume = height * PI*(rad*rad);
                cout << fixed << showpoint << setprecision(2);
                cout << "Volume is : " << volume << endl;
        }

        void setarea()
        {
                area = 2*PI*(rad*rad) + 2*PI*(rad*height);
                cout << fixed << showpoint << setprecision(2);
                cout << "Surface area is : " << area << endl;
        }
};

int main()
{
        Circle shape1;
        Cylinder shape2;

        shape1.setX();
        shape1.setY();
        shape1.setCircumference();
        shape1.setCArea();
        cout << endl;
    std::cin.get();
    return 0;
}
Add a comment
Answer #2
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
const double PI = 3.1415926;
class Circle
{
private:
        double radius;
        double x;
        double y;
        double circumference;
        double cArea;
public:
Circle()
{
radius = 0;
x = 0;
y = 0;
circumference = 0;
cArea = 0;
}
        int setRadius()
{
cout << "Enter radius: ";
cin >> radius;
         if (radius < 1)
{
cout << "Please eneter a positive number: ";
cin >> radius;
}
         return radius;
}
        void setX()
{
cout << "Enter X cordinate: ";
cin >> x;
}
        void setY()
{
cout << "Enter y Coirdinate: ";
cin >> y;
}
        void setCircumference()
{
circumference = PI*(radius*radius);
cout << fixed << showpoint << setprecision(2);
cout << " Circumference is: " <<circumference << endl;
}
        void setCArea()
{
cArea = PI*(radius*radius);
cout << fixed << showpoint << setprecision(2);
cout << " Area is: " <<cArea << endl;
}
};
class Cylinder:public Circle
{
private:
        double height;
        double volume;
        double area;
        int rad;
public:
        Cylinder()
        {
                height = 0.0;
                volume = 0.0;
                area = 0.0;
                rad = 0.0;
        }


        void setheight()
        {
                cout << "What is the height: " << endl;
                cin >> height;
        }

        void setrad()
        {
                cout << "Please enter the radius" << endl;
                cin >> rad;
        }

        void setvolume()
        {
                volume = height * PI*(rad*rad);
                cout << fixed << showpoint << setprecision(2);
                cout << "Volume is : " << volume << endl;
        }

        void setarea()
        {
                area = 2*PI*(rad*rad) + 2*PI*(rad*height);
                cout << fixed << showpoint << setprecision(2);
                cout << "Surface area is : " << area << endl;
        }
};

int main()
{
        Circle shape1;
        Cylinder shape2;

        shape1.setX();
        shape1.setY();
        shape1.setCircumference();
        shape1.setCArea();
        cout << endl;
    std::cin.get();
    return 0;
}


Add a comment
Know the answer?
Add Answer to:
C++ Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ problem 11-3 Chapter 10 defined the class circleType to implement the basic properties of a...

    C++ problem 11-3 Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in Chapter 10. Some...

  • Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the...

    Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderTypethat can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleTypedesigned in Chapter 10. Some of the operations that can...

  • In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk,...

    In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk, juice, and water, in cylindrical containers. The shipping charges depend on the amount of the liquid in the container. (For simplicity, you may assume that the container is filled to the top.) They also provide the option to paint the outside of the container for a reasonable amount. Write a program that does the following: Prompts the user to input the dimensions (in feet)...

  • Write a java class definition for a circle object. The object should be capable of setting...

    Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and 40.5, respectively. Print their areas and circumference. Here is the Java class file (Circle.java). Compile it. public class Circle{ //Instance Variables private double PI = 3.1459; private double radius; //Methods public Circle ( ) { }    //get method (Accessor Methods ) public double getRadius (...

  • Create a class named Circle with fields named radius, diameter, and area. Include a constructor that...

    Create a class named Circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and calculates the other two values. Also include methods named setRadius() and getRadius(). The setRadius() method not only sets the radius, but it also calculates the other two values. (The diameter of a circle is twice the radius, and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant...

  • Design and implement class Circle to represent a circle object. The class defines the following attributes...

    Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1.      A private variable of type double named radius to represent the radius. Set to 1. 2.      Constructor Methods: •        Python : An overloaded constructor method to create a default circle. •        C# & Java: Default Constructor with no arguments. •        C# & Java: Constructor method that creates a circle with user-specified radius. 3.      Method getRadius() that returns the radius. 4.     ...

  • Please add //comments to the header file below. #ifndef CIRCLE_H_INCLUDED #define CIRCLE_H_INCLUDED #include <iostream> using namespace...

    Please add //comments to the header file below. #ifndef CIRCLE_H_INCLUDED #define CIRCLE_H_INCLUDED #include <iostream> using namespace std; class Circle { private: double radius; // declaration of public methods in header file public: Circle() { // default value radius = 1; } void input() { cout << "Enter radius: "; cin >> radius; } void print() { double PI = 3.14159; double area = PI * radius * radius; double circumference = 2 * PI * radius; cout << "Circle with...

  • Exercise 1: A circle is defined by its radius (we are not interested in its center)....

    Exercise 1: A circle is defined by its radius (we are not interested in its center). A cylinder is defined by circle and height.  Design and implement a class called Circle that has the necessary attributes to describe it and at least the following member methods: setRadius( ), getRadius( ), Circumference( ), Area( ), Display( ), and two constructors, one is parameterized constructor and another empty constructor with default zero value.  Design and implement a class called Cylinder...

  • I need to implement a program that requests a x,y point and the radius of a...

    I need to implement a program that requests a x,y point and the radius of a circle. then it figures out the area and circumference using an overloaded operation. The full instructions, what I have and the errors I have are below. A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, pointType, that can store and process a point in the x-y plane. You should then perform operations on the point, such as...

  • Write a Java console application that prompts the user to enter the radius of a circle,...

    Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. Write a JavaFX GUI application to do the same calculation, and draw the circle. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Write and document your program per class coding conventions. Add an instance variable double radius. Generate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT