Algorithms and Programming eXercises #10
Adding to the Environment - Solutions
1. Type rainbows = (red, orange, yellow, green, blue, indigo, violet);
suits = (hearts, diamonds, spades, clubs);
cardvalues = (ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king);
states = (qld, nsw, vic, sa, wa, nt, tas);
zodiacs = (aquarius, libra, taurus, gemini.... cant remember, dang);
tvchannels = (abc, sbs, 9, 7, 10);
eras = (precambrian, cambrian, mezozoic ...);
manufacturers = (ford, holden, honda, mitsubishi, hyundai);
2. Type emotions = (fear, anger, glad, sad);
activeEmotions = (anger, glad);
passiveEmotions = (fear, sad);
Var myPassiveEmotionalState : activeEmotions;
myActiveEmotionalState : passiveEmotions;
Begin
myPassiveEmotionalState := fear;
myActiveEmotionalState := glad;
3. see Q9, Ex 12
4. Program HiCard;
{generates 2 cards and reports which is the highest - Ace = 1}
Type cards : 0..51;
Var card1, card2: cards;
Begin
card1 := random(52);
repeat
card2 := random(52)
until card2 <> card1;
if (card1 mod 13) = (card2 mod 13)
then writeln('IT IS A TIE!'
else if (card1 mod 13) > (card2 mod 13)
then writeln('CARD1 WON!')
else writeln('CARD2 WON')
End.
|