IPT - A Virtual Approach IPT A Virtual Approach by Peter Whitehouse
Quick Links:
 
 
Information and Intelligent Systems Social and Ethical Implications Human Computer Interaction Software and Systems Engineering eXercise Files Course Outline and Assessment A-Z of Geeky Acronyms Terrace Work Program 2004 Sillybus FAQ = Frequently Asked Questions Help
 
 

eXercise #10

Adding To The Environment

  1. 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.
    1. The colours of the rainbow

    2. The suits in a deck of cards

    3. The card values in each suit of a deck of cards

    4. The states of Australia (in post code order if known)

    5. The signs of the zodiac

    6. The various Brisbane TV Channels

    7. The differerent geological eras

    8. At most, 5 automobile manufacturers


  2. 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.

  3. 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.

  4. 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).

Solutions

wonko@wonko.info
©Copyright t 1992..2017+. Edition 25.150117
wonkosite
Creative Commons License
This work is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 2.1 Australia License
.