akosiraff

Download DeckOfCards C++ Answer

Oct 31st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.74 KB | None | 0 0
  1.  
  2. Download: https://solutionzip.com/downloads/deckofcards/
  3. SCIT
  4. School of Computing and Information Technology
  5. Faculty of Engineering & Information Sciences
  6. CSCI124 – Applied Programming – July 2017 Session
  7. Assignment 2 (80 marks)
  8. 1. Due: TBA
  9. 2. Daily penalty: minus 20% per day (maximum 3 days)
  10. 3. Please zip all your program files in a folder called “YourName_A2” and submit
  11. via the Moodle system
  12. 4. All file names given in this assignment MUST be respected
  13. 5. Please write down your names in EVERY file submitted
  14. 6. This assignment is worth 12% of the total marks of this subject.
  15. Background
  16. To become familiar with program designs dealing with
  17. – Applications on arrays using pointer arithmetic.
  18. – The use of void* for generic design
  19. – Sorting and searching
  20. – Dynamic allocations
  21. Problem
  22. A deck of cards may be used for playing a variety of card games, with varying elements
  23. of skill and chance, some of which are played for money. No matter what sort of card
  24. games, the basic principle is always the same, shuffle the cards, distribute the cards and
  25. arrange for the cards. These are the objective of this assignment.
  26. The following shows a sample of familiar playing cards used by most of the people:
  27. 2
  28. Different countries may have different naming of card values. For example, the French
  29. people name the Jack, Queen and King as Valet, Dame and Roi
  30. respectively.
  31. They call the suits Spades, Hearts, Diamonds and Clubs as Pigues,
  32. Coeurs, Carreaux and Trèfles respectively. If you wish to hear my Singapore
  33. accent of French pronunciation of these 4 words, feel free to see me ?
  34. When you buy a pack of playing cards, you always see that they are arranged in order;
  35. firstly the cards are arranged based on the colors and among the colors, they are arrange
  36. based on the card values (we usually call them the ranks of the cards).
  37. After shuffling the cards, you then distribute the cards to the players. Each player
  38. usually
  39. holds the same number of cards depending on the game. We usually call it a hand (of
  40. cards). When players receive the cards, they usually like to re-arrange the cards in order,
  41. firstly by colors and then by rank.
  42. For example, the bridge game has 4 players, and each player has 13 cards. Here are the
  43. arrangements of cards of the players:
  44. 3
  45. Everyone has his (her) way of arranging the cards, this is less important to this
  46. assignment as long as you fix your way of arranging.
  47. Let us now illustrate what you have to do for this Assignment. In order to cater for the
  48. need of various conventions of naming the cards by different countries, we propose the
  49. following structure definition of a playing card:
  50. struct Card
  51. {
  52. Char * color;
  53. RankType rank;
  54. };
  55. A deck of playing cards is an array of structure Card’s and it is not necessary 52 cards,;
  56. for example French Tarot card game has 78 cards!!
  57. Important to note
  58. You should treat the array of Card as Card*. All storages used for the arrays
  59. should be dynamically created; and delete them when they are no longer needed.
  60. When accessing to an element of the array, you should access it via a pointer, i.e. by
  61. dereferencing this pointer. Using the notation, for example cardArray [k] or
  62. *(cardArray + k) accessing to the k
  63. th element of the array cardArray is not
  64. allowed.
  65. The color is one of the following four C-strings (array of characters)
  66. 4
  67. “Club” “Diamond” “Heart” “Spade”
  68. and the rank is one of the following enumeration constant pointers:
  69. enum RankType {Two, Three, Four, Five, Six, Seven, Eight,
  70. Nine, Ten, Jack, Queen, King, Ace};
  71. You can alter the order of the enumeration constants in the above definitions but my
  72. illustrations of this assignment will base on the above order.
  73. As can be seen from the above definition of colors, based on the ASCII values
  74. “Club” < “Diamond” < “Heart” < “Spade” And the order of the constants in RankType is obvious in definition. A card should be printed together with the color symbols: ? - C ? - D ? - H ? - S and the ranks should be printed as 2 3 4 5 6 7 8 9 T J Q K A. For example Spade 10, should be printed as ST. We have all the definitions and declarations. Let us look at the details of each of the tasks. Task 1 – Shuffle of cards A deck of playing cards is stored in an array of Card structures. All the cards are distinct. A few functions which are important to deal with this task: - to get a playing card and all the cards should be randomly generated - to print a playing card - to insert a playing card into an array - to print a deck of playing cards - etc For example, after we have shuffled the playing cards, we can display them according to the following format, i.e. the 1st interaction when you execute your program: 5 According to the above interaction, you wish to have 4 hands of 10 cards each. 4 and 10 are input data. Task 2 – Distribute of cards Depending on the number of players who plays in a card game, we usually try to distribute the same number of cards to each player. For example, bridge game has 4 players and each player has 13 cards. The cards hold by each player is called a hand. Based on this definition, you can define Card ** someHands; You can interpret someHands is two-dimensional arrays, the 1st dimension (row index) stands for the number of hands and the 2nd dimension (column index) represents the number of cards for each hand. Alternatively, you can define an alias using the typedef definition, for example typedef Card * Hand; and use it to declare some hands, for example Hand *someHands; Using the deck of cards shuffled in Task 1, we can now distribute them. Let us look at the interactions and the displays: 6 We will look at some special cases when user enters the wrong information later. One important function for this task, obviously, is the distribution of card function and this function should receive as parameter the deck of cards shuffled in Task 1. Task 3 – Arrange of cards As can be seen from the distributed hands in Task 2, all the hands are not arranged in order. Almost all the players when they receive a hand of playing cards, they like to group the same colors together and among the colors, they also like to arrange them in rank order; and sometimes they also like to know the number of cards for each color. How to arrange an array of playing cards in order? You can assume that you are given an array which is already sorted. You now wish to insert a playing card in the sorted array. Two alternatives: - You can search starting from the 1st element of the sorted array and locate the right position to insert a playing card; or - You can also search starting from the last element of the sorted array and locate the right position to insert the playing card. Initially you can assume that the sorted array consists of only the 1st element of a hand of playing cards. You continually insert the 2nd element, the 3rd element and so on until the last element of the array of playing cards. The following screen shows some of the useful information after the arrangement: In the above screen, 2 – 4 – 1 – 3 means 2 cards in spades, 4 cards in hearts, 1 card in diamonds and 3 cards in clubs. The cards are arranged in decreasing order based on the 7 colors; and among the colors, the cards are arranged in decreasing order based on the ranks. Finally, the garbage collection!!! All the storages used for this application should be dynamically allocated. Before proceeding to next step, you should destroyed all storages used. Here is the interaction and display: Task 4 – To drive the whole application You now design a main function to drive the whole application. Let us look at the whole run of the system: (Replace SP by your own name for the ease of recording your assignment marks) As can be seen from the above interactions, the whole dealing system is repeated. The above screen shows one of the abnormal cases. 8 Another abnormal case: Final screen captured: You can see that if you ask for one hand of 52 cards, the deck of playing cards will be arranged all in order. IMPORATANT TO NOTES Put all the function prototypes with some descriptions to the prototypes in a header file called A2.h; its implementations are in A2.cpp and the main function is stored in the file called MainA2.cpp. Here is the summary of all the files you have to submit, zip them in a zip file called YourName_A2.zip: (1) A2.h (2) A2.cpp (3) MainA2.cpp (4) A cpp file called YourName_A2.cpp that you copy and paste in order of the files (1) to (3) for grading and plagiarism testing purpose. (5) A project file called YourName_A2 9 (6) Make a declaration saying something similar to “You did not pass your assignment to anyone in the class or copy anyone’s work; and you are willing to accept whatever penalty given to you and also to all the related parties involved”
  75.  
  76. Download: https://solutionzip.com/downloads/deckofcards/
Add Comment
Please, Sign In to add comment