0

So I am having some trouble with programming. I have a project that my professor wants us to make a poker game. We are supposed to have a Card class with public members: Constructer,ShuffleCard, GetCard(), and Thirteen void functions to display cards.

also Private members: A deck of cards, and NextCard.

I am having trouble figuring out what needs to be in the class along with creating the program. :( Do not write it for me, I just am SOL and I am not able to find a tutor who will help me with this so I have turned to my only source, the internet. Please don't call me stupid.

  • I'm confused - which class are you having trouble with knowing how to write? (The main reason I ask is that it sounds like this should be more than one class; for example, it sounds like the concepts of a card, a deck of cards, a list of cards, and different types of cards are conflated here). – EJoshuaS - Stand with Ukraine Sep 25 '16 at 02:38

2 Answers2

0

I'll try to give real world examples to help you through it (even though they might not be rigorous enough for some people on StackOverflow...). This might not directly represent what you have to do for your assignment (since we don't have much details), but at least it should help you understand better.

A class is kind of a type. By this, I mean it is to be treated like and type of object (real world ones). A Card object is something that has a Value (1,2,3,... J,Q,K) and a Type (Spade, Heart, etc), which could be implemented as private attributes. You would then write a getValue() and getType() member to return those attributes value.

You would then have a DeckOfCards, which might be implemented as a custom class which contains a collection of Card objects and methods to manipulate it, such as shuffleCards(), getCardOnTopOfDeck(), resetDeck(), etc.

As you can see, those are made to help you build a game in a more "real world oriented code". You would start a game by creating a deck (calling DeckOfCards constructor), then giving cards to each player (getCardOnTopOfDeck(), which would have to remove it from the collection of Card objects contained in the DeckOfCards object). I think you can extrapolate from here.

Cedric
  • 889
  • 1
  • 8
  • 18
0

Here is a code snippet to get an idea . Happy coding:

enum suit_t {DIAMOND,SPADE,CLUB,HEART};
enum power_t {ACE=1,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,JACK,QUEEN,KING};


struct card_t
{
    suit_t suit_;
    power_t power_;
};

class deck
{

private:
    card_t card_[52];

public:
    deck();
    void shuffle();
    card_t get_card() const;
    card_t next_card();
    void display(power_t power, suit_t suit);
};
seccpur
  • 4,996
  • 2
  • 13
  • 21