Question: Write a C++ program to allow the user to enter name-score pairs, sort the scores in ascending order and calculate the average score. This program

Write a C++ program to allow the user to enter name-score pairs, sort the scores in ascending order and calculate the average score. This program dynamically allocates an array large enough to hold a user-defined number of test scores and also dynamically allocates an array to hold the student names. For each student taking a test, the user types the students name followed by the students integer test score. Once all the scores are entered, the array holding test scores and the array holding student names should be passed to a function that sorts the scores in ascending order. When the sorted list of scores is displayed, each students name should be displayed along with his or her score. Another function should be called that calculates the average score

How many test scores will you enter? 5

Enter student 1s last name: Klien

Enter that students test score: 100

Enter student 2s last name: Lee

Enter that students test score: 90

Enter student 3s last name: Goss

Enter that students test score: 98

Enter student 4s last name: Green

Enter that students test score: 95

Enter student 5s last name: Clinton

Enter that students test score: 96

The test scores in ascending order, and their average, are:

Name Score

Lee 90

Green 95

Clinton 96

Goss 98

Klien 100

Average score: 95.80

__________________________

I have this so far:

#include using namespace std;

int main() { //will store the number of scores int numberofScores; //double for storing the total, to later use in the findAvg function double totalScores; //asks the user how many scores the user will enter, //and stores them in 'numberofScores' cout << "How many test scores will you enter?" ; cin >> numberofScores; //declares a new array based on the number of scores //the user said will enter. arrScore = new double [numberofScores]; stringArray = new string [numberofScores]; // for loops for the amount of scores the user said will enter, // and asks for the last name and the test score of the student for (int i = 0; i < numberofScores; i++) { cout <<" Enter student << i <<'s last name:" ; cin >> stringArray[i] cout <<" Enter that student's test score" ; cin >> arrScore[i] while (arrScore < 0) { cout <<"Error, please enter a non-negitive score"; cout <<"Please try again, this time no negitive scores: "; cin >> arrScore[i] while (arrScore > 100) { cout <<"Error, please enter a non-negitive score"; cout <<"Please try again, this time no negitive scores: "; cin >> arrScore[i]

//calculates the total score for (int i = 0, i < numberofScores; i++) { totalScores += arrayScore[i] } void calcAverage (double totalScores, int numberofScores) { //declare a double to store the average double averageScore; //calculates the average average = totalScores / numberofScores; //prints the average score cout <<"Average Score: " << average << endl;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!