CSCI-1200 Data Structures
Homework 2 — Tennis Classes
In this assignment you will practice using C++ classes as you parse and compute statistics from the results of
Grand Slam tennis championships (the Australian Open, the French Open, Wimbledon, and the U.S. Open).
Please carefully read the entire assignment before beginning your implementation.
Here’s a crash course in tennis scoring: A match between two players consists of a number of sets. For
men’s Grand Slam events, the first player to win three sets is the winner of the match (a.k.a., the best
of five). Each set in the match consists of a number of games. The first player to win six games is the
winner of the set, but the player must win by two games. If the set score gets to 6-5 (or 5-6), the players
play a twelfth game. If the set score is 7-5 (or 5-7), the set is over.
In this match, player Novak Djokovic defeated player Andy Murray in a four set match. Djokovic won the
first set (which went to a tiebreak). Murray won the second set (also a tiebreak). In the third set Murray
only won three games, and in the last set Murray did not with any games.
File I/O and Command Line Arguments
Your program will run with three command-line arguments. The first is the input file containing the match
information. The second is the output file where you will write the computed statistics. The third argument
will indicate which data table should be printed. Valid options for the third argument are: –match_stats,
–game_stats, or –custom_stats. For example, here is a valid command line to your program:
./tennis_statistics.out sample_scores.txt sample_scores_out.txt –match_stats
We provide a variety of small and large input files, and sample output for some of these input files. The
input data was originally downloaded from http://stevegtennis.com/, but the format has been modified
to simplify your work to parse the input.
Each match is listed on a separate line. The winner is always listed first. Each player has a first name and
a last name (two strings). The special string “d.” is placed between the two names. Each set is a string
concatenating the number of games the first player won with the number of games the second player won,
with the character “-” between.
Statistics Collected and Output
When –match_stats is specified, your program should create a table with the players ordered by the
percentage of matches they won. Alphabetize players by last name, then first name if they are tied. Each
row of the table should include the player, the number of matches won, the number of matches lost and the
percentage of matches won. You should do a little bit of nice formatting to this output (see the example
code from lecture and look at STL iomanip library references).
For example, given an input file with these matches:
Marcos Baghdatis d. Radek Stepanek 6-4 6-3 3-6 0-6 7-5
David Nalbandian d. Danai Udomchoke 6-2 6-2 1-6 6-7 6-1
Marcos Baghdatis d. Ivan Ljubicic 6-4 6-2 4-6 3-6 6-3
Marcos Baghdatis d. David Nalbandian 3-6 5-7 6-3 6-4 6-4
Your program will produce this table:
Player W L percentage
Marcos Baghdatis 3 0 1.000
David Nalbandian 1 1 0.500
Ivan Ljubicic 0 1 0.000
Radek Stepanek 0 1 0.000
Danai Udomchoke 0 1 0.000
When –game_stats is specified, your program should create a table with the players ordered by the
percentage of games they won. Again alphabetize players by last name, then first name if they are
tied. As in the first part, each row lists the player, the number of games won, the number of games lost and
the percentage of games won. Here’s the output for the data above:
Player W L percentage
David Nalbandian 49 44 0.527
Radek Stepanek 24 22 0.522
Marcos Baghdatis 73 69 0.514
Ivan Ljubicic 21 25 0.457
Danai Udomchoke 18 25 0.419