ITEC 320: Programming Assignment 5

Due Date: 11:59:59 p.m., Saturday 5/2/2020

Late programs not accepted

Submit command: submit itec320-01 compete.adb queues.adb stacks.adb


Last modified:
Updates: You should now use this URL for the assignment checker: itec-noki01. The old one will disappear.

  1. 2020 Apr 25 11:28:16 PM: Set 2020 due date
  2. 2020 Apr 25 08:19:34 PM: Corrected output order so that it's consistent everywhere (ie overall winner printed first and first person eliminated printed last)
  3. 2019 Nov 15 03:00:11 PM: Fixed the tournament directions and sample output.
  4. 2019 Nov 15 03:00:11 PM: Assignment checker now up (vpn or on-campus).

You are to write an Ada program simulating a double-elimination tournament. You will read in the player-descriptions (name, skill-level, age), and then print the tournament-results. The tournament proceeds as follows:

  1. The players form a line as they arrive at the contest (ie the order of this line will initially be the same as the order of the input data). This is the zero-loss line.
  2. The first two players in the zero-loss line play a match (with the winner determined as described below). The match-winner stays in the zero-loss line (going to the back), while the loser goes to the back of the one-loss line.
  3. Step (b) repeats: After the first two players play, the next two in line play, and then the next two, etc., until there is only one person in the zero-loss line. That person remains in the zero-loss line until the last round.
  4. For the second round, the process repeats with the players on the one-loss line. (Essentially steps b and c repeat, but with different lines). Pairs of players play a match and the match-winner goes to the back of the one-loss line and the loser goes to the all-done line. When round two is finished, the zero-loss and one-loss lines will each have exactly one player, and everyone else will be on the all-done line.
  5. For the final round, the two players that are on the zero-loss and one-loss lines play matches until one of them has two losses, and that player joins the all-done line. At the very end the player who doesn't have two losses joins the all-done line (and tries to not gloat).
  6. When everybody is on the all-done line you will print the members of that line as described in output format.

Match rules:

  1. In a match between two players, the player with the largest skill level wins.
  2. In a match between two players with the same skill level, the oldest player wins (experience, you know).
  3. In a match between two players with the same skill level and the same age, the player with the largest number of wins will win.
  4. In a match between two players with the same skill level and age and the same number of wins, the one with the fewest number of losses will win.
  5. In a match between two players with the same skill level and age and the same number of wins and losses, the one who originally arrived first wins (ie the winner is the player who was first in the input).

Input: Input is from standard input, with two successive lines of input for each player. The first line of input for a player contains the players name. You should trim this line, but it can contain embedded white space and other characters. The second line contains two postive integers: A skill level and an age. Skill levels will be in the range 1 .. 999 and age in the range 3 .. 99. There can be white space around any name or value. There can be any number of players (well, within memory limits). You may assume that the input is valid.

Since there is no limit on the name length you may wish to look at Ada.Strings.Unbounded. This package contains a procedure Trim which uses a value for Side which is of type Trim_End, defined in package Ada.Strings. You can use Ada.Text_IO.Unbounded_IO.Get_Line to input an Unbounded_String. You may need to use procedure Ada.Text_IO.Skip_Line when processing the input.

Output: The output of your program should consist of a header followed by the information for each player, in columns, with one line per player:

Players should be printed reverse order: the first person to join the all-done line is printed last first, and the last person to join that line (ie the person who doesn't have two losses) is printed first last. Print one line per player (even if there are are only zero or one players).

Sample run: With the input shown below

 Person uno
            500 55 
            Player dos 
            400 54 
Senorita tres 
300           53 
Chap cuatro 
            200 52 
Person cinco 
            100 51

Expected output:

Number Age Skill Wins Losses Name 1 55 500 4 0 Person uno 2 54 400 2 2 Player dos 3 53 300 2 2 Senorita tres 5 51 100 0 2 Person cinco 4 52 200 0 2 Chap cuatro

Stacks and Queues: You must implement a dynamic implementation of a queue and a stack, using these queue and stack package specifications. Notice that these packages contain a procedure print that prints the current stack and queue. You can use this for debugging, and perhaps for printing your output. Notice that the packages have a parameter for a routine for printing an item of type ItemType. (Why?)

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

Notes:

You must create an access type for players so that you can use pointers to players on your lines.

Dr. Barland's notes on writing the queue package.

You will of course want to structure your program well and make good use of language features.

In the notes on Generic Child Packages the second generic package example use a print routine as a parameter. This is similar to this assignment's generic stack and queue packages, which have a parameter for printing. (Of course, the example is different from this assignment since the example uses arrays and child packages).

Notice that types stack and queue are limited types, which means that a variable of type stack or queue can't be assigned (ie be on the left of an assignment statement) in the client.

You might find it helpful to keep a count of the number of players; you can use this count to control how many matches need to be played on each queue since each match moves one player off the queue.

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 your array implementations.