Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

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 objects vital statistics (area and circumference).

Code:

#include

using namespace std;

class Circles

{

private:

float radius;

int center_x;

int center_y;

public:

double findArea();

double findCircumference();

void printCircleStats();

Circles(float r);

Circles(float r, int centerX, int centerY);

Circles();

};

const double PI = 3.14;

Circles::Circles()

{

center_x = 0;

center_y = 0;

radius = 1;

}

Circles::Circles(float r)

{

radius = r;

center_x = 0;

center_y = 0;

}

Circles::Circles(float r, int centerX, int centerY)

{

radius = r;

center_x = centerX;

center_y = centerY;

}

double Circles::findArea()

{

return 3.14*radius*radius;

}

double Circles::findCircumference()

{

return 2 * 3.14*radius;

}

void Circles::printCircleStats()

{

cout << "The radius of the circle is " << radius << endl;

cout << "The center of the circle is (" << center_x << "," << center_y << ")" << endl;

}

int main() {

Circles sphere1(2), sphere2;

cout << " Sphere 1 : " << endl;

sphere1.printCircleStats();

cout << "The area of the circle is " << sphere1.findArea() << endl;

cout << "The circumference of the circle is " << sphere1.findCircumference() << endl;

cout << " Sphere 2 : " << endl;

sphere2.printCircleStats();

cout << "The area of the circle is " << sphere2.findArea() << endl;

cout << "The circumference of the circle is " << sphere2.findCircumference() << endl;

system("pause");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

3. You can gain power by making others feel important.

Answered: 1 week ago