Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In c++ Task: Write a program that defines a class Circle and implement it as req

ID: 3822515 • Letter: I

Question


In c++
Task:   
Write a program that defines a class Circle and implement it as required. The class Circle should consist of three private member variables: radius of type double, Pi of type double and color of type string. Circle should also include the following member functions:
print to output the area and diameter of the circle.
setPi to set Pi to the value of 3.14159.
setRadius to set the radius according to the parameters.
setColor to set the color according to the parameter.
getPi to return Pi.
getRadius to return the radius.
getColor to return the color.
area to return the area of the circle. area = pi* radius * radius.
getCircumference to return circumference of the circle. circumference = 2 * pi * radius
A default constructor to initialize radius 1 pi to 3.14.159 and color to “white”.
A constructor that initializes radius, Pi and color according to the parameters.

Using the class Circle to implement the basic properties of a circle. Every cylinder has a base and height, where the base is a circle. The class cylinderType will have the follow new attribute double height. Define a class cylinderType that can capture the properties of a cylinder and perform the usual operation on the cylinder. Derive this class from the class circleType (using circle) Some of the operations to be performed on a cylinder are
Calculate and print the volume
Calculate and print the surface area
Set the height
print to print the radius, height, surface area and volume.
setHeight to set the height according to the parameters.
getHeight to return the height.
CalcArea to calculate the area (2 * Pi * radius2 + height)
CalcVolume to calculate the volume ( Pi * radius2 * height)
A default constructor
An overload constructor that initializes according to the parameters.
equalVolume to compare two Cylinder objects’ volume. Return true if they are the same, otherwise, return false.
In the function main, you should write statements to test your class implementations.   


   

Explanation / Answer

#include <iostream>
using namespace std;

class circleType
{
    private:
    double radius;
    double pi;
    string color;
  
    public:
    void print()
    {
        cout<<" Area of circle = "<<area();
        cout<<" Diameter of circle = "<<2*radius;
    }
  
    //set methods
    void setPi()
    {
        pi = 3.14159;
    }
    void setRadius(double radius)
    {
        this->radius = radius;
    }
    void setColor(string color)
    {
        this->color = color;
    }
    //get methods
    double getPi()
    {
        return pi;
    }
    double getRadius()
    {
        return radius;
    }
    string getColor()
    {
        return color;
    }
    double area()
    {
       double area = pi* radius * radius;
       return area;
    }
    double getCircumference()
    {
        double circumference = 2 * pi * radius;
        return circumference;
    }
    circleType(double radius,double pi,string color)//argument constructor
    {
        this->radius = radius;
        this->pi = pi;
        this->color = color;
    }
    circleType()//default constructor
    {
        radius = 0;
        color = " ";
    }

  
  
};
class cylinderType : public circleType
{
    private:
    double height;
  
    public:
  
    void SetHeight(double height)
    {
        this->height = height;
    }
    void print()
    {
        cout<<" Radius of cylinder = "<<getRadius();
        cout<<" Height of cylinder = "<<getHeight();
        cout<<" SurfaceArea of cylinder = "<<CalcArea();
        cout<<" Volume = "<<CalcVolume();
    }  
    double getHeight()
    {
        return height;
    }
    double CalcArea()
    {
        double area = 2 * getPi() * getRadius()   + height;
        return area;
    }
    double CalcVolume()
    {
        double volume = getPi()*getRadius()*getRadius()* height;
        return volume;
    }
    cylinderType()
    {
        height = 0;
    }
    cylinderType(double height,double radius,double pi,string color):circleType(radius,pi,color)
    {
        this->height = height;
    }
  
      
    bool equalVolume(cylinderType cyl1,cylinderType cyl2)//function to check if two cylinders are equal
    {
        if(cyl1.CalcVolume() == cyl2.CalcVolume())
        return true;
        else
        return false;
    }
  
};
int main()
{
    circleType cir1(2.5,3.3,"Orange");
    cir1.print();
  
   cylinderType cyl1(4.5,3.5,3.14159,"Blue");
   cyl1.print();
   cylinderType cyl2(6.5,1.5,3.14159,"Yellow");
   cyl2.print();
  
   if(cyl1.equalVolume(cyl1,cyl2))
   cout<<" Both cylinders are equal";
   else
   cout<<" Both cylinders are not equal";
  
  
   return 0;
}


output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote