1. Declare three structs to store Athlete, Event and Registration details. The struct
definitions are provided in Appendix 1.
2. Write the driver code (main) and declare an array object of type Registration,
assuming you can have a maximum of 20 registrations. Also, declare a pointer for
this array object that you can use to access the array elements in your program.
3. In the driver, write code to display a menu for the user with the following options.
Each menu item may be selected by the user using the corresponding menu
number. The menu should repeat after each selection until user enters 7 for exit.
1
2
3
4
5
– Read and display registration file
– List all athletes by event
– List all athletes by country
– Read and display result file
– List medal counts by country
CS112 Assignment 1, 2012
1

6
7
– Display medal tally
– Exit
Implement each of the above menu options (1-6) in separate functions that you can call from your driver program. Below are the descriptions for each function, with the function prototypes given in Appendix 1 as a guide.
1 - The registration.txt file contains the registration ID, athlete and event details for each participating athlete. The function takes the registration array pointer (declared in step 2) as an input parameter, together with an integer size (passed as reference and used to count the number of records read in the array). The function should first ask the user to enter the complete path and filename for the input file (example C:\\registration.txt), which is read and stored in the registration array using the pointer. The function should then display the contents of the input file as read in the registration array.
2 - The function takes the registration array pointer, size and an event ID (which is entered by the user within the driver) as inputs and displays the athlete ID, name and country of all athletes registered for that event.
3 - The function takes the registration array pointer, size and a country name (which is entered by the user within the driver) as inputs and displays the athlete ID, name and event name for all athletes representing that country.
4 - The results.txt file contains the event ID and top three athlete IDs (representing gold, silver and bronze winners for that event). Assume there are no ties, no multiple medal winners and the input file can contain a maximum of 20 records (results) at a time. In your driver, declare a 2-D integer array (size 20x4) that can store the contents of the input file. The function should then take this 2-D array and an integer size (passed as reference and used to count the number of records read in the array) as inputs. It should first ask user to enter the complete path and filename for the input file (example C:\\result.txt), which is read and stored in the 2-D array appropriately. The function should then display the contents of the input file as read in the array.
5 - The function takes the registration array pointer, size, 2-D array, size and a country name (which is entered by the user within the driver) as inputs and displays the country name and the total number of gold, silver and bronze medals won by that country.
6 - The function takes the registration array pointer, size, 2-D array and size as inputs and lists all countries who have won a medal and display the total count of gold, silver and bronze medals for each country in some appropriate format (it is not necessary to rank or sort the countries in any particular order).



Appendix 1
Struct Definitions
struct Athlete struct Event struct Registration
{ { {
int aID; int eID; int rID;
string aName; string eName; Athlete rAthlete;
int aAge; string eRecord; Event rEvent;
char aGender; }; };
string aCountry;
};
Function Prototypes
1. void ReadRegistrations (Registration *regPtr, int &size);
2. void ListAthletesByEvent (Registration *regPtr, int size, int eID);
3. void ListAthletesByCountry (Registration *regPtr, int size, string country);
4. void ReadResults (int results[ ][4], int &size);
5. void ListMedalsByCountry (Registration *regPtr, int size1, results[ ][4], int size2, string country);
6. void ListMedalTally (Registration *regPtr, int size1, results[ ][4], int size2);
Appendix 2 – Input Files (available on Moodle)
registration.txt
result.txt
result.txt
Appendix 3 – Sample Output
RID AID AName AAge AGender ACountry EID EName ERecord
101 201 tony 28 m fiji 301 200m 20s
102 202 anna 30 f samoa 305 shotput 25m
103 201 tony 28 m fiji 302 400m 54s
104 203 pita 21 m vanuatu 301 200m 20s
105 203 pita 21 m vanuatu 304 discus 80m
106 204 sam 22 m tonga 301 200m 20s
107 205 lisa 28 f kiribati 305 shotput 25m
108 206 mere 32 f fiji 305 shotput 25m
109 207 kenny 29 f samoa 308 1500m 5m
110 208 raj 40 m fiji 310 200m 20s
EID AID1 AID2 AID3







Appendix 3 – Sample Output
Welcome to Athlete Registration and Result Program
Menu:
1 – Read and display registration file
2 – List all athletes by event
3 – List all athletes by country
4 – Read and display result file
5 – List medal counts by country
6 – Display medal tally
7 – Exit
Enter menu option: 1
Enter registration filename: C:\\registration.txt
RID AID AName AAge AGender ACountry EID EName ERecord
101 201 tony 28 m fiji 301 200m 20s
102 202 anna 30 f samoa 305 shotput 25m
103 201 tony 28 m fiji 302 400m 54s
104 203 pita 21 m vanuatu 301 200m 20s
105 203 pita 21 m vanuatu 304 discus 80m
106 204 sam 22 m tonga 301 200m 20s
107 205 lisa 28 f kiribati 305 shotput 25m
108 206 mere 32 f fiji 305 shotput 25m
109 207 kenny 29 f samoa 308 1500m 5m
110 208 raj 40 m fiji 310 200m 20s
Menu:
1 – Read and display registration file
2 – List all athletes by event
3 – List all athletes by country
4 – Read and display result file
5 – List medal counts by country
6 – Display medal tally
7 – Exit
Enter menu option: 2
Enter event ID: 305
AID Name Country
202 anna samoa
205 lisa kiribati
206 mere fiji
Menu:
1 – Read and display registration file
2 – List all athletes by event
3 – List all athletes by country
4 – Read and display result file
5 – List medal counts by country
6 – Display medal tally
7 – Exit


Menu:
1 – Read and display registration file
2 – List all athletes by event
3 – List all athletes by country
4 – Read and display result file
5 – List medal counts by country
6 – Display medal tally
7 – Exit
Enter menu option: 7
Press any key to continue…