Question: EDIT: the prompt is: Write a program that reads HAND_SIZE cards from the user, then analyzes the cards and prints out the type of poker

EDIT: the prompt is: Write a program that reads HAND_SIZE cards from the user, then analyzes the cards and prints out the type of poker hand that they represent. (HAND_SIZE will be a global constant, typically 5, but your program must still work if it is set to something other than 5.) I've seen a few answer to these but theres a heavy emphasis on the fact that straights need to work in either order that the others don't address.EDIT: the prompt is: Write a program that reads HAND_SIZE cards from

3:30 00 W Qe77% For Credit Assignment 4.1 (50 points] Write a program that reads HAND_SIZE cards from the user, then analyzes the cards and prints out the type of poker hand that they represent. (HAND_SIZE will be a global constant, typically 5, but your program must still work if it is set to something other than 5.) Poker hands are categorized according to the following hand-types: Straight flush, four of a kind, full house, straight, flush, three of a kind, two pairs, pair, high card To simplify the program we will ignore card suits, and face cards. The values that the user inputs will be integer values from LOWEST_NUM to HIGHEST_NUM. (These will be global constants. We'll use LOWEST_NUM = 2 and HIGHEST_NUM = 9, but your program must work if these are set to something different.) When your program runs it should start by collecting HAND_SIZE integer values from the user and placing the integers into an array that has HAND_SIZE elements. It might look like this: (This is a pair, since there are two eights) No input validation is required for this assignment. You can assume that the user will always enter valid data (numbers between LOWEST_NUM and HIGHEST_NUM). Since we are ignoring card suits there won't be any flushes. Your program should be able to recognize the following hand categories, listed from least valuable to most valuable: bool contains ThreeOfKind const int handt) Entor 5 numeric cards, no face cards. Use 2. 9. Card 1 Card 2 Card 4 2 Hand Type Description Example High Card There are no matching cards, and the hand is not a straight 2.5,3,7 Pair Two of the cards are identical 2.5,3,5 Two Par Two different pairs 2.5,3,53 Three of a kind Three matching cards 5.5,3, 57 Straight 5 consecutive cards 3,5,6,4 Full House A pair and three of a kind 5,7,5,7 Four of a kind Four matching cards 2.5,5,5,5 Enter 5 numeric cards, no face cards. Use 2 - 9. Cara Sard Card 31 Two Pair Enter 5 numeric cards, no face cards. Use 2.9. Card 2 Card 3: 4 Card 4 Straight Enter. 5 numeric cards, no face cards. Use 2.9. bool containsTwoPair const int handt) bool contains Straight (const int hool contains FullHouse(const int handt) boo contains FourOfakind(const int hand[ ] A note on straights: a hand is a straight regardless of the order. So the values 3,4,5,6,7 represent a straight, but so do the values 7, 4, 5, 6, 3. Also, a straight requires just 5 consecutive cards, even if HAND_SIZE is larger than 5. Your program should read in HAND_SIZE values and then print out the appropriate hand-type. If a hand matches more than one description, the program should print out the most valuable hand type. Here are three sample runs of the program: Card High cara Additional Requirements 1) You must write a function for each hand type. Each function must accept a const int array that contains HAND_SIZE integers, each representing one of the HAND_SIZE cards in the hand, and must return "true" if the hand contains the cards indicated by the name of the function, "false" if it does not. The functions must have the following signatures. bool containsPair(const int hand[3) Important! In the descriptions below, a pair is defined as exactly two of the same card. If there are more than two of the same card, that is not a pair. Similarly, a three-of-a-kind is defined as exactly three of the same card. If there are more than three of the same card, that is not a three-of-a-kind. However! Since there is no such hand as five-of-a-kind or more, four-of-a- kind must return true if there are four or more of the same card. Il post: returns true if and only if there are one or more pairs in the hand. Note that 17 this function return false if there are more than two of the same card (and no other pairs). bool containsPair(const int hand]): // post returns true if and only if there are two or more pairs in the hand. bool containsTwoPair (const int handli> 11 post: returns true if and only if there are one or more three-of-a-kinds in the hand. bool contains ThreeOfKind(const int hand(1) !! post: returns true if there are 5 consecutive cards in the hand bool contains Straight(const int hand[]) // post: returns true if there is a pair and a three-of-a-kind in the hand bool contains Full House(const int hand) // post: returns true if there is a four-of-a-kind in the hand bool contains Four ofakind(const int hand[ 1) Some examples: A hand that contains three-of-a-kind and two other different cards (for example, 1, 1, 1, 2, 3) should return "false" for "containsPair)" A hand that contains four-of-a-kind should return "false" for "contains Pair()" and "contains ThreeOfKind" A hand that contains a full-house should return "true" for contains ThreeOfKind() and containsPair). A hand that contains two-pair should return "true" for containsPair). Here is a table with some examples that I hope will help clear up any confusion. If there are additional hands that you are unsure about, please ask in the discussion, and I will consider adding rows to this table for further clarification hand 2.2.2.2.4 pair? two pair? three of a kind? full house? four-of-a-kind? straight? F 1 F 2.3.3.3.3 F F F F T F 2.2.3.3.3 T F T F F T F F 2.2.2.3.4 T 2.2.2.3.3.3 F 9.2.4 3.6.5 F T F F F F F F 2) You do not need to write a contains HighCard function. All hands contain a highest card. If you determine that a particular hand is not one of the better hand types, then you know that it is a High Card hand. 3) Do not sort the cards in the hand. Also, do not make a copy of the hand and then sort that. 4) An important objective of this assignment is to have you practice creating excellent decomposition. Don't worry about efficiency on this assignment. Focus on excellent decomposition, which results in readable code. This is one of those programs where you can rush and get it done but end up with code that is really difficult to read, debug, modify, and re-use. If you think about it hard, you can think of really helpful ways in which to combine the tasks that the various functions are performing. 5 extra credit points on this assignment will be awarded based on the following criteria: no function may have nested loops in it. If you need nested loops, the inner loop must be turned into a separate function, hopefully in a way that makes sense and so that the separate function is general enough to be re-used by the other functions. Also, no function other than main() may have more than 5 lines of code. (This is counting declarations, but not counting the function header, blank lines, or lines that have only a curly brace on them.) In my solution ! was able to create just 3 helper functions, 2 of which are used repeatedly by the various functions. These additional criteria are intended as an extra challenge and may be difficult for many of you. If you can't figure it out, give it your best shot, but don't be too discouraged. It's just 5 points. And be sure to study the posted solution carefully. 3:30 00 W Qe77% For Credit Assignment 4.1 (50 points] Write a program that reads HAND_SIZE cards from the user, then analyzes the cards and prints out the type of poker hand that they represent. (HAND_SIZE will be a global constant, typically 5, but your program must still work if it is set to something other than 5.) Poker hands are categorized according to the following hand-types: Straight flush, four of a kind, full house, straight, flush, three of a kind, two pairs, pair, high card To simplify the program we will ignore card suits, and face cards. The values that the user inputs will be integer values from LOWEST_NUM to HIGHEST_NUM. (These will be global constants. We'll use LOWEST_NUM = 2 and HIGHEST_NUM = 9, but your program must work if these are set to something different.) When your program runs it should start by collecting HAND_SIZE integer values from the user and placing the integers into an array that has HAND_SIZE elements. It might look like this: (This is a pair, since there are two eights) No input validation is required for this assignment. You can assume that the user will always enter valid data (numbers between LOWEST_NUM and HIGHEST_NUM). Since we are ignoring card suits there won't be any flushes. Your program should be able to recognize the following hand categories, listed from least valuable to most valuable: bool contains ThreeOfKind const int handt) Entor 5 numeric cards, no face cards. Use 2. 9. Card 1 Card 2 Card 4 2 Hand Type Description Example High Card There are no matching cards, and the hand is not a straight 2.5,3,7 Pair Two of the cards are identical 2.5,3,5 Two Par Two different pairs 2.5,3,53 Three of a kind Three matching cards 5.5,3, 57 Straight 5 consecutive cards 3,5,6,4 Full House A pair and three of a kind 5,7,5,7 Four of a kind Four matching cards 2.5,5,5,5 Enter 5 numeric cards, no face cards. Use 2 - 9. Cara Sard Card 31 Two Pair Enter 5 numeric cards, no face cards. Use 2.9. Card 2 Card 3: 4 Card 4 Straight Enter. 5 numeric cards, no face cards. Use 2.9. bool containsTwoPair const int handt) bool contains Straight (const int hool contains FullHouse(const int handt) boo contains FourOfakind(const int hand[ ] A note on straights: a hand is a straight regardless of the order. So the values 3,4,5,6,7 represent a straight, but so do the values 7, 4, 5, 6, 3. Also, a straight requires just 5 consecutive cards, even if HAND_SIZE is larger than 5. Your program should read in HAND_SIZE values and then print out the appropriate hand-type. If a hand matches more than one description, the program should print out the most valuable hand type. Here are three sample runs of the program: Card High cara Additional Requirements 1) You must write a function for each hand type. Each function must accept a const int array that contains HAND_SIZE integers, each representing one of the HAND_SIZE cards in the hand, and must return "true" if the hand contains the cards indicated by the name of the function, "false" if it does not. The functions must have the following signatures. bool containsPair(const int hand[3) Important! In the descriptions below, a pair is defined as exactly two of the same card. If there are more than two of the same card, that is not a pair. Similarly, a three-of-a-kind is defined as exactly three of the same card. If there are more than three of the same card, that is not a three-of-a-kind. However! Since there is no such hand as five-of-a-kind or more, four-of-a- kind must return true if there are four or more of the same card. Il post: returns true if and only if there are one or more pairs in the hand. Note that 17 this function return false if there are more than two of the same card (and no other pairs). bool containsPair(const int hand]): // post returns true if and only if there are two or more pairs in the hand. bool containsTwoPair (const int handli> 11 post: returns true if and only if there are one or more three-of-a-kinds in the hand. bool contains ThreeOfKind(const int hand(1) !! post: returns true if there are 5 consecutive cards in the hand bool contains Straight(const int hand[]) // post: returns true if there is a pair and a three-of-a-kind in the hand bool contains Full House(const int hand) // post: returns true if there is a four-of-a-kind in the hand bool contains Four ofakind(const int hand[ 1) Some examples: A hand that contains three-of-a-kind and two other different cards (for example, 1, 1, 1, 2, 3) should return "false" for "containsPair)" A hand that contains four-of-a-kind should return "false" for "contains Pair()" and "contains ThreeOfKind" A hand that contains a full-house should return "true" for contains ThreeOfKind() and containsPair). A hand that contains two-pair should return "true" for containsPair). Here is a table with some examples that I hope will help clear up any confusion. If there are additional hands that you are unsure about, please ask in the discussion, and I will consider adding rows to this table for further clarification hand 2.2.2.2.4 pair? two pair? three of a kind? full house? four-of-a-kind? straight? F 1 F 2.3.3.3.3 F F F F T F 2.2.3.3.3 T F T F F T F F 2.2.2.3.4 T 2.2.2.3.3.3 F 9.2.4 3.6.5 F T F F F F F F 2) You do not need to write a contains HighCard function. All hands contain a highest card. If you determine that a particular hand is not one of the better hand types, then you know that it is a High Card hand. 3) Do not sort the cards in the hand. Also, do not make a copy of the hand and then sort that. 4) An important objective of this assignment is to have you practice creating excellent decomposition. Don't worry about efficiency on this assignment. Focus on excellent decomposition, which results in readable code. This is one of those programs where you can rush and get it done but end up with code that is really difficult to read, debug, modify, and re-use. If you think about it hard, you can think of really helpful ways in which to combine the tasks that the various functions are performing. 5 extra credit points on this assignment will be awarded based on the following criteria: no function may have nested loops in it. If you need nested loops, the inner loop must be turned into a separate function, hopefully in a way that makes sense and so that the separate function is general enough to be re-used by the other functions. Also, no function other than main() may have more than 5 lines of code. (This is counting declarations, but not counting the function header, blank lines, or lines that have only a curly brace on them.) In my solution ! was able to create just 3 helper functions, 2 of which are used repeatedly by the various functions. These additional criteria are intended as an extra challenge and may be difficult for many of you. If you can't figure it out, give it your best shot, but don't be too discouraged. It's just 5 points. And be sure to study the posted solution carefully

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!