Rewrite your league application from Assignment 5 (I completed this assignment, I will paste my work below) so that each team/wins pair is stored in a struct named WinRecord.  Your program must meet the following requirements: 1.  The WinRecord struct must have two fields: an int named wins, and a char* named name.  name will point to a dynamically allocated array of characters, see requirement 4 below. 2.  Instead of using two parallel arrays like Assignment 6, the data must be stored in a single array -- a dynamically allocated array of WinRecord structs.  You must ask the user how many teams are in the league to determine how big this array needs to be and then dynamically allocate memory for it using the new operator.  It must deallocate the memory when it is done with the array using delete []. 3.  Your program must use three functions that accept the array of WinRecord structs by address (i.e., pass a WinRecord pointer): void initializeData(WinRecord* standings, int size) void sortData(WinRecord* standings, int size) void displayData(WinRecord* standings, int size) 4.  Note that the name field of each WinRecord struct is just a char* which you need to use to store a C-String.  For this assignment, you must use C-strings, not C++ string objects.  Unlike a C++ string object, the memory to store the actual character array for the C-String is not allocated for you automatically!  I encourage you to develop a function to do this on your own, but I have provided the getLine() function  (Links to an external site.)getLine.cpp (Links to an external site.) to use if you wish.  Note that this function returns a line of text from the keyboard contained in a dynamically allocated array.  You will thus need to deallocate this memory using delete [] when you are done using any arrays you allocated using this function.  Towards the end of main() is a reasonable place to do this allocation.  Note that this is in addition to deallocating the array of WinRecord structs discussed in step 2 above! ***THIS IS MY CODE FOR ASSIGNMENT 5 ***   #include using namespace std; /* function prototypes */ void initializeArrays(string names[], int wins[], int size); void sortData(string names[], int wins[], int size); void displayData(string names[], int wins[], int size); /* main function */ int main() {     // declaring constance variable     const int TEAMSIZE = 5;     string teamNames[TEAMSIZE] = {};     int teamWins[TEAMSIZE] = {};     initializeArrays(teamNames, teamWins, TEAMSIZE);     sortData(teamNames, teamWins, TEAMSIZE);     cout << endl;     displayData(teamNames, teamWins, TEAMSIZE);     return 0; } /* function headers */ void initializeArrays(string names[], int wins[], int size) {     for (int i = 0; i < size; i++)     {         cout << "Enter team #" << i + 1 << ": ";         cin >> names[i];         cout << "Enter the win for team #" << i + 1 << ": ";         cin >> wins[i];     } } void sortData(string names[], int wins[], int size) {     int swapWins;     string swapNames;     bool swap;     do {         swap = false;         for (int i = 0; i < size - 1; i++)         {             if (wins[i] < wins[i + 1])             {                 swapWins = wins[i];                 wins[i] = wins[i + 1];                 wins[i + 1] = swapWins;                 swapNames = names[i];                 names[i] = names[i + 1];                 names[i + 1] = swapNames;                 swap = true;             }         }     } while (swap); } void displayData(string names[], int wins[], int size) {     cout << "League Standings:" << endl;     for (int i = 0; i < size; i++)     {         cout << names[i] << ": " << wins[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

***USING C++***

Rewrite your league application from Assignment 5 (I completed this assignment, I will paste my work below) so that each team/wins pair is stored in a struct named WinRecord.  Your program must meet the following requirements:

1.  The WinRecord struct must have two fields: an int named wins, and a char* named name.  name will point to a dynamically allocated array of characters, see requirement 4 below.

2.  Instead of using two parallel arrays like Assignment 6, the data must be stored in a single array -- a dynamically allocated array of WinRecord structs.  You must ask the user how many teams are in the league to determine how big this array needs to be and then dynamically allocate memory for it using the new operator.  It must deallocate the memory when it is done with the array using delete [].

3.  Your program must use three functions that accept the array of WinRecord structs by address (i.e., pass a WinRecord pointer):

void initializeData(WinRecord* standings, int size)
void sortData(WinRecord* standings, int size)
void displayData(WinRecord* standings, int size)

4.  Note that the name field of each WinRecord struct is just a char* which you need to use to store a C-String.  For this assignment, you must use C-strings, not C++ string objects.  Unlike a C++ string object, the memory to store the actual character array for the C-String is not allocated for you automatically!  I encourage you to develop a function to do this on your own, but I have provided the getLine() function  (Links to an external site.)getLine.cpp (Links to an external site.) to use if you wish.  Note that this function returns a line of text from the keyboard contained in a dynamically allocated array.  You will thus need to deallocate this memory using delete [] when you are done using any arrays you allocated using this function.  Towards the end of main() is a reasonable place to do this allocation.  Note that this is in addition to deallocating the array of WinRecord structs discussed in step 2 above!

***THIS IS MY CODE FOR ASSIGNMENT 5 ***

 

#include <iostream>
using namespace std;

/* function prototypes */

void initializeArrays(string names[], int wins[], int size);
void sortData(string names[], int wins[], int size);
void displayData(string names[], int wins[], int size);


/* main function */

int main()
{
    // declaring constance variable
    const int TEAMSIZE = 5;
    string teamNames[TEAMSIZE] = {};
    int teamWins[TEAMSIZE] = {};

    initializeArrays(teamNames, teamWins, TEAMSIZE);
    sortData(teamNames, teamWins, TEAMSIZE);
    cout << endl;
    displayData(teamNames, teamWins, TEAMSIZE);

    return 0;
}


/* function headers */

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

    for (int i = 0; i < size; i++)
    {
        cout << "Enter team #" << i + 1 << ": ";
        cin >> names[i];
        cout << "Enter the win for team #" << i + 1 << ": ";
        cin >> wins[i];
    }

}

void sortData(string names[], int wins[], int size)
{
    int swapWins;
    string swapNames;
    bool swap;

    do {
        swap = false;

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

            if (wins[i] < wins[i + 1])
            {
                swapWins = wins[i];
                wins[i] = wins[i + 1];
                wins[i + 1] = swapWins;

                swapNames = names[i];
                names[i] = names[i + 1];
                names[i + 1] = swapNames;

                swap = true;
            }

        }
    } while (swap);
}

void displayData(string names[], int wins[], int size)
{
    cout << "League Standings:" << endl;
    for (int i = 0; i < size; i++)
    {
        cout << names[i] << ": " << wins[i] << endl;

    }
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
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