|
|
|
|
eXercise #10
Adding To The Environment
- Create enumerated types for the following set of values. Where possible,
use natural ordering. In each case indicate the number of different
values data of this type can take on as well.
- The colours of the rainbow
- The suits in a deck of cards
- The card values in each suit of a deck of cards
- The states of Australia (in post code order if known)
- The signs of the zodiac
- The various Brisbane TV Channels
- The differerent geological eras
- At most, 5 automobile manufacturers
- The four basic human emotional states are fear, anger,
glad(ness) and sad(ness). We could further divide
these into the categories of active which includes anger
and gladness, and passive which contains fear
and sadness.
Create three pascal types emotions, activeEmotions
and passiveEmotions and two variables myActiveEmotionalState
and myPassiveEmotionalState of the appropriate type. Make
legal (but not necessarily accurate) assignments statements tfor each
of these variables.
- A Pack of cards is divided up into 4 suits (clubs, spades,
diamonds and hearts). Each suit contains Ace, 2,
3, 4, 5, 6, 7, 8, 9, 10, J, Q and K. It is possible to represent any
card in the pack as a number between 0 and 51 (being 52 cards in total
excluding the Joker).
The suit can be extracted from the cardNumber by using the
DIV operator:
cardNum div 13 = suitNumber (which will be 0, 1, 2 or 3)
cardvalue can be extracted from the cardNumber by using the
MOD operator:
cardNum MOD 13 = cardValue (which will be 0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11 or 12)
Using this information, write a program containing relevant type definitions
for suit and cardvalue that will randomly generate and PRINT OUT the
suit and face value of the card.
- Using the program from the previous question, generate 2 random
cards (ensure they are NOT the same card) and report on which is the
HIGHEST card, or if it is a TIE (this is a primitive game of Highcard).
|
|
|
|
|
|
|