Write a program that dynamically allocates an array large en
Write a program that dynamically allocates an array large enough to hold a user- defined number of test scores. Once all the scores are entered, the array should be passed to a func-tion that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and averages with appropriate headings. Use pointer notation rather than array notation whenever possible and make sure you delete the array after displaying the scores. Input Validation: Do not accept negative numbers for test scores.
I am kinda stuck. If someone could help me fix what I have that would be great.
Here is the code that I have so far:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int *testScores;
int size;
int scores;
double average;
//Get the number of test scores
cout << \"How many test scores do you have?\";
cin >> size;
double *testScores = new double[size];
//The array
testScores = new int[size];
cout << \"\ Enter\" << size
<< \"only positive values.\"
<< endl;
for (int index = 0; index < size; index++ )
{
cout << \"Enter the test scores\" << (index + 1) << \": \";
cin >> scores;
while (scores < 0)
{
cout << \"Positives Only:\" << (index + 1) << \":\";
cin >> testScores[index];
}
testScores[index] = scores;
}
cout << \"\ You entered:\";
printTestScores(testScores, size);
sortTestScores(testScores, size);
average = averageTestScores(testScores, size);
cout << \"Average of the test scores:\" << setprecision(2)
<< fixed << average << endl;
cout << endl;
return 0;
}
void setTestScores(double *testScores, int size)
{
double *testPtr = testScores;
for (int i = 0; i < size; i++, ++testScores)
{
cout << \"Test \" << (i + 1) << \": \";
cin >> *testScores;
}
}
double getAverageScore(double *testScores, int size)
{
double accumulator = 0.0;
for (double *testPtr = testScores; testPtr < testScores + size; ++testPtr)
{
accumulator += *testPtr;
}
return accumulator / size;
Solution
#include <iostream.h>
#include <iomanip.h>
int main() {
int *testScores;
int size;
int scores;
int average;
//Get the number of test scores
cout << \"How many test scores do you have?\";
cin >> size;
testScores=new int[size];
// double *testScores = new double[size];
//The array
testScores = new int[size];
cout << \"\ Enter\" << size
<< \"only positive values.\"
<< endl;
for (int index = 0; index < size; index++ )
{
cout << \"Enter the test scores\" << (index + 1) << \": \";
cin >> scores;
while (scores < 0)
{
cout << \"Positives Only:\" << (index + 1) << \":\";
cin >> testScores[index];
}
testScores[index] = scores;
}
cout << \"\ You entered:\";
printTestScores(testScores, size);
sortTestScores(testScores, size);
average = averageTestScores(testScores, size);
cout << \"Average of the test scores:\" << setprecision(2)
<< fixed << average << endl;
cout << endl;
return 0;
}
void setTestScores(int *testScores, int size)
{
int *testPtr = testScores;
for (int i = 0; i < size; i++, ++testScores)
{
cout << \"Test \" << (i + 1) << \": \";
cin >> *testScores;
}
}
int getAverageScore(int *testScores, int size)
{
int accumulator = 0.0;
for (int *testPtr = testScores; testPtr < testScores + size; ++testPtr)
{
accumulator += *testPtr;
}
return accumulator / size;
}
int prinTestScore(testScores,size)
{
for(int i=0;i<size;i++)
cin>>(*(TestScores+i));
}
int sortTestSores(testSocres,size)
{
for(int i=0;i<size;i++)
{
for(j=0;j<size-1;j++)
{
t=*testScors[j];
testScores[j]=testSocres[j+1];
TestScores[j+1]=t;
}
}
}
getch();
}


