I just need to fix one thing but I am unsure what I need to do I know where to issue lies but am unsure how to fix it I know I must change the data type in the Circle class but I am unsure what data type needs to be changed or added.
#pragma once
// This header file contains the Circle class declaration.
#ifndef CIRCLE_H
#define CIRCLE_H
#include <cmath>
class Circle
{
private:
double radius; // Circle radius
int centerX, centerY; // Center coordinates
double findArea()
{
return 3.14 * pow(radius, 2);
}
}; // End Circle class declaration
#endif
// This program uses an array of objects.
// The objects are instances of the Circle class.
#include <iostream>
#include <cmath>
#include <iomanip>
#include "Circle.h" // Circle class declaration file
using namespace std;
const int NUM_CIRCLES = 4;
void bubbleSort(Circle[], int);
int main()
{
Circle circle[NUM_CIRCLES]; // Define an array of Circle objects
// Use a loop to initialize the radius of each object
for (int index = 0; index < NUM_CIRCLES; index++)
{
double r;
cout << "Enter the radius for circle " << (index + 1) << ": ";
cin >> r;
circle[index].setRadius(r);
}
bubbleSort(circle, NUM_CIRCLES);
// Use a loop to get and print out the area of each object
cout << fixed << showpoint << setprecision(2);
cout << "\nHere are the areas of the " << NUM_CIRCLES
<< " circles.\n";
for (int index = 0; index < NUM_CIRCLES; index++)
{
cout << "circle " << (index + 1) << setw(8)
<< circle[index].findArea() << endl;
}
return 0;
}
void bubbleSort(Circle circle[], int size)
{
int temp;
for (int i = 0; i < size - 1; i++)
{
for (int j = 0; j < size - i - 1; j++)
{
if (circle[j] > circle[j + 1])
{
swap(circle[j], circle[j + 1]);
}
}
}
}
#include <iostream>
#include <iomanip>
#include <utility>
class Circle {
private:
double radius {1.0};
int centerX {}, centerY {};
public:
Circle() {}
Circle(double r) : radius(r) {}
Circle(double r, int x, int y) : radius(r), centerX(x), centerY(y) {}
void setRadius(double r) { radius = r; }
int getXcoord() const { return centerX; }
int getYcoord() const {return centerY; }
double findArea() const { return 3.14 * radius * radius; }
};
constexprunsigned NUM_CIRCLES {4};
void bubbleSort(Circle[], unsigned);
int main() {
Circle circle[NUM_CIRCLES];
for (unsigned index {}; index < NUM_CIRCLES; ++index) {
double r {};
std::cout << "Enter the radius for circle " << (index + 1) << ": ";
std::cin >> r;
circle[index].setRadius(r);
}
bubbleSort(circle, NUM_CIRCLES);
std::cout << std::fixed << std::showpoint << std::setprecision(2);
std::cout << "\nHere are the areas of the " << NUM_CIRCLES << " circles:\n";
for (unsigned index {}; index < NUM_CIRCLES; ++index)
std::cout << "circle " << (index + 1) << std::setw(8) << circle[index].findArea() << '\n';
}
void bubbleSort(Circle circle[], unsigned size) {
for (unsigned i {}; i < size - 1; ++i)
for (unsigned j {}; j < size - i - 1; j++)
if (circle[j].findArea() > circle[j + 1].findArea())
std::swap(circle[j], circle[j + 1]);
}
This does the comparison using the circle area. As circle area is used several times it would be better to compute this once within the constructors and stored as part of the class.