I am working on a sorting program that sorts batting averages and names, and prints them to the screen. I am trying to get the sortData function to work in the main function
#include <iostream>
#include <string>
using namespace std;
class Average
{
private:
string name[12];
double avg[12];
public:
void getData();
void sortData(string[], double[], int);
void displayData();
};
void Average::getData()
{
string play_name;
double average;
for (int i = 0; i < 12; i++)
{
cout << "Enter name: ";
cin >> play_name;
cout << endl;
cout << "Enter average: ";
cin >> average;
cout << endl;
name[i] = play_name;
avg[i] = average;
}
}
void Average::sortData(string name[], double avg[],int size)
{
int temp;
bool madeAswap = false;
do
{
madeAswap = false;
for (int count = 0; count < size-1; count++)
{
if (avg[count] > avg[count + 1])
{
temp = avg[count];
avg[count] = avg[count + 1];
avg[count + 1] = temp;
madeAswap = true;
}
}
} while (madeAswap);
// int temp;
// bool madeAswap = false;
do
{
madeAswap = false;
for (int count = 0; count < size-1; count++)
{
if (name[count] > name[count + 1])
{
string temp = name[count];
name[count] = name[count + 1];
name[count + 1] = temp;
madeAswap = true;
}
}
} while (madeAswap);
}
void Average::displayData()
{
for (int i = 0; i < 12; i++)
{
cout << name[i] << " " << avg[i] << endl;
}
}
int main()
{
Average avg;
avg.getData();
// avg.sortData();
avg.displayData();
return 0;
}