Problem

Ascending Circles Program 8-28 from Chapter 8 creates an array of four Circle ob...

Ascending Circles

Program 8-28 from Chapter 8 creates an array of four Circle objects, then displays the area of each object. Using a copy of that program as a starting point, modify it to create an array of eight Circle objects initialized with the following radii: 2.5, 4.0, 1.0, 3.0, 6.0, 5.5, 3.5, 2.0. Then use a bubble sort to arrange the objects in ascending order of radius size before displaying the area of each object.

Program 8-28:

1 // This program uses an array of objects.

2 // The objects are instances of the Circle class.

3 #include

4 #include

5 #include "Circle.h" // Circle class declaration file

6 using namespace std;

7

8 const int NUM_CIRCLES = 4;

9

10 int main()

11 {

12 Circle circle[NUM_CIRCLES]; // Define an array of Circle objects

13

14 // Use a loop to initialize the radius of each object

15 for (int index = 0; index < NUM_CIRCLES; index++)

16 { double r;

17 cout << "Enter the radius for circle " << (index+1) << ": ";

18 cin >> r;

19 circle[index].setRadius(r);

20 }

21

22 // Use a loop to get and print out the area of each object

23 cout << fixed << showpoint << setprecision(2);

24 cout << "\nHere are the areas of the " << NUM_CIRCLES

25 << " circles.\n";

26 for (int index = 0; index < NUM_CIRCLES; index++)

27 { cout << "circle " << (index+1) << setw(8)

28 << circle[index].findArea() << endl;

29 }

30 return 0;

31 }

Program Output with Example Input Shown in Bold

Enter the radius for circle 1: 0[Enter]

Enter the radius for circle 2: 2[Enter]

Enter the radius for circle 3: 2.5[Enter]

Enter the radius for circle 4: 10[Enter]

Here are the areas of the 4 circles.

circle 1 0.00

circle 2 12.56

circle 3 19.63

circle 4 314.00

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT