simple poker card game in object oriented project.

The program is to simulate a simple version of a poker game. The team is required to create a
class for the Card with at least the following attributes:
- Suit. That represents one of these four: Spades, Hearts, Diamonds and Clubs.
- Rank. Thirteen values running from two to ten, Jack, Queen, King, and Ace.
The team must design the class Deck. This class must contains 52 cards; each unique by the
suit and rank values. The class Deck should have a function call Shuffle, to initialize the
cards in a random order into an array, or perhaps to allow the user to pick random cards from
the array of 52 cards.
Finally, a class Player should also be design, this class is to receive five cards from the deck,
and this could be done with a function SetCard in the class player and a function
HandOneCard from the Deck class. The class player should have a function CheckHand
that display in the screen if there is any card with the same number grouped in pairs, trips or
quads. Look at the example output.

Poker Game Options :
1 – Shuffle and hand
2 – Exit
3 – Additional functions
Please enter an option : 1
Shuffling.....!
5  K A K 5
You have two pairs : [5, K]
Press any key to go back to main menu....

i already write the class but i am not sure how to write the functions,this is my class.


#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string>
using namespace std;

class Card
{
protected:
int suits[4];
char * ranks[13];
public:
Card()
{
suits[4] = (0x03,0x04,0x05,0x06);
ranks[13] = ("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K");
}
void showCards();
};

class Deck
{
protected:
int deck[52];
public:
void ShuffleDeck();
void HandOneCard();
};

class Players
{
protected:
int i,u,y,r,e;
public:
void SetCard();
void CheckHand();
};


I don't know how to do a randomizer for poker cards.
have you got a main()?... plus you might want to edit that and put [code][/code] around the code...

As far as a function, the initilizer Card() that you have is actually a function. You could have written it like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Card
{
  // ...
  public:
  Card()
  int otherFunction(); // just to show another example
};
Card::Card()
{
  suits[4] = (0x03,0x04,0x05,0x06);
  ranks[13] = ("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K");
}
int Card::otherFunction()
{
  // ...
}


is that what you needed help with?
oh, if you are going to use ranks as a char array, it would probably be better to to call it as one..

char * ranks[13]; creates essentially a char pointer array... or something like a 2D char array...

char ranks[13]; this is probably all you need, but you need to change another line:

ranks[13] = ('A', '2' /*.. basically all the double quoted char arrays to single quoted chars */ );


Oh, it might be better to use more regular characters for the suits... like H,D,S,C or something
Last edited on
Try using a STL container instead of an array for your deck. Then simply call an STL algorithm to do the shuffling for you.
raw array could use the STL algorithm--random_shuffle too
1
2
3
char card[10] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'};  
std::random_shuffle(card, card + 9);
cout<<"card = "<<card<<"\n";
Must've missed that. Well, use the above. (Do remember to include cstdlib, though.)
Thanks everyone for the help.
can any pro C++ programmer add me MSN pusonghui@hotmail.com i got so much question to ask. Thanks a lot.
There won't be many people who will be doing such things, try just posting them on here or alternatively try the IRC channel: http://www.cplusplus.com/forum/lounge/28548/
Topic archived. No new replies allowed.