This lab requires you to design and implement a C++ program to simulate a game o
ID: 3639812 • Letter: T
Question
This lab requires you to design and implement a C++ program to simulate a game of Blackjack between two to four players. Your program must incorporate a two-dimensional array to represent the suit and the value of each card dealt to a player, keep track of which cards have been dealt to which player, and use a random-number generator to pick each card to be dealt to a player.//Description: the program will use a 2D array and a random-number
//generation to play Blackjack and keep track of a playing-card deck.
//Input: User data entry and a playing-card deck represented as a two-
//dimensional array
//Output: A screen display showing the current card hands of each player
// and the dealer, their score, win and lose status, and a final representation
// of the card deck after the game is over
#include <iostream>
#include <iomanip>
#include <windows.h>
using namespace std;
void main (void)
{
bool bPlayerDraw[5]; //Boolean to determine if player holds (F)
//or draws card (T)
char cPlay = 'N'; //Character variable for play game input
char cCardDeck[4][13]; //Character array representing the card deck
int iCard; //Card array index
//0 = 2 card
//1 = 3 card
//2 = 4 card
//3 = 5 card
//4 = 6 card
//5 = 7 card
//6 = 8 card
//7 = 9 card
//8 = 10 card
//9 = jack card
//10 = queen card
//11 = king card
//12 = ace card
int iNumberOfDraws = 0; //Number of rounds of card draws
int iSuit; //Suit array index
//0 = diamonds
//1 = hearts
//2 = clubs
//3 = spades
// ASCII character display reference for display card suit symbols
//3 = heart symbol
//4 = diamond symbol
//5 = club symbol
//6 = spade symbol
int iNumberOfPlayers = 0;//Number of players in current game
int iPlayerCount[5]; //Integer array to holder each player's count
//iPlayer[0] is always the dealer
int iHighestCount = 0; //Highest count for a single game
int k, m; //integer loop counters
srand(GetTickCount()); //Seed the random-number generator
//Main game loop
//Enter your code here…
Here is a sample of the finished program’s output.
Welcome to Honest Sam's Blackjack Table
Glad to have you back!
Enter the number of players in the game.
There must be at least one player but no more than four.
Number of players: 3
Dealer Player 1 Player 2 Player 3
Card 1: 5? 7? 4? Q?
Card 2: 5? K? 5? 2?
Card 3: J? 4? 6? 10?
Card 4: Hold Hold Q? Hold
Card 5: Hold Hold Hold Hold
Final: 20 21 25 22
Lose Win! Lose Lose
Display entire card deck, rows = suits, columns = card
0 = dealer card, 1 = Player 1 card, 2 = Player 2 card, etc.
2 3 4 5 6 7 8 9 10 J Q K A
? 2 2 3 0 3 1
?
? 0 2 2
? 3 1 0 1
Welcome to Honest Sam's Blackjack Table
Do you feel lucky today?
Do you think you should take what you have left and go home?
Press Y or y to play or any other key to exit the game.
STEP 3: Program Specifications
1. There is always a dealer in the game.
a. At the start of the game, the dealer’s first card will not be shown or displayed. The second card will be displayed.
b. The dealer may draw additional cards.
c. The dealer must use a random-number generator to determine the maximum number of cards the dealer will draw--a value between 0 and 3. In other words, the dealer is a computer player.
d. The dealer does not show all the cards or the total until all the players have either gone bust (over 21) or hold (no more cards drawn).
2. There must be at least one other player (you) and up to a maximum of four other players (all played by you).
. On a player’s turn, that player may either draw a card or hold. Once a player holds, he or she should not be asked to draw another card during this game.
a. All the cards for each player, including the first card dealt, are displayed, along with the suit symbol: spades ?, clubs ?, hearts ?, or diamonds ?.
3. Each game will start with a new, 52-card deck, which is modeled on a real deck of cards.
. The card deck has 52 cards with no jokers.
a. The card deck is represented by a two-dimensional array of data-type character, where the first dimension represents the suit and the second dimension represents the card in the suit, such as the following.
i. char CardDeck[4][13];
b. At the start of each game, each element of the two-dimensional array is initialized to a value of " ", or the "space" character.
c. The deck has four suits, represented by the following dimension indices.
. 0 = diamonds
i. 1 = hearts
ii. 2 = clubs
iii. 3 = spades
d. Each suit has 13 cards: 2, 3, 4, 5, 6, 7, 8,9 ,10, jack, queen, king, and ace.
e. Each card in a suit is represented by the following dimension indices.
. 0 = the 2 card
i. 1 = the 3 card
ii. 2 = the 4 card
iii. 3 = the 5 card
iv. 4 = the 6 card
v. 5 = the 7 card
vi. 6 = the 8 card
vii. 7 = the 9 card
viii. 8 = the 10 card
ix. 9 = the jack
x. 10 = the queen
xi. 11 = the king
xii. 12 = the ace
f. All the number cards are worth their face value (i.e., a 3 of diamonds is worth 3).
g. All face cards are worth 10.
h. An ace is worth either 1 or 11. Your final-score calculation must be able to handle this correctly for both the dealer and each player.
i. A random-number generator must be used to select the suit and the card in the suit.
. Once a card and suit are selected, the program should check if the value of that array element is a "space."
1. If the array element = "space," set the element equal to an integer, identifying the dealer or the player.
a. 0 = dealer
b. 1 = player 1
c. 2 = player 2
d. 3 = player 3
e. 4 = player 4
2. If the array element ! = "space," then the random-number and card-checking process should repeat until a "card" or an array element is selected that is = "space."
j. Once a card is drawn during a game, it cannot be drawn again.
4. When the program first starts, it should prompt the user, asking if he or she wants to play a game of Blackjack or exit the program.
5. If the user inputs to play the game, the next decision should be 1, 2, 3, or 4 players.
6. At the start of the game, the dealer and each player should be dealt two cards. One of the dealer’s card's value and suit should not be displayed.
7. The number of cards that the dealer will draw during a game should be determined by a random-number generator that will return a value of 0, 1, 2, or 3 cards to be drawn.
8. Each player may then draw a card or hold.
9. If, after drawing a card, any player or the dealer goes over a score of 21, he or she is not allowed to draw any more cards during the game.
10. Once a player holds, he or she should not be asked to draw a card again during the game.
11. The game continues until one of the following conditions occur:
. all players have declared hold;
a. all players and the dealer have gone over 21;
b. a maximum of five cards total are held by any player at the end of a round of card draws; or
c. any combination of the above.
12. The display should show each player’s (and the dealer’s) hand and update the display after each round of card draws.
spades ?, clubs ?, hearts ?, and diamonds ?
Example
Card 1 Card 2 Card 3 Card 4 Card 5
Dealer: ? 10?
Player 1: A? 2?
Player 2: J? Q?
Player 3: 3? 8?
13. At the end of a game, the display should be repeated, with the addition of win or lose and an updated balance.
Example
Card 1 Card 2 Card 3 Card 4 Card 5 Total Stats
Dealer: J? 10? 20 Lose
Player 1: K? 2? 5? 1? 5? 23 Lose
Player 2: J? Q? 20 Lose
Player 3: 3? 8? K? 21 Win!
14. The program should then ask each player if he or she wants to play again or leave the game.
15. The game continues with a new round, as long as there is one player remaining.
16. If there are no remaining players, the program should exit.
Explanation / Answer
#include #include #include using namespace std; //prototypes... void play21(void); int dealCards(int, string); void hit(int &); void determineWinner(int, int); int Random(int, int); void main(){ char keepPlaying = 'n'; //loop control variable do { play21(); //keep playing? cout > keepPlaying; } while(keepPlaying == 'Y' || keepPlaying == 'y'); } void play21(void){ //play one hand of 21 //randomize the cards srand((int) time(0)); // deal the cards int person = dealCards(2, "Your Cards:"); coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.