Please help me with these last few steps of this c++ program!! Here\'s what im s
ID: 3547278 • Letter: P
Question
Please help me with these last few steps of this c++ program!! Here's what im stuck on....
Excercise 2: There can be several constructors as long as they differ in number of parameters or data type. Alter the program so that the user can enter either just the radius, the radius and the center, or nothing at the time the object is defined. Whatever the user does NOT include (radius or center) must be initialized somewhere. There is no setRadius function and there will no longer be a setCenter function. You can continue to assume that the default radius is 1 and the default center is (0, 0). Alter the client portion (main) of the program by defining an object sphere1, giving just the radius of 2 and the default center, and sphere2 by giving neither the radius nor the center (it uses all the default values). Be sure to print out the vital statistics for these new objects (area and circumference).
In addition to the output in Exercise 1, the following output should be included:
The radius of the circle is 2
The center of the circle is (0, 0) The area of the circle is 12.56
The circumference of the circle is 12.56
The radius of the circle is 1
The center of the circle is (0, 0) The area of the circle is 3.14
The circumference of the circle is 6.28
Exercise 3: Alter the program you generated in Exercise 2 so that the user will be allowed to enter either nothing, just the radius, just the center, or both the center and radius at the time the object is defined. Add to the client portion of the code an object called sphere3 that, when defined, will have the center at (15, 16) and the default radius. Be sure to print out this new object
Explanation / Answer
#include <iostream>
using namespace std;
//_________________________________________________________________________
// This program declares a class for a circle that will have
// member functions that set the center, find the area, find
// the circumference and display these attributes.
// The program as written does not allow the user to input data, but
// rather has the radii and center coordinates of the circles (spheres in the program)
// initialized at declaration or set by a function.
//class declaration section (header file)
class Circles
{
public:
void setCenter(int x, int y);
double findArea();
double findCircumference();
void printCircleStats(); // This outputs the radius and centre of the circle.
Circles (float r); // Constructor with radius.
Circles (float r,int x,int y); // Constructor with radius and centre
Circles (int x,int y); // Constructor with centre
Circles(); // Default constructor
~Circles(); // Default destructor.
private:
float radius;
int center_x;
int center_y;
};
const double PI = 3.14;
//Client section
int main()
{
Circles sphere1(2);
sphere1.printCircleStats();
cout << "The area of the circle is " << sphere1.findArea() << endl;
cout << "The circumference of the circle is " << sphere1.findCircumference() << endl;
Circles sphere2;
sphere2.printCircleStats();
cout << "The area of the circle is " << sphere2.findArea() << endl;
cout << "The circumference of the circle is " << sphere2.findCircumference() << endl;
Circles sphere3(15,16);
sphere3.printCircleStats();
cout << "The area of the circle is " << sphere3.findArea() << endl;
cout << "The circumference of the circle is " << sphere3.findCircumference() << endl;
return 0;
}
//___________________________________________________________________________
//Implementation section Member function implementation
Circles::Circles()
{
radius = 1;
center_x = 0;
center_y = 0;
}
// Fill in the code to implement the non-default constructor
Circles::Circles(float r)
{
center_x = 0;
center_y = 0;
radius = r;
}
// Fill in the code to implement the non-default constructor 2
Circles::Circles(float r,int x,int y)
{
center_x = x;
center_y = y;
radius = r;
}
// Fill in the code to implement the non-default constructor 2
Circles::Circles(int x,int y)
{
center_x = x;
center_y = y;
radius = 1;
}
// Fill in the code to implement the findArea member function
double Circles::findArea()
{
return 3.14*radius*radius;
}
// Fill in the code to implement the findCircumference member function
double Circles::findCircumference()
{
return 2*3.14*radius;
}
void Circles::printCircleStats()
// This procedure prints out the radius and center coordinates of the circle
// object that calls it.
{
cout << "The radius of the circle is " << radius << endl;
cout << "The center of the circle is (" << center_x
<< "," << center_y << ")" << endl;
}
void Circles::setCenter(int x, int y)
// This procedure will take the coordinates of the center of the circle from
// the user and place them in the appropriate member data.
{
center_x = x;
center_y = y;
}
Circles::~Circles()
{
cout <<"This concludes the Circles class for each object that is destroyed" << endl;
}