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

I asked this question once before and the person who answered this did not follo

ID: 3768305 • Letter: I

Question

I asked this question once before and the person who answered this did not follow the directions below. Could someone please help me to solve this question and break it down into Circle.h and Circle.cpp

This is a C++ Question. I am totally lost, any help would be appreciated, thanks in advance.

Circle Class. Write a class name Circle, with the class declaration in a file called Circle.h and the implementation in a file called Circle.cpp. The class will have two data members, a double that holds the radius of the circle and a double called pi which will be set to the value, 3.14159 (data member cannot be set in the class declaration, pi should not be set via a parameter but set in the constructor). The class must provide the following member functions

Default Constructor – that sets the radius to 0.0

Constructor – that 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 – calculates and returns (as double) the area of the circle using the formula
area = pi * radius * radius

getDiameter – calculates and returns (as double) the diameter of the circle using the formula
diameter = radius * 2

getCircumference – calculates and returns (as double) the circumference of the circle using the formula
circumference = 2 * pi * radius

Write a program that demonstrates the Circle class by asking the user for the circle’s radius and creating a Circle object and then reporting the circle’s area, diameter and circumference. Two objects need to be created each using one of the two constructors (showing that both work along with the mutators and accessors).

Explanation / Answer

#include<iostream>

using namespace std;

class Circle

{

private:

double pi = 3.14159,radius;

public:

Circle()

{

radius = 0.0;

}

  

Circle(double r)

{

radius = r;

}

  

void setRadius(double r)

{

radius = r;

}

  

double getRadius()

{

return this->radius;

}

  

double getArea()

{

return this->pi*this->radius*this->radius;

}

  

double getDiameter()

{

return 2*this->radius;

}

  

double getCircumference()

{

return 2*this->pi*this->radius;

}

};

int main()

{

double radius;

cout << "Enter the radius : ";

cin >> radius;

Circle c1(radius);

  

cout << "Area of circle is : " << c1.getArea() << endl;

cout << "Diameter of circle is : " << c1.getDiameter() << endl;

cout << "Circumfrence of circle is : " << c1.getCircumference() << endl;

  

Circle c2;

  

cout << "Area of circle with default value of radius is : " << c1.getArea() << endl;

cout << "Diameter of circle with default value of radius is : " << c1.getDiameter() << endl;

cout << "Circumfrence of circle with default value of radius is : " << c1.getCircumference() << endl;

  

}

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