Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C++ Create a Blackjack program with the following features: Single player game against the dealer. Numbered cards count as the number they represent (example:

Using C++

Create a Blackjack program with the following features:

  1. Single player game against the dealer.
  2. Numbered cards count as the number they represent (example: 2 of any suit counts as 2) except the Aces which can count as either 1 or 11, at the discretion of the player holding the card.
  3. Face cards count as 10.
  4. Player starts with $500.
  5. Player places bet before being dealt a card in a new game.
  6. New game: Deal 2 cards to each player with one up and one down each.
  7. If both the dealer and the player have 21, the result is a "Push" (meaning a tie). The game ends and the player's bet is returned to them.
  8. If the player or the dealer has 21, the game ends. The bet is added to their pot if they win and deducted from them if they lose.
  9. If neither has 21, it is the player's turn. They will continue to be offerred cards (to "Hit") to add to their total until they either exceed 21 or they choose to not take any more cards (to "Stand"). If they exceeded 21, the game ends, the player loses and their bet is deducted from their pot.
  10. If the player did not exceed 21, it is the dealer's turn. The dealer must continue to take cards until their sum is 17 or greater. At that point, they must "Stand" (not take any more cards).
  11. Whoever is closer to 21 wins and the bet is either added to or deducted from the player's pot as appropriate.
  12. After a game ends and money is distributed, the player is offerred another game - as long as they still have money in their pot.
  13. The game should have a nice, easy to understand interface.
  14. The code should be well documented and indented according to the specification discussed in class.
  15. Your program should be divided up into the following functions (which should be completely commented):
    1. playGame - plays a complete game of Blackjack
    2. getBet - prompts for and returns a valid bet by the player
    3. initialDeal - deals the first 2 cards to the players and determines if there was a winner - returns 0=dealer, 1=player, 2=push, 3=no winner yet.
    4. playerTurn - handles the player's turn - returns true if the player is still in the game or false if they busted.
    5. dealerTurn - handles the dealer's turn - returns true if the dealer is still in the game or false if they busted.
    6. deal - deals a single card into a given hand
    7. showHand - displays the names of the cards in the given hand - handles hidden cards
    8. totalHand - returns the (best) total for the cards in the given hand - handle aces here
    9. getCardName - given a card number, it returns the associated card name
    10. getCardSuit - given a card number, returns the associated card suit
    11. getCardValue - given a card number, returns the value of the card (1 for aces)
    12. checkHands - called with both hands, determines if the winner (0=dealer, 1=player, 2=push)
    13. initializeDeck - initialize the deck of cards
    14. shuffleDeck - shuffle the deck of cards

What to do:

  1. Completely describe the user interface that you plan to implement.
  2. Examine the functions above and start creating prototypes for each. Think about what data needs to be passed in and what the function will return.
  3. Start designing each function. Pay attention to where data is defined in each function. Make sure the data is defined at the level where it needs to be maintained.
  4. Add any other functions you need, but defines those outlined above.
  5. Complete your design by confirming to yourself that your design is solid by "running" it as we have on the board in class.
  6. Create a skeleton of your program using the prototypes to create function stubs.
  7. Write code for a function and test it thoroughly before moving on to another function.
  8. Repeat until the program is complete.

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

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

=+c. If there were six different covers rather than just four,

Answered: 1 week ago

Question

What makes Zipcar an attractive employer for which to work?

Answered: 1 week ago

Question

Evaluate Figure 6-9; what other questions would you ask, and why?

Answered: 1 week ago