Task 1 Do the Shuffle Now that youve created a pseudo deck

Task #1 – Do the Shuffle Now that you’ve created a “pseudo” deck of cards that you have stored in an array, now programmatically “shuffle” them in order to create a deck of cards that is randomly sorted. How you accomplish this task is up to you! You must use either the Array or ArrayList for this task.

Task #2 – Display both the Unshuffled and Shuffled Decks Display both decks in a comma delimited format. (i.e., 3 of Hearts, 7 of Clubs, etc. …)

Solution

// shuffle deck of 52 cards randomly and sorting task1

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main() {
int z;
int x,j,k,temp_var;
int deck_card[52];
int p;
srand(time(0)); // for random
  
for (x=0; x<52; x++) {
deck_card[x] = x;
}
  

while (cin >> p)
{
for ( x=0; x<(52-1); x++)
{
k = x + (rand() % (52-x));
int temp_var = deck_card[x];
deck_card[x] = deck_card[k];
deck_card[k] = temp_var;
}
  
for (j=0; j<p; j++)
{
cout<<deck_card[j] << \" \";
}
cout<<endl;
}
cin>>z;
  
return 0;
  
}

Task #1 – Do the Shuffle Now that you’ve created a “pseudo” deck of cards that you have stored in an array, now programmatically “shuffle” them in order to crea

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site