programming in C.
Microsoft Word - A3.docx Assignment 3: commonWealthGames2022 (Marked out of 100, 8% weight) Topics covered (in addition to 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 commonWealth.txt. • When you run the program, this filename commonWealth.txt must be passed as a command-line argument - read Week 8 lecture slides (W8L1.pdf) for more on command- line arguments. • Use the following constants – they are already defined in givenA3.h: #define COUNTRIES 15 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 Commonwealth Games in Birmingham this year. For the purpose of this assignment, we have the medal tally for 15 countries only, that are picked at random. The country names and their medal counts that you need for this code are given in the data file commonWealth.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. All function definitions must be placed in a file called lastnameFirstnameA3.c. Important tip: Start the assignment by writing the first function readFromFile first– this will populate the arrays you need for other functions. 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 [MEDALCAT], 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 (char countryNames [COUNTRIES][MAX_LENGTH_CNAME], int totalMedals[COUNTRIES]) Returns void Displays a horizontal histogram of stars, where each star represents 2 medals (any remaining medal will also count as 1 star). The total number of medals must be printed at the end of the line. For example, the number of stars printed for Australia are 89, although its total count is 178. Similarly, Uganda, with a total number of medals as 5, prints 3 stars (and not 2). (note that the medal counts displayed here may be different from the actual medal counts in the games). 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: 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 choices shown below in section 1.1.1. Call this program lastnameFirstnameA3Main.c. You may use the main function given in file givenMain.c on Courselink as the starting code for writing your main function. 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 (you may use the menu given in givenMain.c) • The file name commonWealth.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 (commonWealth.txt) to function readFromFile. Menu choices are shown next: 1. Display all country names read from data file commonWealth.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. Exit 2.0ProgramSubmissionandAdministrationInformation The following section outlines what is expected when submitting the assignment and various other administration information with respect to the assignment. 2.1ProgramSubmission You must submit 2 files lastnameFirstnameA3.c and lastnameFirstnameA3Main.c Incorrect file names will result in penalty. 2.2ProgramExpectations Your program is expected to follow the outlined information exactly. Failure to do so will result in deductions to your assignment grade. • The program files you submit MUST compile with NO warnings and errors using the flags - std=c99 and -Wall. • If you decide to define and use helper functions (other than what is listed in the .h file), then you must also add their prototypes in lastnameFirstnameA3.c, along with their definitions. • Programs that fail to compile will be given a mark of 0. • Programs that produce warnings upon compilation will receive a deduction of 1 mark for each type/category of warning. • Penalties will occur for missing style, comments, header comments etc. • The program file must contain the header comment shown in section Program Header Comment Format with the underlined & bolded sections properly filled in. 2.3Listof“DoNot”s • Do not change any given prototype • Do not use Global Variables o Using global variables will result in 0 in the assignment • Do not use GOTO statements o Using Goto statements will result in 0 in the assignment 2.4HeaderComment Use the template given below for header comment – you must include them in both c files submitted. . /!\ Note: The file name, student name and email ID must be changed per student. /************************chaturvediRituA3.c************** Student Name: Ritu Chaturvedi Email Id: ritu Due Date: November … Course Name: CIS 1300 I have exclusive control over this submission via my password. By including this statement in this header comment, I certify that: 1) I have read and understood the University policy on academic integrity. 2) I have completed the Computing with Integrity Tutorial on Moodle; and 3) I have achieved at least 80% in the Computing with Integrity Self Test. I assert