Answer a sample solution follows pseudocode start

This preview shows page 59 - 61 out of 61 pages.

Answer: A sample solution followsPseudocode:startDeclarationsnum xnum ynum limit59
Programming Logic and Design, 9eSolutions 6-num indexnum playerCardnum playerCardNumnum computerCardnum computerCardNumnum playerWin = 0num computerWin = 0num tie = 0string playerCardSuitstring computerCardSuitnum LENGTH = 52num GROUPS = 4num ROUNDS = 26num BOUNDS[GROUPS] = 0, 13, 26, 39num cards[LENGTH] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52string SUITS[GROUPS] = “Clubs”,“Diamonds”,“Hearts”,“Spades”getReady()while y < ROUNDSdetailLoop()endwhilefinishUp() stopgetReady()limit = LENGTHy = 0returndetailLoop()// input the player’s cardindex = random(limit)playerCard = cards[index]x = GROUPS-1while playerCard < BOUNDS[x]x = x – 1endwhileplayerCardNum = playerCard – BOUNDS[x]playerCardSuit = SUITS[x]// move the cards up (take out player card)x = indexwhile x < (limit – 1)cards[x] = cards[x+1]x = x + 1endwhilelimit = limit – 1// input the computer’s cardindex = random(limit)computerCard = cards[index]x = GROUPS-1while computerCard < BOUNDS[x]x = x – 160
Programming Logic and Design, 9eSolutions 6-endwhilecomputerCardNum = computerCard – BOUNDS[x]computerCardSuit = SUITS[x]// move the cards up (take out computer’s card)x = indexwhile x < (limit – 1)cards[x] = cards[x+1]x = x + 1endwhilelimit = limit – 1output “Player’s card: ”, playerCardNum, “ of ”, playerCardSuitoutput “Computer’s card: ”, computerCardNum, “ of ”, computerCardSuitif playerCardNum > computerCardNumoutput “Player wins hand!”playerWin = playerWin + 1elseif computerCardNum > playerCardNumoutput “Computer wins hand!”computerWin = computerWin + 1elseoutput “Tie!”tie = tie + 1endifendify = y + 1returnfinishUp()output “End of game”return61

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture