Functions and Recursions – Strings – Problem #5
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Consider a standard deck of cards containing 52 playing cards divided into four sets of spades, heart, diamond and clubs, with each set containing 13 cards, nine number cards with the num- bers ‘2’ to ‘10 printed on them and four letter cards with the letters ‘A (Ace)’, ‘J (ack)’, ‘K (King)’ and ‘Q (Queen)’ printed on them. Now for simplicity, consider the number card ‘10’ removed from each set, so each set now contains 12 cards in total. Three siblings Alice, Bob, Sarah play a game, where five cards are randomly picked from the deck of cards and given to one of them. In the same manner, five cards are given to each of the remaining two players. The player with the highest sum of the cards wins the game. The cards J (Jack), K (King), Q (Queen), A (Ace) have values of 11, 12, 13 and 1 respectively. For winning the game, only the sum of the card values matter, their corresponding set does not matter. Write a C program following the below points to play this game. (a) Write a C function int counting cards(char arr[ ]) that computes the sum of the cards of a player as per the character array passed as argument. (b) Take three character arrays (char Alice[5], char Bob[5], and char Sarah[5]) to take the cards distributed to each sibling and find the winner. Your input should be either from ‘2’ to ‘9’ (as characters, not int) for denoting the number cards (note that card number ‘10’ has been removed) or ‘A’, ‘J’, ‘K’ and ‘Q’ for the four letter cards, for each of the three siblings. You must call int counting cards(char arr[]) from main() for each of the three siblings, determine the winner and display the winner in main() itself. In case there is a tie among sum values for any two or all of the siblings, simply print ‘game tied’. [30] Example 1: Input: Alice: AJ23K Bob: 234Q8 Sharah: 12678 Output: Alice total: 29 Bob total: 30 Sarah total: 24 Bob wins!