Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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...

1 answer below »
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 a
ays, 1 and 2D strings
1.0    Prerequisite    –    First    things    First    

• 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.1    The    task        
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
andom. 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.
Part    A    of    the    task:
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 a
ays you need for other functions.
1.1.0    Function    names,    their    prototypes    and    description:    
    
1 void readFromFile (char fileWithMedals [30],
XXXXXXXXXXint country [COUNTRIES][MEDALCAT],
XXXXXXXXXXchar 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],
XXXXXXXXXXint totalAllCountries [COUNTRIES]);
Returns void
Finds total medals for each country and stores it in a
ay totalAllCountries.
3 int findTotalPerMedal (int country [COUNTRIES][MEDALCAT],
XXXXXXXXXXint totalAllMedals [MEDALCAT],
XXXXXXXXXXint * whichMedal);

Finds total number of medals in each category (Gold/Silve
Bronze) and stores them in a
ay
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],
XXXXXXXXXXint 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],
XXXXXXXXXXchar countryNames [COUNTRIES][MAX_LENGTH_CNAME],
XXXXXXXXXXint 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],
XXXXXXXXXXchar 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],
XXXXXXXXXXchar 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],
XXXXXXXXXXint indexMedal,
XXXXXXXXXXint 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 a
ay called indexOfCountries.


9
int findAllWithOnlyXMedals (int country [COUNTRIES][MEDALCAT],
XXXXXXXXXXint indexMedal,
XXXXXXXXXXint 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 a
ay called indexOfCountries.
10 int findCountryIndexWithMinOrMaxLength (int minOrMax,
XXXXXXXXXXchar 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:    You    may    write    additional    functions    if    you    think    necessary.    If    you    do,    
you    must    include    their    function    prototypes    in    your    main    program    and    their    
definitions    in    lastnameFirstnameA3.c    –    DO    NOT    change    the    given    header    file.        
Part    B    of    the    task:        
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.1    main    program
Note that
• The main program must have a menu-driven code that displays a menu for each
function described in section XXXXXXXXXXyou 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.0    Program    Submission    and    Administration    Information    

The following section outlines what is expected when submitting the assignment and various
other administration information with respect to the assignment.

2.1    Program    Submission    
You must submit 2 files lastnameFirstnameA3.c and lastnameFirstnameA3Main.c
Inco
ect file names will result in penalty.

2.2    Program    Expectations    

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 e
ors 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.3    List    of    “Do    Not”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.4    Header    Comment        
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
Answered 4 days After Nov 23, 2022

Solution

Pratyush answered on Nov 28 2022
52 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here