(Solved) : Grab Bag Grab Bag Simple Data Structure Created Either Array Linked Structure Going Opt Li Q37256334 . . .
Grab Bag:
The Grab-Bag is a simple data structure that can be createdeither with an array or a linked structure (We are going to opt forthe linked structure). The GrabBag has two major functions:
add things to the bag
remove things RANDOMLY from the bag
Specifications:
Bag (65% specification)
You are to implement a Grab-Bag data structure in C/C++. You maychoose to use either language as your code base.
You will create several structs to accomplish this:
Card Struct
o Suit
o Value
BagNode
o Card* card
o BagNode* next
You will maintain any and all necessary pointers to create andmaintain the bag. This should be similar to a linked-list inapproach. A head pointer and possibly a tail pointer are goodideas.
You will also implement several functions to create thefunctionality of the bag:
getCurrentSize():int – item count of bag
isEmpty():bool/int – is the bag empty or not
add() – Add the item to the bag
o Hint – think about which add function you want to use from thelinked list
o Hint – Remember we remove randomly … so … do we need any fancyinsertion?
grab():Card – get a card out of the bag!
o Remember this is random
Hint – arbitrary remove
Hint – don’t forget your cases
getFrequencyOf():int – get a count of how many of an item isin the bag
empty() – empty the bag
fillWithCards() – fill the bag with a new deck of 52!
I have not outlined perfectly every function that you may needor write. The above functions are REQUIRED though. You mayimplement any needed functions to help or perform other tasks. Alsonote that I don’t have the parameters perfectly laid out for you.You will have to pass pointers around to make these functionswork.
If you are using C – remember you don’t have Pass-By-Reference,so make sure you return that Head pointer or otherwise deal withthat problem. If you are using C++ – remember you DO havePass-By-Reference, use that to your advantage.
Hi-Low-Guess Game:
Your goal is to create a simple “Hi-Low-Guess” game for theplayer to play. The computer will act as the dealer and the playerwill be given 3 options: the next card will be higher, the nextcard will be lower, guess the next card.
If the player guesses higher or lower and they are correct theyget a point. If they guess a specific card, they get 5 points! Ifthe card is equal value, the player neither wins or loses and isawarded 0 points and is prompted to guess again.
Each time the player is offered a guess they should beshown:
All the cards that have been drawn so far
The last card drawn that you’re guessing against
The probability the next card will be higher
The probability the next card will be lower
The probability of drawing a specific value
OTHER REQUIREMENTS:
The player will keep guessing until they get their guesswrong
You should re-populate the deck after the deck has been 2/3rdsused
o Leave the last card drawn out though
o Make sure you tell the player that the deck was re-filled
Count Aces as low (value 1)
Notes:
The bag is the deck. Since you pick stuff out of the bagrandomly, you don’t have to shuffle it
You should use H, D, S and C for Hearts, Diamonds, Spades andClubs
You should use numerical values 1 – 13 for card values Makea printCard function that “pretty prints” your card for you
While there are explicitly required functions for the high-lowgame – YOU ARE EXPECTED TO WRITE APPROPRIATE FUNCTIONS
The player can play as long as they keep guessing correctly.Don’t forget to refill the bag after 34 cards have been drawn.Don’t forget to tell your user that you are doing so.
Sample Output:
Cards drawn:
[K-H] [4-S] [7-D] Cards left in deck: 49
Probability of next card being higher: 46.94%
Probability of next card being lower: 46.94%%
Probability of next card being the same: 6.12%
Probability of next card being:
A 8.16%
2 8.16%
3 8.16%
4 6.12%
5 8.16%
6 8.16%
7 6.12% 8
8.16%
9 8.16%
10 8.16%
J 8.16%
Q 8.16%
K 6.12%
Last card: [7-D]
Points: 2
Choose option:
1 – Next card will be higher
2 – Next card will be lower
3 – Guess exact value
Use Cases:
If the user selects 1 or 2, draw the next card.
o Award a point if the user guessed right and prompt them fortheir next guess showing all the above information.
o If the user guesses wrong. It’s game over. Tell them “GAMEOVER” and show them their score. Exit the game.
o If the card is the same value as the previous card, then tellthe user “Same card” and give them 0 points and prompt them fortheir next guess showing all the above information.
If the user uses option 3:
o Prompt the user for the value they want to guess.
o Draw the next card. o If the value matches, then give the user5 points and prompt them for their next guess showing all the aboveinformation.
o If the value doesn’t match, it’s game over. Tell them “GAMEOVER” and show them their score. Exit the game.
****************************************************************************************************************************************************************************************
Please code this for me and use comments to show what you’redoing!
Expert Answer
Answer to Grab Bag: The Grab-Bag is a simple data structure that can be created either with an array or a linked structure (We are…
OR