Creating deck of card objects

Hello all - I have a small card game project due this Sunday that involves creating 2 separate classes: one for card objects(myCard), one for a deck object (myDeck) that creates 60 cards in its constructor. However, if I just call 60 card objects in the deck's constructor through inheritance and create a deck object in main, I don't believe I would be able to manipulate/access those individual card objects due to scope(? - could be wrong).

If I, for example, wanted to shuffle the deck and manipulate those individual cards, what would be the best way to structure this? Should I create a vector of "myCard" objects as a protected variable, use push_back for 60 cards in the myDeck's constructor and access them that way?

My apologies if this is a weird question. I am still very new to the language while going to school for business, so finding the most logical way to approach smaller projects seems to be a struggle for me at the moment.

Thank you!
I don't understand your reference to "inheritance". There's no inheritance here.

I also don't understand what kind of deck has 60 cards. Is this an extended deck with two extra ranks?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Regular deck of 52 cards
const int Ranks = 13, Suits = 4, DeckSize = Ranks * Suits;

class Card {
    int rank, suit;
public:
    Card(int r, int s) : rank(r), suit(s) { }
    int getRank() const { return rank; }
    int getSuit() const { return suit; }
};

class Deck {
    std::vector<Card> cards;
    int top; // may need this for dealing
             // (unless you are popping cards from the vector)
public:
    Deck() : top(0) {
        for (int s = 0; s < 4; s++)
            for (int r = 1; r <= 13; r++)
                cards.push_back(Card(r, s));
    }
    void shuffle() { } // you can shuffle the cards here
}

Last edited on
Topic archived. No new replies allowed.