Question: How can I take the code from 2 andmodify it to fit for #3?
( I need to do #3. I could use my code from 1 and 2 to dothat.)
Code for part 1 :
#include <iostream>
#include <cstdlib>
#include <ctime>
#define SUIT 4
#define CARDS 13
using namespace std;
// Gives a random integer given a modulus
unsigned int randomNumber(unsigned int modulus);
//shuffle the deck of cards
void shuffleCards(bool deckOfCards[][CARDS], unsigned intnumOfRows, unsigned int numOfCols);
//Deal a hand of five cards
void dealHand(bool deckOfCards[][CARDS], unsigned int numOfRows,unsigned int numOfCols);
//Shuffle & deal a hand of 5 cards
int main () {
//Create deck of cards
//4 rows and 13 columns represents suits and cards 1–card
//0–card dealt
bool deckOfCards[SUIT][CARDS];
//shuffle cards
for(int player=0; player<5; player++){
cout << “Player ” << (player + 1) <<“: n”;
shuffleCards(deckOfCards, SUIT, CARDS);
//Deal the hand
dealHand(deckOfCards, SUIT, CARDS);
}
//Pause system so we can view results
system(“PAUSE”);
return 0;
}//End of this
//RANDOM NUMBER FUNCTION
unsigned int randomNumber(unsigned int modulus){
//variable store random number
unsigned int randNum;
srand(time(NULL)); //seed random number function
randNum = (rand() % modulus); //Calculate random number
return randNum;
}
// SHUFFLE CARDS FUNCTION
void shuffleCards(bool deckOfCards[][CARDS], unsigned intnumOfRows, unsigned int numOfCols){
unsigned short counterRows; //variable for control of outer forloop
unsigned short counterCols; //variale to control inner forloop
for(counterRows = 0; counterRows < numOfRows;counterRows++){
for(counterCols = 0; counterCols < numOfCols;counterCols++){
deckOfCards[counterRows][counterCols] = 1;
}//end inner for
}//end outer for
}//end of function
//Deal a hand of five cards
void dealHand(bool deckOfCards[][CARDS], unsigned int numOfRows,unsigned int numOfCols){
//variable for loop countrol
unsigned short counter;
unsigned short suitNumber; //0 – 3 Hearts, Diamonds, Clubs,Spades
unsigned short cardNumber; //0 – 12, Cards Ace – King in ascendingorder
//Suit names
string cardSuit[SUIT] = {“Hearts”, “Diamonds”, “Clubs”,”Spades”};
//Card names
string cardNames[CARDS] = {“Ace of “, “Two of “, “Three of “,
“Four of “, “Five of “, “Six of “,
“Seven of “, “Eight of “, “Nine of “,
“Ten of “, “Jack of “, “Queen of “,
“King of “};
//For loop loops five times to generate five random cards
for(counter = 1; counter <= 5; counter++){
do{
//Get a random suit number and card number to display a randomcard
suitNumber = randomNumber(numOfRows);
cardNumber = randomNumber(numOfCols);
if(deckOfCards[suitNumber][cardNumber] == 1){
//Display the card
cout << cardNames[cardNumber] << cardSuit[suitNumber]<< endl;
}
}while(deckOfCards[suitNumber][cardNumber] == 0);
//set deckOfCards[][] to 0 to show card no longeravailable
deckOfCards[suitNumber][cardNumber] = 0;
}//end of for
}//end of function
Code for part 2:
#include <iostream>
#include <cstdlib>
#include <ctime>
#define SUIT 4
#define CARDS 13
using namespace std;
// Generates a random integer given a modulus
unsigned int randomNumber(unsigned int modulus); //RAND SUIT &CARD#
//shuffle the deck of cards by setting all entries to1
void shuffleCards(bool deckOfCards[][CARDS], unsigned intnumOfRows, unsigned int numOfCols); // SHUFFLING CARDS= CARDSBECOME AVAILABLE= RESETS TO 1
//Deal a hand of five cards
void dealHand(bool deckOfCards[][CARDS],int playerHands[][14],unsigned int numOfRows, unsigned int numOfCols); // DEAL ANDDISPLAY RESULT
void resetPlayerHands (int playerHands [][14]);
void displayHand (int playerHands [][14]);
//Shuffle and deal a hand of 5 cards
int main () {
//Create the deck of cards
//4 rows, 13 columns representing suits and cards. 1–card isthere,
//0–card is dealt
bool deckOfCards[SUIT][CARDS]; //
int playerHands[4][14];
//shuffle the cards
shuffleCards(deckOfCards, SUIT, CARDS);
//Deal the hand
dealHand(deckOfCards, playerHands, SUIT, CARDS);
displayHand(playerHands);
resetPlayerHands(playerHands);
cout << endl;
//Pause the system so we can view the results
system(“PAUSE”);
return 0;
}//End of main()
// RANDOM NUMBER FUNCTION
unsigned int randomNumber(unsigned int modulus){
//variable to store random number
unsigned int randNum;
srand(time(NULL)); //seed the random number function
randNum = (rand() % modulus); //Calculate random number
return randNum;
}
// SHUFFLE CARDS FUNCTION
void shuffleCards(bool deckOfCards[][CARDS], unsigned intnumOfRows, unsigned int numOfCols){
unsigned short counterRows; //variable for control of outer forloop
unsigned short counterCols; //variale to control inner forloop
for(counterRows = 0; counterRows < numOfRows; counterRows++){ //START AT ROW 0
for(counterCols = 0; counterCols < numOfCols; counterCols++){//SET COLUMN 0, STARTT, KEEP GOING TILL COLUMN COUNTER <13, NEEDTO PUT 1 IN COLUMN
deckOfCards[counterRows][counterCols] = 1;// NEED TO PUT 1 INCOLUMN
}//end inner for
}//end outer for
}//end of function
//Deal a hand of five cards
void dealHand(bool deckOfCards[][CARDS], int playerHands[][14],unsigned int numOfRows, unsigned int numOfCols){
//variable for loop countrol
unsigned short counter;
unsigned short suitNumber; //0 – 3 Hearts, Diamonds, Clubs,Spades
unsigned short cardNumber; //0 – 12, Cards Ace – King in ascendingorder
//Suit names
string cardSuit[SUIT] = {“Hearts”, “Diamonds”, “Clubs”,”Spades”};
//Card names
string cardNames[CARDS] = {“Ace of “, “Two of “, “Three of “,
“Four of “, “Five of “, “Six of “,
“Seven of “, “Eight of “, “Nine of “,
“Ten of “, “Jack of “, “Queen of “,
“King of “};
//For loop loops five times to generate five random cards
for(counter = 1; counter <= 5; counter++){
do{
//Get a random suit number and card number to display a randomcard
suitNumber = randomNumber(numOfRows);
cardNumber = randomNumber(numOfCols);
//Hide display1
/*if(deckOfCards[suitNumber][cardNumber] == 1){
//Display the card
//cout << cardNames[cardNumber] << cardSuit[suitNumber]<< endl; //
}*/
}while(deckOfCards[suitNumber][cardNumber] == 0);
//set deckOfCards[][] to 0 to show card no longer available
deckOfCards[suitNumber][cardNumber] = 0;
}//end of for
//modify the deal hands function
for(int rows = 0; rows < 4; rows++)
{
playerHands[rows][0] = 1; // KEEPING PLAYER NUMBER IN COLUMN1
}
// Saving Deck of cards to player hands
for(int rows = 0; rows < 4; rows++)
{
for(int cols=1; cols<14;cols++)
{
playerHands[rows][cols] = deckOfCards[rows][cols-1];
}
}
}
// Reset player hands function
void resetPlayerHands (int playerHands [][14]){
for(int rows = 0; rows < 4; rows++)
{
playerHands[rows][0] = 1; // KEEPING PLAYER NUMBER IN COLUMN1
}
// Saving Deck of cards to player hands
for(int rows = 0; rows < 4; rows++)
{
for(int cols=1; cols<14;cols++)
{
playerHands[rows][cols] = 0;
}
}
}
//Creating function displayHands
void displayHand (int playerHands [][14]){
string cardSuit[SUIT] = {“Hearts”, “Diamonds”, “Clubs”,”Spades”};
//Card names
string cardNames[CARDS] = {“Ace of “, “Two of “, “Three of “,
“Four of “, “Five of “, “Six of “,
“Seven of “, “Eight of “, “Nine of “,
“Ten of “, “Jack of “, “Queen of “,
“King of “};
cout << “Player ” << playerHands[0][0] <<endl;
for(int rows = 0; rows < 4; rows++)
{
for(int cols=1; cols<14;cols++)
{
if ( playerHands[rows][cols]== 0)
{
cout << cardNames[cols] << cardSuit[rows] <<endl;
}
}
}
}
1) Modify my card-dealing program so that it deals and displays 5 5-card hands, the max number of hands that can be dealt with a 52-card deck Cardst 2) Modify my card-dealing program as follows: Create a double-subscripted array playerHands[[ that is 4 rows by 14 columns. The first column of the array should store the number 1 indicating that the hand stored is owned by player 1. Sx#Staks Create a function resetPlayerHands() that accepts playerHands [] [] as an input and resets all entries to 0 except for the first column of the array-which is intended to indicate the player number. Modify the deal Hands() function so that it takes playerHands[][] and deckOfCards as inputs and stores the result of dealing 5 cards into the array playerHands[] []. The function dealHand () should not display the result of the deal. Create a function displayHands() which accepts playerHands[] [] as an input and displays the player number and the player’s hand to the screen. 3) Modify your program form exercise #2 as follows: Create a function displayMenu() that as the user whether they want to play cards or not. If the user does not want to, the program should exit. Otherwise, the user should be prompted for the number of players (15) who wish to play. displayMenu() should return the number of players to main. Adjust the playerHands[][] array so that it can accommodate up to 5 players data. Adjust the dealHand() function so that it deals up to 5 hands based on the user’s choice that displayMenu() retunred to main. Adjust the displayHands() function so that it displays all of the hands that were dealt during that round of cards. Show transcribed image text 1) Modify my card-dealing program so that it deals and displays 5 5-card hands, the max number of hands that can be dealt with a 52-card deck Cardst 2) Modify my card-dealing program as follows: Create a double-subscripted array playerHands[[ that is 4 rows by 14 columns. The first column of the array should store the number 1 indicating that the hand stored is owned by player 1. Sx#Staks Create a function resetPlayerHands() that accepts playerHands [] [] as an input and resets all entries to 0 except for the first column of the array-which is intended to indicate the player number. Modify the deal Hands() function so that it takes playerHands[][] and deckOfCards as inputs and stores the result of dealing 5 cards into the array playerHands[] []. The function dealHand () should not display the result of the deal. Create a function displayHands() which accepts playerHands[] [] as an input and displays the player number and the player’s hand to the screen. 3) Modify your program form exercise #2 as follows: Create a function displayMenu() that as the user whether they want to play cards or not. If the user does not want to, the program should exit. Otherwise, the user should be prompted for the number of players (15) who wish to play. displayMenu() should return the number of players to main. Adjust the playerHands[][] array so that it can accommodate up to 5 players data. Adjust the dealHand() function so that it deals up to 5 hands based on the user’s choice that displayMenu() retunred to main. Adjust the displayHands() function so that it displays all of the hands that were dealt during that round of cards.
Expert Answer
Answer to Question: How can I take the code from 2 and modify it to fit for #3? ( I need to do #3. I could use my code from 1 and …