Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Topic : Basics Types, Formatted I/O, Expressions, Selection Statements, Loops, Functions, Program Organization Your turn!!! Program : Classifying a Poker Hand (poker.c) Definition : The

image text in transcribed
image text in transcribed
Topic : Basics Types, Formatted I/O, Expressions, Selection Statements, Loops, Functions, Program Organization Your turn!!! Program : Classifying a Poker Hand (poker.c) Definition : The program classifies a poker hand. Each card in the hand has a suit and a rank. Jokers are not allowed, and aces are high. Suits: clubs, diamonds, hearts, spades Ranks: two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace For input purposes, ranks and suits will be single letters (upper-or lower-case): Ranks: 23456789tjqka Suits: cdh s After reading a hand of five cards, the program will classify the hand using the categories, If a hand falls into two or more categories, the program will choose the best one. Categories (listed from best to worst): straight flush (both a straight and a flush) four-of-a-kind (four cards of the same rank) full house (a three-of-a-kind and a pair) flush (five cards of the same suit) straight (five cards with consecutive ranks) three-of-a-kind (three cards of the same rank) two pairs pair (two cards of the same rank) high card (any other hand) Actions to be taken if the user enters an illegal card or tries to enter the same card twice: Ignore the card Issue an error message Request another card Entering the number 0 instead of a card will cause the program to terminate. The program has three task: Read a hand of five cards (read_cards): will store information about the hand into several arguments. Analyze the hand for pairs, straights, and so forth (analyze_hand): examine arguments, storing its findings into external variables. Print the classification of the hand (print_result) main calls these functions inside an endless loop. The functions will need to share a fairly large communicate through num_in_rank and num_in_suit local variables. How should we represent the hand of cards? analyze_hand will need to know how many cards are in each rank and each suit. This suggests that we use two arrays, num_in_rank and num_in_suit. num_in_rank[r] will be the number of cards with rank r. num_in_suit[s] will be the number of cards with suit s. We'll encode ranks as numbers between 0 and 12 . Suits will be numbers between 0 and 3 . We'll also need a third array, card_exists, so that read_cards can detect duplicate cards. Each time read_cards reads a card with rank r and suit s, it checks whether the value of card_exists[r][s] is true. If so, the card was previously entered. If not, reod_cards assigns true to card_exists(r)/s]. Both the read_cards function and the analyze_hand function will need access to the num_in_rank and num_in_suit arrays, so they will be parameters of the functions. The card_exists array is used only by read_cards, so it can be local to that function. As a rule, variables should be made external only if necessary

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions