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

Urgently need help for this question! Write a circle class that has the followin

ID: 3624758 • Letter: U

Question

Urgently need help for this question!

Write a circle class that has the following member variables:
radius: a double
pi: a double initialized with the value 3.14159

The class should have the following member function:
Default Constructor. A default constructor that sets radius to 0.0.
Constructor. Accepts the radius of the circle as an argument.
setRadius. A mutator function for the radius variable.
getRadius. An accessor function for the radius variable.
getArea. Returns the area of the circle, which is calculated as area = pi * radius * radius
getDiameter. Returns the diameter of the circle, which calculated as diameter = radius * 2
getCircumference. Returns the circumference of the circle, which is calculated as circumference = 2 * pi * radius

Write a program that demonstrates the Circle class by asking the user for the circle's radius, creating a Circle object, and then reporting the circle's area, diameter, and circumference.

Explanation / Answer

please rate - thanks

#include <iostream>
using namespace std;
class circle
{private:
   double radius;    
   const static double pi=3.14159;
public:
   circle()
      {radius=0.0;
        }
   circle(double r)
      {setRadius(r);
      }
   void setRadius(double r)
      {radius=r;
      }
   double getRadius()
      {return radius;
      }
   double getArea()
      {return pi*radius*radius;
      }
   double getDiameter()
      {return radius*2;
      }
   double getCircumference()
      { return 2.*pi*radius;
       }
};

int main()
{double r;
cout<<"Enter radius: ";
cin>>r;
circle mycircle(r);  
cout<<"A circle with radius "<<mycircle.getRadius()<<" has an"<<endl;
cout<<"area of: "<<mycircle.getArea()<<endl;
cout<<"diameter of: "<<mycircle.getDiameter()<<endl;
cout<<"circumference of: " << mycircle.getCircumference()<<endl;
system("pause");
return 0;
}

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