Rewrite your most recent high scores program so that each name/score pair is stored in a struct named Highscore. Except as noted below, this new program will continue to meet all of the requirements of your most recent high scores program. Your new program should meet the following additional requirements: The Highscore struct should have two fields: an int named score and a char array named name. The char array should have 24 elements, making the maximum length of the name 23. The data should be stored in a single array, a dynamically allocated array of Highscore structs. Your program should use three functions that accept the array of Highscore structs:void readData(Highscore scores[], int size) void sortData(Highscore scores[], int size) void displayData(const Highscore scores[], int size) You may use any sort algorithm, but I would recommend using the selection sort from lesson 9.6. Don't use C++'s sort() function, but you can use the swap() function. Note that when you swap your array elements, you can swap the entire struct. You don't need to swap the name and the score separately. You may assume that the user enters names that are 23 characters or less. Be sure to declare your struct above your prototypes, since the word "Highscore" appears in your prototypes.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Rewrite your most recent high scores program so that each name/score pair is stored in a struct named Highscore. Except as noted below, this new program will continue to meet all of the requirements of your most recent high scores program. Your new program should meet the following additional requirements:

  1. The Highscore struct should have two fields:
    • an int named score
    • and a char array named name. The char array should have 24 elements, making the maximum length of the name 23.
  2. The data should be stored in a single array, a dynamically allocated array of Highscore structs.
  3. Your program should use three functions that accept the array of Highscore structs:void readData(Highscore scores[], int size) void sortData(Highscore scores[], int size) void displayData(const Highscore scores[], int size)
  4. You may use any sort algorithm, but I would recommend using the selection sort from lesson 9.6. Don't use C++'s sort() function, but you can use the swap() function.
  5. Note that when you swap your array elements, you can swap the entire struct. You don't need to swap the name and the score separately.
  6. You may assume that the user enters names that are 23 characters or less.
  7. Be sure to declare your struct above your prototypes, since the word "Highscore" appears in your prototypes.

    Current Code:

    #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;

    }

     

    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];

        }

    }

     

    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;

                }

            }

        }

    }

    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 6 steps with 6 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education