# (Solved) : Question Take Code 2 Modify Fit 3 Need 3 Could Use Code 1 2 Code Part 1 Include Include I Q42700810 . . .

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;
}

}
}
}

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 …

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.