Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that records and displays league standings for a baseball league. The program will ask the user to enter five team names, and

Write a program that records and displays league standings for a baseball league. The program will ask the user to enter five team names, and five win amounts. It will store the data in memory, and print it back out sorted by wins from highest to lowest.

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.

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 new. It must deallocate the memory when it is done with the array using delete [].

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)

Note that the name field of each WinRecord struct is just a char* which you need to use to store a C-String. 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! but I have provided the getLine() function getLine.cpp 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. Note that this is in addition to de-allocating the array of WinRecord structs discussed in step 2 above!

The sample output from your program should look approximately like this (user input in orange):

Enter team #1: Padres

Enter the wins for team #1: 75

Enter team #2: Dodgers

Enter the wins for team #2: 91

Enter team #3: Giants

Enter the wins for team #3: 92

Enter team #4: Rockies

Enter the wins for team #4: 65

Enter team #5: Diamondbacks

Enter the wins for team #5: 70

League Standings:

Giants: 92

Dodgers: 91

Padres: 75

Diamondbacks: 70

Rockies: 65

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions