Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c code for this program, please explain Program : Classifying a Poker Hand (poker.c) Definition: The program classifies a poker hand. Each card in the

image text in transcribedimage text in transcribed

image text in transcribed

c code for this program, please explain
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: cdhs 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 tasks: >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, read_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. Expected output: Enter a card: 2s Enter a card: 5s Enter a card: 4s Enter a card: 3s Enter a card: 6s Straight flush Enter a card: 8c Enter a card: as Enter a card: 8c Duplicate card; ignored. Enter a card: 7c Enter a card: ad Enter a card: 3h Pair Enter a card: 6s Enter a card: d2 Bad card; ignored. Enter a card: 2d Enter a card: 9c Enter a card: 4h Enter a card: ts High card Enter a card: 0

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

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago