Deck Class

Hey guys, I'm working on a project. its a memory card game. in this game the deck is a little weird its 2 decks of 9-ace (48 cards). I've got a card class
1
2
3
4
5
6
7
8
9
10
11
12
13
card.h

class PlayingCard
{
    private:
        cardSuit suit;
        int rank;
    public:
	PlayingCard();
        string rankString(int r) const;
        string suitString(cardSuit s) const;
        string cardString() const;
};


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
card.cpp

PlayingCard::PlayingCard()
{
    rank = 14;
    suit = 1;
}

PlayingCard::PlayingCard(int rank, cardSuit s)
{
    suit;
    rank;
}

string PlayingCard::rankString(int r) const
{
    switch (int r)
    {
        case NINE:
            return "9";
            break;
        case TEN:
            return "T";
            break;
        case JACK:
            return "J";
            break;
        case QUEEN:
            return "Q";
            break;
        case KING:
            return "K";
            break;
        case ACE:
            return "A";
            break;
    }
}

string PlayingCard::suitString(cardSuit s) const
{
    switch (cardSuit s)
    {
        case CLUB:
            return "C";
            break;
        case DIAMOND:
            return "D";
            break;
        case HEART:
            return "H";
            break;
        case SPADE:
            return "S";
            break;
    }
}

string PlayingCard::cardString() const
{
    return suitString(suit) + rankString(rank);
}


and I need to generate a deck of card objects. so can anyone help me with this? I'm not really sure where to start on making my deck class and its really bugging me:P
Thanks for any help
1
2
3
4
5
PlayingCard::PlayingCard(int rank, cardSuit s)
{
    suit;
    rank;
}


You realize this doesn't do anything. It will compile, however your fields will not be populated. You need to assign the parameters to your fields. I would also change the first parameter from rank to something else to avoid a name clash (though, if you used an initialization list the names of the parameters can be the same as the fields).

I'm not really sure where to start on making my deck class

How about giving the Deck class a vector of PlayingCards?
would you like to offer some advice on how I can populate those fields?
You have populated them in the other constructor. You're assigning 14 to rank and 1 to suit. In the constructor taking in the parameters, you simply need to assign the parameters to your member variables.
Topic archived. No new replies allowed.