Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NEED HELP MAKING MY CODE DO THESE REQUIREMENTS: 5.2.1 Card Shuffler 1. A card sh

ID: 656157 • Letter: N

Question

NEED HELP MAKING MY CODE DO THESE REQUIREMENTS:

5.2.1 Card Shuffler

1. A card shuffler shuffles the N decks of cards, where N is defined by the
user.
2. A card shuffler distributes a different card to the dealer everytime.

5.2.2 Dealer

1. A dealer has a name.
2. A dealer retrieves a card from the shuffler.
3. A dealer distributes the card to the player.

5.2.3 Player

1. A player has a name.
2. A player retrieves a card from the dealer.
3. A player displays all the cards at his/her hands.

Here is my code: I shuffled 4 decks but need to shuffle N decks now. After the shuffle i need to deal cards. help please!

#include <iostream>
#include <fstream>
#include <cstdlib>

// Defining decks, suits, cards, and swaps
#define decks 4
#define suits 4
#define cards 13
#define swaps 1000

// C++ standard namespace resolution.
using namespace std;

// Swap the contents of the two array elements
int swap(int* element1, int* element2)
{
   int temp;
   temp = *element1;
   *element1 = *element2;
   *element2 = temp;

   // returns the contents of the first array element after swapping
   return *element1;

}
// Shuffle the 4 decks of cards
int shuffle(int ticket[], int nSwap)
{
   int card[208];
   int index1, index2, total;
   total = (decks*suits*cards);

   // Choosing two array element and swap them
   while (nSwap--)
   {
       index1 = rand() % total;
       index2 = rand() % total;

       // Swaps the index of the first card with the index of the second card
       swap(&card[index1], &card[index2]);
   }
   // Returns the ticket number of the first array element
   return card[0];
}
// Determine the card information by the ticket number
int determineCardInformation(int ticketNumber, int* deck, int* suit, int* cardNumber)
{
   *deck = (ticketNumber / (cards*suits)) + 1;
   ticketNumber = ticketNumber % (cards*suits);
   *suit = (ticketNumber / (cards)) + 1;
   ticketNumber = ticketNumber % (cards);
   *cardNumber = ticketNumber + 1;

   // return the actual card number and not the ticket number
   return *cardNumber;
}
// Display the ticket number and information about the card
void displayCardInformation(int ticketNumber, int deck, int suit, int cardNumber)
{
   cout << " ";
   cout << "Ticket Number: " << ticketNumber;
   cout << " Deck Number:" << deck;
   cout << " Suit: ";

   // Declaring the suits
   if (suit == 1)
       cout << "Spade";
   else if (suit == 2)
       cout << "Heart";
   else if (suit == 3)
       cout << "Diamond";
   else if (suit == 4)
       cout << "Club";

   cout << " Card Number: " << cardNumber;
}

int main()
{
   int card[208], deck = 0, suit = 0, cardNumber = 0, tickerNumber = 0, i, n;

   // From the input determine what card it is
   for (i = 0; i<208; i++)
       card[i] = i;

   // Shuffle the card
   shuffle(card, swaps);

   // Ask how many cards to be dealt
   cout << "Enter the number of cards to be dealt: ";
   cin >> n;

   // Determines card information from the input and then displays it
   for (i = 0; i    {
       determineCardInformation(card[i], &deck, &suit, &cardNumber);
       displayCardInformation(card[i], deck, suit, cardNumber);
   }

   system("pause");
   return 0;
}

Explanation / Answer

NEED HELP MAKING MY CODE DO THESE REQUIREMENTS:

5.2.1 Card Shuffler

1. A card shuffler shuffles the N decks of cards, where N is defined by the
user.
2. A card shuffler distributes a different card to the dealer everytime.

5.2.2 Dealer

1. A dealer has a name.
2. A dealer retrieves a card from the shuffler.
3. A dealer distributes the card to the player.

5.2.3 Player

1. A player has a name.
2. A player retrieves a card from the dealer.
3. A player displays all the cards at his/her hands.

Here is my code: I shuffled 4 decks but need to shuffle N decks now. After the shuffle i need to deal cards. help please!

#include <iostream>
#include <fstream>
#include <cstdlib>

// Defining decks, suits, cards, and swaps
#define decks 4
#define suits 4
#define cards 13
#define swaps 1000

// C++ standard namespace resolution.
using namespace std;

// Swap the contents of the two array elements
int swap(int* element1, int* element2)
{
   int temp;
   temp = *element1;
   *element1 = *element2;
   *element2 = temp;

   // returns the contents of the first array element after swapping
   return *element1;

}
// Shuffle the 4 decks of cards
int shuffle(int ticket[], int nSwap)
{
   int card[208];
   int index1, index2, total;
   total = (decks*suits*cards);

   // Choosing two array element and swap them
   while (nSwap--)
   {
       index1 = rand() % total;
       index2 = rand() % total;

       // Swaps the index of the first card with the index of the second card
       swap(&card[index1], &card[index2]);
   }
   // Returns the ticket number of the first array element
   return card[0];
}
// Determine the card information by the ticket number
int determineCardInformation(int ticketNumber, int* deck, int* suit, int* cardNumber)
{
   *deck = (ticketNumber / (cards*suits)) + 1;
   ticketNumber = ticketNumber % (cards*suits);
   *suit = (ticketNumber / (cards)) + 1;
   ticketNumber = ticketNumber % (cards);
   *cardNumber = ticketNumber + 1;

   // return the actual card number and not the ticket number
   return *cardNumber;
}
// Display the ticket number and information about the card
void displayCardInformation(int ticketNumber, int deck, int suit, int cardNumber)
{
   cout << " ";
   cout << "Ticket Number: " << ticketNumber;
   cout << " Deck Number:" << deck;
   cout << " Suit: ";

   // Declaring the suits
   if (suit == 1)
       cout << "Spade";
   else if (suit == 2)
       cout << "Heart";
   else if (suit == 3)
       cout << "Diamond";
   else if (suit == 4)
       cout << "Club";

   cout << " Card Number: " << cardNumber;
}

int main()
{
   int card[208], deck = 0, suit = 0, cardNumber = 0, tickerNumber = 0, i, n;

   // From the input determine what card it is
   for (i = 0; i<208; i++)
       card[i] = i;

   // Shuffle the card
   shuffle(card, swaps);

   // Ask how many cards to be dealt
   cout << "Enter the number of cards to be dealt: ";
   cin >> n;

   // Determines card information from the input and then displays it
   for (i = 0; i    {
       determineCardInformation(card[i], &deck, &suit, &cardNumber);
       displayCardInformation(card[i], deck, suit, cardNumber);
   }

   system("pause");
   return 0;
}