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

using C++ This is the first part of a project to deal 13 cards to 4 players from

ID: 3814496 • Letter: U

Question

using C++ This is the first part of a project to deal 13 cards to 4 players from a shuffled deck of 52 cards. Each card in the deck will be represented by an integer from 0 to 51. We will see later how to translate the integer into a string representing a card. The deck and each hand will be represented by a vector of ints. The vectors should be declared in the main function and not declared globally. void unwrap(deck) # load the deck vector with integers in order from 0 to 51 void shuffle(deck) # shuffle the deck vector using random_shuffle method

Explanation / Answer

program.cpp ------

#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<vector>

using namespace std;

void unwrap(vector<int> &);
void shuffle(vector<int> &);

int main()
{
   srand(unsigned(time(0)));
   vector<int> deck;
   unwrap(deck);
   //for(int i = 0; i <= 51; i++)
       //v.push_back(i);
   cout<<" Before random shuffling ";
   for(vector<int>::iterator i = deck.begin(); i != deck.end(); ++i)
       cout<<" "<<*i;
   cout<<endl;
   shuffle(deck);
   //random_shuffle(deck.begin(), deck.end());
   cout<<" After random shuffling ";
   for(vector<int>::iterator i = deck.begin(); i != deck.end(); ++i)
       cout<<" "<<*i;
   cout<<endl;
   return 0;
}

void shuffle(vector<int> &deck)
{
   random_shuffle(deck.begin(), deck.end());
}

void unwrap(vector<int> &deck)
{
   for(int i = 0; i <= 51; i++)
       deck.push_back(i);
}