ITEC 320: Programming Assignment 5

Due Date: 5:00 p.m., Saturday 12/9/2017

Late programs NOT accepted

Submit command: submit itec320-01 competition.adb queue_pkg.adb stack_pkg.adb

Last modified:

  1. 2017 Nov 29 09:06:35 PM: Slightly modified output format and updated assignment checker.

You can see an example of this program at assignment checker (which uses gnoga to integrate the GUI, web server, and problem solution). On-campus or VPN session required.

You are to write an Ada program that simulates a double elimination contest. Your program will input a list of players, each of whom has a name and an integer skill level. (More detail on the input format is given below.) After all players have been input, pairs of players are repeatedly formed and the members of a pair play a match against each other. As described below, the skill level (and perhaps some other information) determines who wins the match. Players are eliminated from the competition when they have two losses.

The sequence of play is as follows:

  1. Players with no losses play matches until only one remains with no losses.
  2. Then, players with one loss continue to play matches until only one player remains with one loss.
  3. Finally, the two players who have exactly zero and one losses play one or two matches until one of them has exactly two losses (and the other has zero or one loss).

Players stand in lines until it is time for a match. Three lines are needed for different types of players: those with no losses, those with one loss, and those with 2 losses (ie those who have been eliminated). The players form the line of no losses as they arrive at the contest (ie the order of this line will initially be the same as the order of the input data). When match time comes, the first two players in the appropriate line get out of line and play a match. The winner goes to the back of the same line, and the loser goes to the back of the line containing players with the appropriate number of losses.

Players in any line play in order. In other words, the first two play, then the second two play, then the third two play, and so on, until only one player remains in that line.

The output of your program should consist of the following information for each player, in columns with one line per player:

In the output, the list of players should be in the REVERSE of the order in which they were eliminated. In other words, the winner should be first, followed by the player who the winner most recently beat, and so on with the player who was eliminated first at the end of the output. Here is a sample run.

Sample input:

Person890123456789     500
Person2                400
Person3                300
Person4                200
Person5                100

Expected output:

Name                  Number  Skill  Wins  Losses 
Person890123456789       1     500     4     0
Person2                  2     400     2     2
Person3                  3     300     2     2
Person5                  5     100     0     2
Person4                  4     200     0     2

Input comes from standard input and consists of one line of input for each player. Each line of the input consists of the name in the first 20 columns and the skill level beginning in column 21. Your program should produce meaningful output if there are zero, one, or two players. (Don't forget that two players should have contests, until one has two losses.) You may assume that the input is valid.

A player's skill level will be represented by an integer. In a match between two players, the player with the largest skill level wins. If two players have the same skill level, the player with the largest number of wins will win. If two players have the same skill level and number of wins, the one with the fewest number of losses will win. IF two players have the same skill level and number of wins and losses, then the one who arrives first wins (ie the winner is the player who is first in the input).

You must implement a dynamic implementation of a stack and a queue, using these stack and queue package specifications.
[Note: If you want to work on your client program before you have your dynamic queue packages working, then you can implement and use the array implementations of stacks and queues. However, if you do this, do NOT submit the array implementations.]

It is important that you do not make any changes to these specification files

Your program should be called competition.adb. You do not need to raise any exceptions in your program.


  1. Don't overcomplicate the input. You can simply have a loop whose entire body something like get(s); get(skill); where s: String(1 .. 20); . Make sure that you don't have extra blanks at the end of the input lines and that you create your input file on the same system that you are executing your program.

  2. You might find it useful to count the number of players.

  3. If you want to work on the client before finishing with the dynamic stack and queue, you can find static implementations by replacing p5.html with showstatic in the URL for this page.

Extra credit: For 10 points extra credit, you can write your client using pointers. In some ways, using pointers makes the client a bit more complex to write; however, in other ways, using pointers actually simplifies the program.

You will want to structure your program well and make good use of language features. As always, be sure to use good indentation, descriptive constant, variable, type, function, procedure, and package names. Use named constants when appropriate. Also use good commenting style, remembering that the first thing in any program file should be a comment that gives a brief overview of what the file contains (and should do). You might find these commenting guidelines helpful.

When testing, be sure to use lots of different examples. You can either supply test data at the keyboard (remembering to end the input with a ^D at the beginning of a line), or by feeding the contents of a file to it (e.g. calc < test_data) where the use of the UNIX redirection symbol < causes the contents of the file test_data to be feed into the program as if they had been typed in from the keyboard.

When debugging programs, run-time exceptions are a common occurrence. One way to find the line at which an exception occurs is to place put statements in your program so you can follow it's execution. Another way is to use the gdb debugger (ie gnu debugger): these instructions show you how. Note that you can also use gvd (the gnu visual debugger) to debug your program and find the source of an exception as well as other information.

Use the submit command to turn your program in for grading. You may submit as many times as you like, but since only the last submission is kept, if the last one is late, then your assignment is late. Always remember to use the -ls option of submit to check that your submission was received. To submit your work you can use the command at page top.