ComS 228 Fall 2005
Homework 1
Objectives:
- To implement a class and write member functions, including constructors
- To work with nested structs and arrays
- To practice writing test code
A single game of ten-pin bowling is made up of ten frames. At the
start of a frame, ten pins are freshly set up; the bowler tries to knock
the pins over by rolling a heavy ball into them. If all ten pins are
knocked over on the bowler's first try, it is called a strike
and an X is marked on the scorecard in the first slot for that frame.
Otherwise, the number of pins knocked down (0-9) during the first try are
marked down in the first slot and the bowler has a second try. If all the
remaining pins are knocked down during the second try, that is called a
spare and the second slot on the scorecard is marked with a /.
If the bowler doesn't knock down all the pins by their second try, then
that is called an open frame and the number of pins knocked down
during the second try is written down in the second slot for that frame on
the scorecard.
Calculating the score for a frame is tricky, and can be automated by
a computer.
- If the frame was an open frame, then the score for that frame
is the total number
of pins knocked down on the two tries.
- If the frame was a spare, then the score for that frame is 10 plus
the number of pins knocked down on the next roll.
- If the frame was a strike, then the score for that frame is 10 plus
the number of pins knocked down on the next two rolls.
Some things to notice:
- If you get a strike in the last frame, you have to bowl twice more to
compute the score for the last frame.
- If you get a spare in the last frame, you have to bowl once more.
- A perfect score in bowling is by making 12 consecutive strikes: 10 for
the regular frames, plus two extra strikes on the two extra rolls. The
score for each frame is then 30 (10 + 20 for the next two rolls), and since
there are 10 frames, a perfect score is 300.
In this programming assignment, you will be writing a class to handle
the matchup between two teams of bowlers. Each team consists of the same
number of bowlers, defined by a constant called TEAMSIZE. Each player
bowls 10 frames (plus extra rolls as necessary), and all their scores
are added together to get their team score. The team with the highest score
wins the matchup.
To start this assignment, download the BowlingMatch.h file.
Other than possibly changing the
value of TEAMSIZE for testing purposes, do not change anything in
BowlingMatch.h.
In particular, don't change the prototypes for any of the member functions,
as the TA will rely on them for testing.
You should also download BowlingMatch.cpp.
Put all of your code for this HW in BowlingMatch.cpp. In
this file, you should implement all the functions specified in
BowlingMatch.h. Additionally, if you want to write your own helper
functions, you can write them as non-member functions and put their
prototypes and implementations where indicated in BowlingMatch.cpp.
One of the constructors reads in the players' frames from a file. The
input file should be formated as follows:
- A player entry consists of the player's name on one line. Players'
names will be 20 characters or less, including spaces, and will end with a
newline. The next line contains characters representing ball1 and ball2 (if
necessary) for each frame, plus extra characters for extra rolls.
Spaces may or may not be inserted between
characters. There may be extra spaces at the end of the line.
- A team entry consists of the team name on one line, followed by
TEAMSIZE player entries. Team names will be 20 characters or less.
A blank line occurs after the last player.
- The input file will contain exactly two team entries.
Here is an example of a correctly formatted input file:
match.dat.
The printMatch() function needs to output the data in a nice-looking format.
Here's the format:
- A line containing "Team: " followed by the team name.
- A line containing "Total: " followed by the team's score.
- A table of scores for the team members.
The table constains a column of width 20, and for each frame, a column of
width 4. The text in all columns should be right-justified. The table
begins with a header row, with "Frame" in the first column and the numbers
1 to 10 in the next 10 columns. Then, for each player, the table contains
the following:
- A blank line.
- A line with the player's name in the first column and ball1 and ball2
characters in the frame columns, for the ten frames plus any extra rolls.
- A line with "score" in the first column, and the frame score for each
frame in the next 10 columns.
- A line with "total" in the first column, and the cumulative frame scores
for each frame in the next 10 columns.
Here is an example output showing what the
printMatch() function should display for the match.dat file given above.
You may download a sample program that tests the BowlingMatch class:
hw1test.cpp. Remember that this is sample
test code only; it does not fully test your implementation and fully-testing
your code is part of the assignment. Also, remember that part of the points
for this assignment will depend on documentation and programming style, as
discussed in the first recitations.
To help you handle compiling multiple files, you can download a
Makefile for this assignment and sample test code.
To compile all your code, just type "make" at the command line.
When you are ready to submit your programming assignment:
- Copy the file BowlingMatch.cpp into your turnin directory.
(Command: "cp BowlingMatch.cpp ~/turnin"). Make sure you copy
the file you have edited, not the originals you downloaded.
- Change to your turnin directory ("cd ~/turnin") and make sure only that
file is listed there ("ls").
- Run the turnin command ("~cs228/public/bin/turnin cs228 hw1"). Make sure
the last part of the command is "hw1" exactly.