Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Blackjack game C++ source code welcome the user, and show them their starting cash amount. Display a menu. 1) Play a hand 2) Show current

Blackjack game C++ source code

welcome the user, and show them their starting cash amount.

  • Display a menu.
  • 1) Play a hand
  • 2) Show current cash balance
  • 3) Exit
  • cashvariable (short data type), and initialize it to 100 (i.e., give it an initial value of 100).
  • Display welcome message.
  • Display starting cash amount.

setsuitto a random number from 3 to 6. ASCII values 3 to 6 represent the heart, diamond, clubs, and spade characters.

  • Create a random number from 2 to 14, and then setfaceandvalueto appropriate values based on the random number that was generated.
  • 2 to 9 generated: Set face to the number character (add 48 and then typecast to a character), and set value to the number.
  • 10 generated: Set face toTand the value to 10.
  • 11 generated: Set face toJand the value to 10.
  • 12 generated: Set face toQand the value to 10.
  • 13 generated: Set face toKand the value to 10.
  • 14 generated: Set face toAand the value to 11.
  • In the public section of the header file, create a toString( ) prototype. In the implementation file, code the method to return the suit and face combined into one string
  • Create a showCards( ) method that receives a vector that holds Card objects and then shows the cards on one line.
  • Create a prototype for the method above the main method and below the includes section.
  • string showCards( vector cards );
  • Below the main method, create the showCards( ) method that loops through each card and returns a single string with the values. Here is the code to show you how the vector works.
  • /// Show the cards in the vector
  • string showCards( vector cards )
  • {
  • string output = "";
  • for each ( Card c in cards )
  • {
  • output += c.toString( ) + " ";
  • }
  • return output;
  • }

create the playHand( ) method. This method should accept the cash variable as a parameter. The cash variable needs to change in the playHand( ) method. When the player wins, we give the player more cash. When the player loses, we take cash away from the player.

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

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions