RU beehive logo ITEC dept promo banner
ITEC 320
2018fall
nokie
ibarland

Pointers and ADTs
hw07 tournament: implement stack, queue

Due: 2018-Dec-08 (Sat.) 23:59 on D2L; no late programs accepted.

Deliverables

On D2L, submit tournament.adb, queues.adb, stacks.adb. You do not need need to submit the package-specifications queues.ads, stacks.ads.
Bring hardcopy by on Monday (you can put it under my door if I'm not around).

Updates: ignoring formatting and minor phrasing changes

You are to write an Ada program simulating a tournament that is a series of last-person-standing contests. You will read in the player-descriptions (name, skill-level), and then print the tournament-results. The tournament proceeds as follows:

  1. The players form a “contenders’ line” as they arrive at the contest (i.e. the order of this line will initially be the same as the order of the input data).
  2. The first two contenders play a match (with the winner determined as described below). The match-winner stays in the contenders’ line (going to the back), while the loser goes to the back of the “runner-ups’ line”.
  3. Step (b) repeats: After the first two contenders play, the next two in line play, and then the next two, etc. When there is only one person in the contenders’ line, that person proudly marches off to the winners’ area.
  4. Then, the runner-ups’ line becomes the new contenders’ line (with one fewer player than before), and the steps (b)-(c) repeat.
  5. When everybody is in the winners’ area, you will print the members of that line as described in output format.

Match Resolution

A match between two individuals is resolved by skill, with tie-breakers given here. The match-winner is the player with…

  1. the higher skill level if different; else…
  2. the larger age-in-years (experience, you know) if different; else…
  3. the larger number of wins so far if different; else…
  4. the fewest number of losses if different; else…
  5. the lower initial arrival-number (i.e. the player who “arrived” first in the input).

Input: Input is from stdin, 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 positive 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. Remember that you will probably want 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:

(The last line will end with a newline.)

Players should be printed reverse order (i.e. the winner of the very first match gets printed last). Print one line per player (even if there are are only zero or one players).

Example

Sample input

Person uno 500 55 Player dos 400 54 Senorita tres 300 53 Chap cuatro 200 52 Person cinco 100 51
UI detail: If copy/pasting the above, be sure to drag the mouse just slightly out of the box, so that your copying includes the final newline (after the 51).

Expected output:

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

Stacks and Queues: You must implement a dynamic implementation of a queue and a stack, using the queues.ads and stacks.ads package specifications. Notice that these packages contain a procedure print to print the current stack and queue. You can use this for debugging, and perhaps for printing your output. Notice the package-parameter for a routine to print one ItemType. (Why?)

Do not make any changes to these specification files. (I will use the originals, when I compile your program.)

Notes

As always: structure your program well, and make good use of language features.

Some class-notes, and a good set of incremental steps, about queues can be found here.

My own solution used a helper routine called move that moved players out of one queue and onto another.

In the notes on Generic Child Packages the second 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 actual code 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 (i.e. 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, which you can use 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 (not advised), then you can implement and use the array implementations of (bounded) stacks and queues. If you do so, do not submit your array implementations.


logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.