Sei sulla pagina 1di 2

KIE1008 (Programming Tutorial) Session 2016/2017 (Semester 2)

Tutorial 4: Stacks and Queues

1. This programming exercise aims to develop a card game using stack.

There are four suits: diamond (♦), club (♣), heart (♥) and spade (♠); and each suit contains 13
cards: 2-9, Jack, Queen, King and Ace. The ‘value’ of the card is given as above in descending order
(value first, then suit). (♠Ace being the largest and ♦2 being the smallest).

The game contains two players, and each player is randomly given 10 cards. Then, the two players
will compare card by card (according to the stack sequence). The player with “larger” card will
take both cards After comparing all the 10 cards, the player with more cards is the winner.

Note:

i. Ensure the randomness in the card distribution so that each run will give a different set of card.

ii. Ensure no duplicate card being assigned (only one set of cards)

Sample output:

Player 1: S2 CK H4 S5 D8 S7 D9 SQ HJ DQ

Player 2: D3 CA H3 DJ S6 HK H2 SK DK SA

Winner: Player 2 (14 cards)

2. This programming exercise aims to model a queuing system at a bank that consists of two queues:
one normal queue and one priority queue for senior citizen (above the age of 55) and VIP. The
service conditions are given as below:
i. Customers at VIP queue will be served first if the queue is not empty.
ii. For every 3 customers from VIP queue being served, 1 customer from normal queue must
be served.
iii. The time to serve a customer is 10 min. (a customer cannot be served prior to his/her
time of arrival)
iv. The capacity for each queue is 10 customers; after the capacity if full, customer that is
entitled for priority queue is put at normal queue, but the normal customer will be denied
service (dropped).

The arrival time of the customers and their status are given below:

Customer Arrival Time Age Status


A 0900 22 Normal
B 0900 23 VIP
C 0900 26 Normal
D 0900 25 Normal
E 0900 56 Normal
F 0900 57 Normal
KIE1008 (Programming Tutorial) Session 2016/2017 (Semester 2)

G 0900 58 Normal
H 0930 25 Normal
I 0940 32 Normal
J 0950 60 VIP
K 0950 65 Normal
L 1000 63 Normal
M 1000 45 Normal
N 1000 48 Normal
O 1010 50 VIP

Write a program that shows the service order and the time of service for the customers above.

Note: Are there customers being rejected services or downgraded due to queue full?

Example output:

1. 0900: Customer B (Priority)


2. 0910: Customer E (Priority) …

---END---

Potrebbero piacerti anche