Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that dynamically allocates an array large enough to hold a numbe

ID: 3555216 • Letter: W

Question

Write a program that dynamically allocates an array large enough to hold a number of test score. The size of the array should be input by the user. Once all the scores are entered, the array should be passed to a function that calculates the average score and returns the average. The main function should display the average. (Do not accept negative numbers for test scores.)

I found this from another question but it's throwing errors. It's saying "int count Error: expression must have object-to-pointer type." and it's also saying "Error: identifier "average" is undefined." and those two errors are only coming from the function "void arrAvgScore" at the bottom of the program. I'm willing to add time and points as long as the program runs fine. Also, I took the two errors and made them bold and underlined so they stick out better.

Here's what I've got now:

#include <iostream>

#include <iomanip>

using namespace std;

void arrSelectSort(double *, int);

void arrAvgScore(double *, int);

int main()

{

double *TestScores, //To dynamically allocate an array

total = 0.0; //Accumulator

double average = 0; //To hold average test scores

int numTest, //To hold number of test scores

count; //Counter variable

//Get the number of test scores you wish to average and put in order

cout << "How many test scores do you wish ";

cout << "to enter? ";

cin >> numTest;

//Dynamically allocate an array large enough to hold that many scores

TestScores = new double[numTest];

//Get the test scores

cout << "Enter the test scores below. ";

for (count = 0; count < numTest; count++)

{

cout << "Test Score " << (count + 1) << ": ";

cin >> TestScores[count];

}

// Input validation. Only numbers between 0-100

while (numTest<0)

{

cout << "You must enter a scores that non-negative" << endl;

cout << "Please enter again: ";

cin >> TestScores[count];

}

//Calculate the total test scores

for (count = 0; count < numTest; count++)

{

total += TestScores[count];

}

average = total / numTest;

//Dsiplay the results

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

cout << "The average of all the test score is " << average << endl;

//Free dynamically allocated memory

delete[] TestScores;

TestScores = 0; //make TestScores point to null

?

?

?

?

//Display the Test Scores in ascending order

cout << "The test scores, sorted in ascending order, are: ";

system("pause");

return 0;

}

//This function performs an ascending order selection sort

void arrSelectSort(double *arr, int size)

{

int startScan;

double minIndex;

double minElem;

?

for (startScan = 0; startScan < (size - 1); startScan++)

{

minIndex = startScan;

minElem = arr[startScan];

?

for (int index = startScan + 1; index < size; index++)

{

if (arr[index] < minElem)

{

minElem = arr[index];

minIndex = index;

}

}

void arrAvgScore(double *arr[], int size);

{

double total = 0;

int numTest;

for (int count = 0; count < numTest; count++)

{

total += numTest[count];

average = total / numTest;

}

}

}

Explanation / Answer


#include <iostream>

#include <iomanip>

using namespace std;

void arrSelectSort(double *, int);

void arrAvgScore(double *, int);

int main()

{

double *TestScores, //To dynamically allocate an array

total = 0.0; //Accumulator

double average = 0; //To hold average test scores

int numTest, //To hold number of test scores

count; //Counter variable

//Get the number of test scores you wish to average and put in order

cout << "How many test scores do you wish ";

cout << "to enter? ";

cin >> numTest;

//Dynamically allocate an array large enough to hold that many scores

TestScores = new double[numTest];

//Get the test scores

cout << "Enter the test scores below. ";

for (count = 0; count < numTest; )

{

cout << "Test Score " << (count + 1) << ": ";

int temp;
cin>>temp;
if(temp<0) {
cout<<"Negative Numbers aren't allowed ";
cout<<"Please Enter Again ";
}
else {
TestScores[count]=temp;
   count++;
}


}

// Input validation. Only numbers between 0-100

//Calculate the total test scores

for (count = 0; count < numTest; count++)

{

total += TestScores[count];

}

average = total / numTest;

//Dsiplay the results

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

cout << "The average of all the test score is " << average << endl;

//Display the Test Scores in ascending order

cout << "The test scores, sorted in ascending order, are: ";
for (count = 0; count < numTest; count++)

{

cout<<TestScores[count]<<" ";

}

//Free dynamically allocated memory

delete[] TestScores;

TestScores = 0; //make TestScores point to null

system("pause");

return 0;

}

//This function performs an ascending order selection sort

void arrSelectSort(double *arr, int size)

{

int startScan;

double minIndex;

double minElem;

for (startScan = 0; startScan < (size - 1); startScan++)

{

minIndex = startScan;

minElem = arr[startScan];

for (int index = startScan + 1; index < size; index++)

{

if (arr[index] < minElem)

{

minElem = arr[index];

minIndex = index;

}

}

void arrAvgScore(double *arr[], int size);

{

double total = 0;

int numTest=0,average=0;

for (int count = 0; count < numTest; count++)

{

total += arr[count];

average = total / numTest;

}


}

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote