-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeckshuffle.cpp
More file actions
67 lines (59 loc) · 1.4 KB
/
deckshuffle.cpp
File metadata and controls
67 lines (59 loc) · 1.4 KB
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
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
class CardPicker {
int* deck;
string suits[4];
string ranks[13];
public:
CardPicker() {
deck = new int[52];
suits[0] = "Spades";
suits[1] = "Hearts";
suits[2] = "Diamonds";
suits[3] = "Clubs";
ranks[0] = "Ace";
ranks[1] = "2";
ranks[2] = "3";
ranks[3] = "4";
ranks[4] = "5";
ranks[5] = "6";
ranks[6] = "7";
ranks[7] = "8";
ranks[8] = "9";
ranks[9] = "10";
ranks[10] = "Jack";
ranks[11] = "Queen";
ranks[12] = "King";
for (int i = 0; i < 52; i++)
deck[i] = i;
}
void shuffleDeck() {
srand(time(0));
for (int i = 0; i < 52; i++) {
int index = rand() % 52;
int temp = deck[i];
deck[i] = deck[index];
deck[index] = temp;
}
}
void pickFourCards() {
cout << "Four randomly selected cards:" << endl;
for (int i = 0; i < 4; i++) {
int card = deck[i];
string suit = suits[card / 13];
string rank = ranks[card % 13];
cout << rank << " of " << suit << endl;
}
}
~CardPicker() {
delete[] deck;
}
};
int main() {
CardPicker picker;
picker.shuffleDeck();
picker.pickFourCards();
return 0;
}