Ask Question
3 August, 22:52

Write a program that records high-score data for a fictitious game. the program will ask the user to enter five names, and five scores. it will store the data in memory, and print it back out sorted by score. the output from your program should look approximately like this: enter the name for score #1: suzy enter the score for score #1: 600 enter the name for score #2: kim enter the score for score #2: 9900 enter the name for score #3: bob enter the score for score #3: 1012 enter the name for score #4: armando enter the score for score #4: 8000 enter the name for score #5: tim enter the score for score #5: 514

+4
Answers (1)
  1. 4 August, 01:21
    0
    Scores. cpp

    #include

    #include

    using namespace std;

    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 ()

    {

    string names[5];

    int scores[5];

    //reading names and scores

    initializeArrays (names, scores, 5);

    //sorting the lists based on score.

    sortData (names, scores, 5);

    //displaying the contents of both arrays

    displayData (names, scores, 5);

    return 0;

    }

    void initializeArrays (string names[], int scores[], int size) {

    for (int i=0; i
    cout<<"Enter the name for score #"<< (i+1) <<": ";

    cin >> names[i];

    cout<<"Enter the score for score #"<< (i+1) <<": ";

    cin >> scores[i];

    }

    }

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

    int temp = 0;

    string tempStr = "";

    for (int i=0; i < size; i++) {

    for (int j=1; j < (size-i); j++) {

    //checking max score and sorting based on it.

    if (scores[j-1]< scores[j]) {

    //swap the elements!

    //swapping scores

    temp = scores[j-1];

    scores[j-1] = scores[j];

    scores[j]=temp;

    //swapping names

    tempStr = names[j-1];

    names[j-1] = names[j];

    names[j]=tempStr;

    }

    }

    }

    }

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

    cout<<"Top Scorers:"<
    //printing the elements up to the size of both arrays.

    for (int i=0; i
    cout<
    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program that records high-score data for a fictitious game. the program will ask the user to enter five names, and five scores. it ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers