he data must be stored in two dynamic arrays: an array of strings named names, and an array of ints named scores. These arrays must be declared and allocated using "new" in the main function. The user input of the names and scores should be done in a function named readData(). It should have the following signature: void readData(string names[], int scores[], int size) You must also write two more functions: one to sort both arrays in descending order by score, and one to display the final list of names and scores. They should have the following signatures. void sortData(string names[], int scores[], int size) void displayData(const string names[], const int scores[], int size) The main function should be very short. It should just get the number of scores, allocate the two arrays, invoke these three functions, and then deallocate the arrays. Some of you may not have studied sorting algorithms. Sorting is covered in lesson 9, section 9.6. You can copy as much code from that lesson as you like. You may use C++'s built-in swap() function, but do not use C++'s sort() function. #include #include using namespace std; // function declarations void initializeArrays(string names[], int scores[], int size); void sortData(string names[], int scores[], int size); void displayData(const string names[], const int scores[], int size); int main() {     int size;     cout << "How many scores will you enter?:";     cin >> size;     string* names = new string[size];     int* scores = new int[size];     initializeArrays(names, scores, size);     sortData(names, scores, size);     displayData(names, scores, size);     cin.get();     system("PAUSE");     return 0; } /* This function will get the user inputs* and populate those values into an array*/ void initializeArrays(string names[], int scores[], int size) {     for (int i = 0; i < size; i++)     {         cout << "Enter the name for score #" << i + 1 << ":";         cin >> names[i];         cout << "Enter the score for score #" << i + 1 << ":";         cin >> scores[i];     } } /* This function will sort the array based on scores*/ void sortData(string names[], int scores[], int size) {     string temp;     int tempScore;     for (int i = 0; i < size; i++)     {         for (int j = i + 1; j < size; j++)         {             if (scores[i] < scores[j])             {                 temp = names[i];                 names[i] = names[j];                 names[j] = temp;                 tempScore = scores[i];                 scores[i] = scores[j];                 scores[j] = tempScore;             }         }     } } // This function will display the output void displayData(const string names[], const int scores[], int size) {     cout << "Top Scores :" << endl;     for (int i = 0; i < size; i++)     {         cout << names[i] << ": " << scores[i] << endl;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

he data must be stored in two dynamic arrays: an array of strings named names, and an array of ints named scores. These arrays must be declared and allocated using "new" in the main function.

The user input of the names and scores should be done in a function named readData(). It should have the following signature:

void readData(string names[], int scores[], int size)

You must also write two more functions: one to sort both arrays in descending order by score, and one to display the final list of names and scores. They should have the following signatures.

void sortData(string names[], int scores[], int size) void displayData(const string names[], const int scores[], int size)

The main function should be very short. It should just get the number of scores, allocate the two arrays, invoke these three functions, and then deallocate the arrays.

Some of you may not have studied sorting algorithms. Sorting is covered in lesson 9, section 9.6. You can copy as much code from that lesson as you like. You may use C++'s built-in swap() function, but do not use C++'s sort() function.

#include <iostream>
#include<string>
using namespace std;
// function declarations
void initializeArrays(string names[], int scores[], int size);
void sortData(string names[], int scores[], int size);
void displayData(const string names[], const int scores[], int size);
int main()
{
    int size;
    cout << "How many scores will you enter?:";
    cin >> size;
    string* names = new string[size];
    int* scores = new int[size];
    initializeArrays(names, scores, size);
    sortData(names, scores, size);
    displayData(names, scores, size);
    cin.get();
    system("PAUSE");
    return 0;
}
/* This function will get the user inputs* and populate those values into an array*/
void initializeArrays(string names[], int scores[], int size)
{
    for (int i = 0; i < size; i++)
    {
        cout << "Enter the name for score #" << i + 1 << ":";
        cin >> names[i];
        cout << "Enter the score for score #" << i + 1 << ":";
        cin >> scores[i];
    }
}
/* This function will sort the array based on scores*/
void sortData(string names[], int scores[], int size)
{
    string temp;
    int tempScore;
    for (int i = 0; i < size; i++)
    {
        for (int j = i + 1; j < size; j++)
        {
            if (scores[i] < scores[j])
            {
                temp = names[i];
                names[i] = names[j];
                names[j] = temp;
                tempScore = scores[i];
                scores[i] = scores[j];
                scores[j] = tempScore;
            }
        }
    }
}
// This function will display the output
void displayData(const string names[], const int scores[], int size)
{
    cout << "Top Scores :" << endl;
    for (int i = 0; i < size; i++)
    {
        cout << names[i] << ": " << scores[i] << endl;
 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY