IUP Computer Science
CO 310 Spring 1997

Project 6
(Due   29 April 1997)

For your last project, you are to write a program that performs various tasks related to a tournament. Your program will need to construct a tournament tree by deciding which teams are winners and which are losers in a tournament. When the winner of the tournament is determined, your program must display information about that team and then handle queries about any other team taking part in the tournament.

You will be given a complete RandomNumber class to use in deciding which team wins each game. This class is provided by Ford & Topp (authors of our textbook). You will also be given a partial Ttree class to use in constructing the tournament tree and in answering questions about the teams playing in the tournament. You will be required to add one member function to the Ttree class (you may add others if you wish). The one that you must add is

void  Beaten  (void)	
which displays the names of each team that the team in the Current node has beaten in the tournament.

Write main (and any associated functions) to read in the names of 64 teams from a file and construct degenerate Ttrees whose roots hold the team names. Then, have pairs of teams play a game and randomly choose a winner. Put the winner's name in the root of a degenerate Ttree and merge this Ttree with the two Ttrees whose roots hold the names of the teams playing the game. This action should produce the next level for the tournament tree. Repeat the game playing for teams on the new level; and repeat for each succeeding level until the tree is complete and an overall winner is chosen.

Here is an example for 4 teams, named A, B, C, and D.

Pair A and B for a game and assume the random choice for winner is A. Pair C and D for a game and assume the random choice for winner is D. Form the next level as shown.

Then, repeat for the next level, having teams A and D play; assume the winner is D. Then, the tournament tree is complete (see next page). Output the name of the winning team (e.g. D) and list all the teams that the tournament winner has beaten, A C

Next, allow tournament queries to be made. Prompt for a team name, read it in, and display a list of all teams beaten by that team in the tournament. Repeatedly, prompt until a name is entered that is NOT a team in the tournament.

The data file for this project is named TOURNEY.DAT. The file RANDOMFT.H contains the RandomNumber class; and the file PROJ6.CPP contains a partial Ttree class and a minimal main function. All of these files are in 310LIB:, O:\JLW\310, and L:\JLW\310 as with previous projects. You should modify and rename PROJ6.CPP to include all of the Ttree class and rest of your program. Rename the file to you-p6.cpp where you is your initials. This way you will only need to submit one file containing your program. TOURNEY.DAT consists of the number of teams on the first line and then one team name per line for the rest of the file. All team names are single words containing no more than 12 letters. When reading the file, read the correct number of team names; do not read to end of file.

EXTRA CREDIT:
Small: Write the beaten function recursively.

Large: Modify your program to handle any number of teams up to 100, not just numbers of teams that are powers of 2. When there are an odd number of teams on a level, randomly select one to get a "bye" into the next level. Pair all other teams and randomly select winners. Note: there are actually 65 team names in TOURNEY.DAT. Change the first line to 65 and you have ready-made test data for the extra credit part.

The RandomNumber class is used as follows:

int             val;
RandomNumber    pick(29);		
val = pick.Random(100);		
val = pick.Random(4) + 10;	
 
This makes pick a random number and "seeds" it with 29. You may use any positive number as a seed (0 seeds with the system time). The first assignment makes val an integer in the range 0 to 99; and the second assigns val an integer in the range 10 to 13;