Assignment 2
Assignment 2
2024/2025 Semester 1
Assignment 2
Overview
The ICC Men’s T20 World Cup Cricket tournament was held in the West Indies and the USA from
June 1-29, 2024. The file, t20_world_cup_2024_batting_stats.txt, contains the batting
statistics of each player in the tournament. Each row in the file contains the following data on one
player:
The number of players in the file is unknown beforehand but a player name of “END” indicates that
there are no more players in the file.
This assignment requires you to write a program which generates some additional statistics on a
team specified by the user at the keyboard.
NB: You do not need to understand the game of cricket to do this assignment. You should focus on
the data and how to process the data to produce the required results.
Program Requirements
(1) Your program should start by requesting the user to specify the name of a team that
participated in the 2024 World Cup.
(2) Read the data for each player from the file, t20_world_cup_2024_batting_stats.txt. If
the player’s team is the same as the one specified by the user, write the following data on the
player in one line of a new output file, country_batting_stats.txt, in the order specified:
NB: Data from the Team Name and Strike Rate columns in the input file should be omitted
from the output file.
If no players are found for the team specified by the user, your program should display a
message and terminate (by using the exit (1) statement or the return (1) statement).
(4) Open the country_batting_stats.txt file and read the data on each player. As the data is
being read, generate a histogram on the batting statistics of each player. One asterisk must be
1
displayed for every ten runs scored by a player. If this works out to a fractional number of
asterisks, x, display y asterisks, where y is the smallest integer bigger than x. So, if x is 12.3,
display 13 asterisks.
To display a certain number of asterisks on the monitor, a function has been provided,
printStars. To display 5 asterisks, call the function as follows: printStars (5). To display 8 asterisks,
call the function as follows: printStars (8). In general, to display n asterisks where n is an integer,
call the function as follows: printStars (n).
After producing the histogram, indicate how many rows of players were read from the file.
(5) While processing the country_batting_stats.txt file, write code to find out the following:
(a) The player who made the highest number of runs in the tournament and the player who
made the second highest number of runs. Note that the total number of runs scored by a
player is in the # Runs column.
The highest number of runs scored by a player in an ICC T20 World Cup tournament is 319. It
was scored by V_Kohli from India in the 2013/2014 tournament. For the player who made
the highest number of runs in the 2024 tournament, find the difference between his score
and that of V_Kohli.
(b) The player who made the highest individual score in a match for the given team (under the
Highest Score column). The highest individual score in an ICC T20 World Cup tournament is
123, made by BB_McCallum from New Zealand against Bangladesh in the 2012 tournament.
For the player with the highest score in the 2024 tournament, find the difference between
his score and that of BB_McCallum.
NB: Suppose that a player’s highest score is stored as a negative number, x. The actual
score of the player is -x. The negative number indicates that the player was “not out”
when he stopped batting.
(c) Find and display the name of the player who scored the smallest total number of runs in the
tournament.
(d) Find and display the name of the player who scored the highest average number of runs in
the tournament. The average is calculated by dividing the number of runs by (the number of
innings – number of “not outs”). For example, if a player scored 210 runs in 6 innings but
had two “not outs”, the average number of runs for that player is (210 / (6 – 2) (i.e., 52.5).
NB: Do not perform the division if (the number of innings – number of “not outs”) is equal
to zero. Instead, assign 0 to the average.
(e) The total number of fifties and the total number of hundreds scored by all the players in the
team during the tournament.
(6) You should review the Sample Output document to find out what your output should be for this
assignment. Your output does not have to look the same. However, numeric values should be
identical to what is shown in the document.
Files
2
The data file, t20_world_cup_2024_batting_stats.txt together with a .cpp file containing
the printStars function can be downloaded from myeLearning as a zipped file. Submit your program
for Assignment 2 in a single .cpp file. Do not submit any other files.