Question: The below program (Program 1) declares a simple Circle class, defines two circle objects, sets their radiuses using a member function, then calculates and displays

The below program (Program 1) declares a simple Circle class, defines two circle objects, sets their radiuses using a member function, then calculates and displays their areas. Execute the program to verify that it behaves as described.

Program 1

#include

#include

using namespace std;

class Circle

{

private:

double radius;

public:

void setRadius(double r)

{

radius = r; }

double calcArea()

{ return 3.14 * pow(radius, 2); }

};

int main()

{

Circle circle1, circle2;

circle1.setRadius(1);

circle2.setRadius(2.5);

cout << "The area of circle1 is " << circle1.calcArea () << endl;

cout << "The area of circle2 is " << circle2.calcArea () << endl;

return 0;

}

Part1- Update Program 1 in such a way that includes no inline functions

Part2 - Update Program 1 to apply the followings:

a. Remove the member function setRadius.

b. Add a constructor that takes the radius value as an argument.

c. Add a default constructor that initializes the radius member variable to 1.

d. Add the appropriate accessor (getter function) that returns the radius member variable.

e. Add a member function, calcPerimeter, that calculates and returns the perimeter of the circle.

f. Add a destructor that displays the following message: Circle is destroyed.

In the main program:

g. Define circle1 using the default constructor.

h. Define circle2 using the constructor with the argument 2.5.

i. Use the accessor (created in d) and the function calcPerimeter to display the radius and the perimeter for both circles. Examples of messages to be displayed:

The perimeter of the circle with radius 1 is 6.28

The perimeter of the circle with radius 2.5 is 15.7

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!