files below
Microsoft Word - A3.docx Assignment 3: Olympics2020 (Marked out of 100, 9% weight) Topics covered (excluding those covered in A1 and A2): loops, functions, sequential files, 1 and 2D arrays, 1 and 2D strings 1.0Prerequisite–FirstthingsFirst • You are required to download the given header file called givenA3.h, and a text file called tokyoOlympics.txt. • When you run the program, this filename tokyoOlympics.txt must be passed as a command-line argument - read Zybooks 2.24 and 12.7 for more on command-line arguments. • Use the following constants – they are already defined in givenA3.h: #define COUNTRIES 10 This represents the number of countries. #define MEDALCAT 3 This represents the number of medal categories (e.g. Gold, Silver, Bronze). #define MAX_LENGTH_CNAME 100 This represents the maximum length of any country name. 1.1Thetask In this assignment, you are required to write multiple functions that help in generating statistics and reports on the medals achieved at Tokyo Olympics this year. For the purpose of this assignment, we have the medal tally for only 10 countries that are picked at random. The country names and their medal counts that you need for this code are given in the data file tokyoOlympics.txt. Your code must write definitions for the following functions (shown in section 1.1.0 below) and use them in main to test. More on main program is given in section 1.1.1. PartAofthetask: You must write a SEPARATE user-defined function definition, for each and every one of the following tasks. You must do this in a file called lastnameFirstnameA3.c. 1.1.0Functionnames,theirprototypesanddescription: 1 void readFromFile (char fileWithMedals [30], int country [COUNTRIES][MEDALCAT], char countryNames [COUNTRIES][MAX_LENGTH_CNAME]); Returns void This function takes 3 parameters as shown. The 1st parameter called fileWithMedals is a string that stores the filename of a sequential data file. The 2nd and 3rd parameters are populated using data file that stores the country names and medals won by each country. 2 void findTotalPerCountry (int country [COUNTRIES] [MEDALCAT], int totalAllCountries [COUNTRIES]); Returns void Finds total medals for each country and stores it in array totalAllCountries. 3 int findTotalPerMedal (int country [COUNTRIES][MEDALCAT], int totalAllMedals [COUNTRIES], int * whichMedal); Finds total number of medals in each category (Gold/Silver/Bronze) and stores them in array totalAllMedals Returns the maximum value in totalAllMedals Outputs (through call-by-reference parameter) the index of the category with maximum medals – category given in parameter whichMedal 4 void hHistogram (int country [COUNTRIES][MEDALCAT], int totalMedals[COUNTRIES]); Returns void Displays a horizontal histogram of stars, where each star represents a medal. The total number of medals must be printed at the end of the line. For example (note that the medal counts may be different for you). 5 int searchCountry (char countryName [MAX_LENGTH_CNAME], char countryNames [COUNTRIES][MAX_LENGTH_CNAME], int totalAllCountries [COUNTRIES]) Returns the total number of medals won by a country, given its name (countryName). If countryName does not exist in the given list of 10 countries, it returns -1. 6 void rankTopThreeByTotal (int totalAllCountries [COUNTRIES], char countryNames [COUNTRIES][MAX_LENGTH_CNAME]); Returns void Displays the top three country names and the total medals won by each of them – the display must be in order of total medals won. For example, it displays: Ritu Chaturvedi void hHistogram (char countryNames [COUNTRIES][MAX_LENGTH_CNAME], int totalMedals[COUNTRIES]); Ritu Chaturvedi Ritu Chaturvedi Ritu Chaturvedi MEDALCAT 7 void rankTopThreeByMedal (int country [COUNTRIES][MEDALCAT], char countryNames [COUNTRIES][MAX_LENGTH_CNAME]); Returns void Displays the top three country names and the total gold medals won by each of them – the display must be in order of total gold medals won. For example, it displays: 8 int findAllWithNoXMedals (int country [COUNTRIES][MEDALCAT], int indexMedal, int indexOfCountries [COUNTRIES]); Returns the total number of countries with no medal of a specific category, where category = indexMedal (1 for Gold, 2 for Silver, 3 for Bronze). Note that this category is input to the function by main. Stores the indices of countries that do not have indexMedal in an array called indexOfCountries. 9 int findAllWithOnlyXMedals (int country [COUNTRIES][MEDALCAT], int indexMedal, int indexOfCountries [COUNTRIES]); Returns the total number of countries that have ONLY won medals of a specific category, where category = indexMedal (1 for Gold, 2 for Silver, 3 for Bronze). Note that this category is input to the function by main. Stores the indices of such countries in an array called indexOfCountries. 10 int findCountryIndexWithMinOrMaxLength (int minOrMax, char countryNames [COUNTRIES][MAX_LENGTH_CNAME]); Returns the index of the countryName that has min or max length - use 1 for min and 2 for max. You must return only one index, even if there are more than 1 countryNames with a max or min length (You can decide which one to return in this case). /*\Note:Youmaywriteadditionalfunctionsifyouthinknecessary.Ifyoudo, youmustincludetheirfunctionprototypesinyourmainprogramandtheir definitionsinlastnameFirstnameA3.c–DONOTchangethegivenheaderfile. PartBofthetask: You must write a main program that displays a menu of functions 1 to 10. Call this program lastnameFirstnameA3Main.c. 1.1.1mainprogram Note that • The main program must have a menu-driven code that displays a menu for each function described in section 1.1.0. • The file name tokyoOlympics.txt (which is the first parameter of readFromFile function) must be given to main through a command line argument as described in section 1.0. (Hint: your main header must be given as int main (int argc, char * argv[])). Thereafter, main passes this filename to function readFromFile. Menu choices are shown next: 1. Display all country names read from data file tokyoOlympics.txt and the total number of medals won by each country 2. Function 2 - Find total number of medals won by each country 3. Function 3 - Finds total number of medals in each category (Gold, Silver, Bronze) 4. Function 4 – Display horizontal histogram 5. Function 5 – Search for a country and return the total number of medals won by it 6. Function 6 – Rank and display top three countries in order of total medals won 7. Function 7 – Rank and display top three countries in order of total gold medals won 8. Function 8 – Find and display all countries that won no X medals, given X as either Gold, Silver or Bronze 9. Function 9 – Find and display all countries that won ONLY X medals, given X as either Gold, Silver or Bronze 10. Function 10 – Find and display name of the country that has minimum or maximum length among all countries read in option 1. 11. Function 11 – Additional Task - Display Vertical Histogram 12. Exit 2.0Additional10%task The above task described in section 1.1 can fetch you 90% in this assignment. Complete the following for the additional 10%. Write the definition of a function that displays a vertical histogram of stars. void vHistogram (char countryNames [COUNTRIES][MAX_LENGTH_CNAME],