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
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
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?
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.