This lab requires you to design and implement a C++ program to simulate a game o
ID: 1811773 • 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.
Summary: Write a statement summarizing your predicted and actual output; identify and explain any differences.
Conclusions: Write at least one nontrivial paragraph that explains, in detail, either a significant problem you had and how you solved it or, if you had no significant problems, something you learned by doing the exercise.
Each lab exercise should have a separate section in the lab-report document.
Your lab grade will be based upon
STEP 1: Starting Visual Studio
Create a new Visual Studio empty project, and add one C++ source code file.
STEP 2: Coding
Enter the following source, which will set up the 2D array and the recommended variable declarations. It is up to the student to design and implement the remainder of the program code.
// Programmer: (put your name here)
// Course: COMP220
// Assignment: Two-Dimensional Arrays
// 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…
do
{ //Intro banner
cout << "Welcome to Black Jack Table" << endl << endl;
cout << "Press Y or y to play or any other key to exit game: ";
cin >> cPlay;
if(cPlay != 'Y' && cPlay != 'y')
{
system("cls");
cout << "Sorry to see you go, better luck next time!";
cout << endl << endl;
system("pause");
exit(0);
}
//Initialize the card
deck to all spaces (nested loop)
//Clear all player scores from previous game
//Reset draw to true also //Clear number of card draw rounds and the winning count
//single loop that sets iPlayer[k] to 0 and bPlayerDraw[k] = true
iNumberOfDraws = 0;
iHighestCount = 0;
system("cls");
cout << "Welcom to Black Jack Table" << endl << endl;
cout << "Glad to have you back!";
do
{
cout << endl << endl;
cout << "Enter the number of players in the game." << endl;
cout << "There must be at least one player, but no more than 4." << endl;
cout << "Number of players: ";
cin >> iNumberOfPlayers;
}
while(iNumberOfPlayers < 1 || iNumberOfPlayers > 4);
//Display Dealer and Player # header for card output display
for(k = 0; k < iNumberOfPlayers; k++)
cout << "Player " << k+1;
while(iNumberOfDraws < 5)
{ iNumberOfDraws++;
cout << endl << "card " << iNumberOfDraws << ": ";
//Loop for card drawing, player hold, card display and count totals
for(k = 0; k < iNumberOfPlayers + 1; k++)
{
do
{
}
while(cCardDeck[iSuit][iCard] != ' ')
if(bPlayerDraw[k] == true)
{
}
else
cout << " Hold";
}
}
//Output final count
cout << endl << endl << "Final: ";
// loop
//Find highest winning
count
// LoOP WITH IF
//Output whether dealer and players won or lost
for(k = 0; k < iNumberOfPlayers + 1; k++)
cout << endl << endl << " ";
for(k = 0; k < 13; k++)
{
}
for(k = 0; k < 4; k++)
{
cout << setw(3) << char(k+3);
for(m = 0; m < 13; m++)
{
cout << setw(3) << cCardDeck[k][m];
}
cout << endl;
}
cout << endl << endl;
}
while(1);
}
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.
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
spades ♠, clubs ♣, hearts ♥, and diamonds ♦
Example
Player 1:
Example
Also it states that they want a sourcefile for notepad can you explain what they want , also were it says add your ENTER YOUR CODE HERE what part of your code do i enter there . Thanks
DeliverablesExplanation / 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
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.