Test Scores #2 Modify the program of Programming Challenge 2 to allow the user to enter name-score pairs using two parralell arrays. For each student taking a test, the user types the student’s name followed by the student’s integer test score. Modify the sorting function so it takes an array holding the student names and an array holding the student test scores. When the sorted list of scores is displayed, each student’s name should be displayed along with his or her score. In stepping through the arrays, use pointers rather than array subscripts.
here is the code i have so far. please help.
#include <iostream>
#include <iomanip>
using namespace std;
void arraySelectSort(double *, int);
void showArrayPtr(double *, int);
void showAverage(double, int);
int main()
{
double *scores,
total = 0.0,
average = 0.0;
int numScores;
cout << "Please enter the number of test scores you would like to use";
cin >> numScores;
scores = new double[numScores];
if (scores == NULL)
return 0;
cout << "Enter the test scores below.\n";
for (int count = 0; count < numScores; count++)
{
cout << "Test score #" << (count + 1) << ": ";
cin >> scores[count];
while (scores[count] <= 0)
{
cout << "Zero or negative numbers not accepted.\n";
cout << "Test Score #" << (count + 1) << ": ";
cin >> scores[count];
}
}
for (int count = 0; count < numScores; count++)
{
total += scores[count];
}
arraySelectSort(scores, numScores);
cout << "The test scores in ascending order are: \n";
showArrayPtr(scores, numScores);
showAverage(total, numScores);
delete[] scores;
return 0;
}
void totalaverage(double *, int)
{
}
void arraySelectSort(double *array, int size)
{
int startScan, minIndex;
double minElem;
for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minElem = array[startScan];
for (int index = startScan + 1; index < size; index++)
{
if (array[index] < minElem)
{
minElem = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = minElem;
}
}
void showArrayPtr(double *array, int size)
{
for (int count = 0; count< size; count++)
cout << array[count] << " ";
cout << endl;
}
void showAverage(double total, int numScores)
{
double average;
average = total / numScores;
cout << fixed << showpoint << setprecision(2);
cout << "Average Score: " << average << endl;
system("pause");
}