Deck of cards

I need a function deal_to that removes one card from the deck and places it into a hand. After dealing 5 another boolean function to compare the 5 cards to see if they are pairs. so far the function cout all the cards from the deck.

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  #include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>


using namespace std;

enum Suit {C, D, H, S};

class Card {
    public:
    Suit suit;
    int val;

    Card(Suit s, int v) {
        suit = s;
        val = v;

    }



};

ostream& operator<<(ostream& o, Card c) {


    switch (c.val) {
        case 1:
            o << "A";
            break;
        case 13:
            o << "K";
            break;
        case 12:
            o << "Q";
            break;
        case 11:
            o << "J";
            break;
        default:
            o << c.val;
    }

    o << "-";

    switch (c.suit) {
        case C:
            o << "C";
            break;
        case D:
            o << "D";
            break;
        case H:
            o << "H";
            break;
        case S:
            o << "S";
            break;
    }

    return o;
}

class Hand {
    public:
vector<Card> hands;


void has_pair();

};

class Deck {

    public:

    vector<Card> cards;

    Deck() {
        Suit local_stuff[] = {C, D, H, S};
        for (int i=0; i<4; i++)
            for (int v=1; v<= 13; v++)
                cards.push_back(Card(local_stuff[i], v));
    }

    void shuffle() {
        for (int i=0; i<999999; i++) {
            swap(cards[rand()%cards.size()], cards[rand()%cards.size()]);
        }
    }

    void deal_to();
    
        
    


};


int main() {

    srand(time(NULL));

    Deck d;
    d.shuffle();



    for (int i=0; i<d.cards.size(); i++) {
        cout << d.cards[i] << "...";
        if (i%7==6) cout << endl;
    }
}
std has shuffle and random_shuffle. You might want to compare them to yours.

deal_to is now part of the deck. It can erase one of the cards, but where does it put it? A reference parameter, perhaps?
Topic archived. No new replies allowed.