PROBLEM STATEMENT:

In the last week, the head of the Australian Olympic Committee has expressed unease about the rate of progress being made for the Olympics Games in Rio De Janiero in 2016. As we all know, the most important part of the Olympics is the Medal Tally Table for the countries competing at the games. Our task is to supply a program, written in C, which will run as a backup in case the on-line systems fail. It will use simple text files for input so that it will not rely on any on-line information. For simplicity, each country will be known by its 3-character country code. The Medal Tally Table is a simple concept – each competing country is listed with its Gold, Silver, and Bronze Medals, and also its Total Medal count. However, it is also necessary to list those countries which have won medals in order of their levels of success.

The program is required by October 15, 2013 and must be thoroughly tested in pilot form by then. It will then be used at a Friendly Meet later in 2013, at which there will be just 25 countries (unlike the 200+ that will likely compete at the Olympics). You should make the change from 25 to over 200 an easy one to make.

The countries to complete at the Friendly are: AUS, BRA, BUL, CHN, COL, ETH, FRA, GBR, GER, HUN, ITA, JAM, KEN, MEX, NOR, POL, POR, RUS, SAF, SPA, TAN, USA, UZB, ZAM, ZIM. Argentina (ARG) has been specifically excluded to give Australia (AUS) a chance to be at the top of at least one medal tally table – the alphabetical one (sorry Pablo).

EXTRA DETAILS:

The one complicating factor with Olympic events (and many other sporting events) is that it is possible for athletes to tie (or dead-heat), and so it is possible for an event to have more than one medal awarded of a particular type. This is a very rare occurrence (except in some combative sports), and so we will assume that results like a triple dead-heat are not possible, but we will allow for an event to contain both a head-heat for first place followed by a dead-heat for third place. This means that as well as identifying countries winning medals for an event, we will need the top 4 finishers and their positions (because there may be up to 4 medallists). The result data for an event will therefore need 4 results, with the possible results being 1st, 2nd , 3rd, 4th (the normal case); 1st, 2nd, 3rd, 3rd (dead-heat for 3rd place); 1st, 2nd , 2nd, 4th (dead-heat for 2nd); 1st, 1st, 3rd, 3rd (dead-heat for both 1st and 3rd); and 1st, 1st, 3rd, 4th (dead-heat for 1st). Remember that only the competitors who place 1st, 2nd, or 3rd are awarded medals.

TASKS:

Your program will read two data files, set up in the same folder as was done for the first assignment. These data files are called input2a.dat and input2b.dat. You program should have the following steps:

  • Read the country codes from the first data file and store them (wherever your program design says it is best to do so). There will be 25 names. You may then close the first file. They will appear in the file in alphabetical order and the country names will be separated by whitespace characters (spaces or newlines), so they can be input using a standard string format in C.
  • Read the second data file until end-of-file. The data in this file will consist of:
    • an event name (a string of up to 15 characters), followed by
    • the 4 best performing countries in that event, each being a position number (an int with the value 1, 2, 3, or 4) and a country name (a string belonging to the set of countries already listed).
    • If the positions listed in the data are not valid and in order (e.g. 4 3 2 1) then you should ignore this data set and report it as an error.
    • Do not worry about incomplete data for any event.
  • For each event, find each correct country in your list, add one to the medal tally according to the position obtained. If a country name is mentioned that cannot be found in your list of countries, then report the event name and the offending country string as an error message, but still process the other results for that event. The country search is case-sensitive, that is Aus will not match AUS.
  • Calculate the total number of medals won by each country.
  • Produce an alphabetically ordered list of the countries and their medal tallies. Consisting of country name, Golds, Silvers, Bronzes, and Total Medals, making sure the lists is output in columns with an appropriate title and width.
  • Sort the list into decreasing order of overall performance by each country:
    • The highest number of gold medals takes precedence,
    • If Golds are equal then highest number of Silvers takes precedence,
    • If Golds & Silvers are equal then decide by number of Bronze medals
    • If all three are equal then simply choose by alphabetical order
  • Produce a similar performance-order list of results to the alphabetical one above, except that this time only print results for countries that have won at least one medal.

Observation: While it is possible to complete this assignment using a number of parallel arrays, your design will be better and easier to work with (especially for sorting the results), if you define your own structured type (you should use our naming convention of structname_t), and then have a single array of these objects. Your design will also benefit from having a number of functions. A solution that does not have well designed functions to perform major tasks, will be marked down significantly.

OUTPUT:

Output should be produced along the following guidelines: Name should be right-justified as stated above, The medal counts are each integers and so an appropriate field size can be used to obtain proper column-style output. Use headings as appropriate to display the data as a table. E.g.

Medal Tally - Alphabetical Order
Country Gold Silver Bronze Total
---------------------------------------------
AUS 24 12 10 46
BRA 15 13 19 47
BUL 6 10 8 24
CHN 22 24 20 66
………… etc.

DATASETS:

There will be 25 country names in the first (input2a.dat) data file. The countries you should use are listed above. We may run your program using a different list of countries, and if you are from overseas and I have not mentioned your particular country, you may leave out a country and insert your own, but you will have to alter the second data file to take account of this. While the file containing the country list will always have 25 country names, the second data file may have any number of complete data sets. Data for the results of a few events are listed below – you should add to this so that there is enough data to properly test the different aspects of your program (e.g.):

Mens-100m 1 JAM 2 USA 3 USA 4 AUS
Womens-100m 1 USA 2 JAM 3 USA 4 USA
MensLongJump 1 BUL 2 AUS 3 HUN 4 ITA
Pole-Vault 1 AUS 2 RUS 3 POL 4 HUN
Boxing57kg 1 ZAM 2 USA 3 SAF 3 ZIM
Mens5000m 1 KEN 2 ETH 3 KEM 4 BUL
Womens-200m 2 JAM 1 USA 3 AUS 4 POL

Note 1: The 57kg Boxing event shows the way that dead-heats are recorded

Note 2: that the second last data set contains an error which would be reported as

Error: Mens5000m Country KEM not competing

Note 3: The last data set is in error and would be reported as

Error: Womens-200m Results 2 JAM 1 USA 3 AUS 4 POL are invalid

It will be normal for these to be one set of data representing one event per line. As each event is run, extra data can then be easily added to the end of the input2b.dat file.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.