1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
//Global constants
const int COLS=13;
const int ROWS=4;
//Create Function prototypes for card loading and shuffling deck of cards
void unwrap(vector<int> &);
void shuffle(vector<int> &);
void printCards(vector<int>);
//Function for dealing cards to players
void deal(const int [][COLS], int);
int main() {
//Declare vector for the number of cards
vector <int> deck;
//Declare our 2D Array for dealing cards to players
int player1[ROWS][COLS] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
int player2[ROWS][COLS] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
int player3[ROWS][COLS] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
int player4[ROWS][COLS] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
cout << "The deck before shuffling: " << endl;
unwrap(deck);
printCards(deck);
cout << "The deck after shuffling: " << endl;
shuffle(deck);
printCards(deck);
//The contents of our deal cards function are
deal(player1, ROWS);
deal(player2, ROWS);
deal(player3, ROWS);
deal(player4, ROWS);
return 0;
}
//Function definitions that load cards and randomly shuffles them
void unwrap(vector<int> &deck)
{
//Load vector with ints from 0 to 51
for (int i = 0; i <= 51; i++)
{
deck.push_back(i);
}
}
// Randomize the cards in the deck
void shuffle(vector<int> &deck)
{
random_shuffle(deck.begin(), deck.end());
}
void printCards(vector<int> deck)
{
for(int j=0; j<deck.size(); j++)
{
cout<< deck[j] << endl;
}
}
void deal(const int numbers[][COLS], int rows)
{
for (int x = 0; x < rows; x++)
{
for (int y = 0; y < COLS; y++)
{
cout<<setw(4) << numbers [x][y] << " ";
}
cout << endl;
}
}
|