Home Forums C Programming waah! Re: Re: waah!

#3595
GWILouisaxwzkla
Participant

Heres the basic program that creates a deck and draws a hand ( not sure what you need to do as far as identifing the type of hand ?? You need the program to tell if the hand falls in one of the catagories : ( high card, pair, three of a kind, full house, straight, flush, four of a kind, straight flush, and royal flush.” ) ?? . Anyway heres the code ( not very complicated just tedious to write ) :


/****************************************************************
* File Name : c:programstempCG.cpp
* Date : July,27,2009
* Comments : new project
* Compiler/Assembler : Visual C++ 6.0
* Modifications :
*
*
*
*
*
* Program Shell Generated At: 12:13:49 p.m.
=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/


#include
#include
#include
//#include
//#include
//#include

using namespace std;


enum type { one , two , three , four , five , six , seven , eight , nine , ten , jack , queen , king };
enum suite { clubs , diamonds , hearts , spades };


struct card
{

type cardType;
suite cardSuite;
bool drawn;
void initialize ( type thisCardType , suite thisCardSuite );
};



//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@

void initializeDeck ( card * deck );
int drawCard ( card * deck );
void printHand ( card * hand );
void createHand ( card * hand , card * deck );
void rebuildDeck ( card * deck );

//##################################################################################


//main function ******************************

int main ( )
{

card deck [ 52 ];
card hand [ 5 ];

initializeDeck ( deck );
createHand ( hand , deck );
printHand ( hand );

return 0 ;
}


/******************************* FUNCTION DEFINITION ******************************

Name : initialize
Parameters :

thisCardType a(n) type ( type ) ,
thisCardSuite a(n) suite ( suite )


Class/Struct associations : struct card

Returns: Void type
Comments:



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void card :: initialize ( type thisCardType , suite thisCardSuite )
{

cardType = thisCardType;
cardSuite = thisCardSuite;
drawn = false;
return;
}

/******************************* FUNCTION DEFINITION ******************************

Name : initializeDeck
Parameters :

deck a(n) cards * ( cards * )


Returns: Void type
Comments:



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void initializeDeck ( card * deck )
{

deck [ 0 ].initialize ( one , clubs);
deck [ 1 ].initialize ( two , clubs );
deck [ 2 ].initialize ( three , clubs );
deck [ 3 ].initialize ( four , clubs );
deck [ 4 ].initialize ( five , clubs );
deck [ 5 ].initialize ( six , clubs );
deck [ 6 ].initialize ( seven , clubs);
deck [ 7 ].initialize ( eight , clubs );
deck [ 8 ].initialize ( nine , clubs);
deck [ 9 ].initialize ( ten , clubs);
deck [ 10 ].initialize ( jack , clubs );
deck [ 11 ].initialize ( queen ,clubs );
deck [ 12 ].initialize ( king , clubs );
deck [ 13 ].initialize ( one , diamonds );
deck [ 14 ].initialize ( two , diamonds );
deck [ 15 ].initialize ( three , diamonds );
deck [ 16 ].initialize ( four , diamonds );
deck [ 17 ].initialize ( five , diamonds );
deck [ 18 ].initialize ( six , diamonds );
deck [ 19 ].initialize ( seven , diamonds );
deck [ 20 ].initialize ( eight , diamonds );
deck [ 21 ].initialize ( nine , diamonds );
deck [ 22 ].initialize ( ten , diamonds );
deck [ 23 ].initialize ( jack , diamonds );
deck [ 24 ].initialize ( queen , diamonds );
deck [ 25 ].initialize ( king , diamonds );
deck [ 26 ].initialize ( one , hearts );
deck [ 27 ].initialize ( two , hearts );
deck [ 28 ].initialize ( three , hearts );
deck [ 29 ].initialize ( four , hearts );
deck [ 30 ].initialize ( five , hearts );
deck [ 31 ].initialize ( six , hearts );
deck [ 32 ].initialize ( seven , hearts );
deck [ 33 ].initialize ( eight , hearts );
deck [ 34 ].initialize ( nine , hearts );
deck [ 35 ].initialize ( ten , hearts );
deck [ 36 ].initialize ( jack , hearts );
deck [ 37 ].initialize ( queen , hearts );
deck [ 38 ].initialize ( king , hearts );
deck [ 39 ].initialize ( one , spades );
deck [ 40 ].initialize ( two , spades );
deck [ 41 ].initialize ( three , spades );
deck [ 42 ].initialize ( four , spades );
deck [ 43 ].initialize ( five , spades );
deck [ 44 ].initialize ( six , spades );
deck [ 45 ].initialize ( seven , spades );
deck [ 46 ].initialize ( eight ,spades );
deck [ 47 ].initialize ( nine , spades );
deck [ 48 ].initialize ( ten , spades );
deck [ 49 ].initialize ( jack , spades );
deck [ 50 ].initialize ( queen , spades );
deck [ 51 ].initialize ( king , spades );

return;
}
/******************************* FUNCTION DEFINITION ******************************

Name : drawCard
Parameters :

deck a(n) cards * ( cards * )


Returns: Void type
Comments:



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
int drawCard ( card * deck )
{
srand ( time(NULL) );


int i = rand () % 52;
while ( deck [ i ].drawn == true )
{

i = rand () % 52;

}
deck [ i ].drawn = true;

return i;
}
/******************************* FUNCTION DEFINITION ******************************

Name : printHand
Parameters :

hand a(n) cards * ( cards * )


Returns: Void type
Comments:



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void printHand ( card * hand )
{
int i = 0;

cout << "hand drawn :" << endl;

while ( i < 5 )
{

cout << " ";
switch ( hand [ i ].cardType )
{
case one:
{
cout << "one ";
};
break;
case two:
{
cout << "two ";
};
break;
case three:
{
cout << "three ";
};
break;
case four:
{
cout << "four ";
};
break;
case five:
{
cout << "five ";
};
break;
case six:
{
cout << "six ";
};
break;
case seven:
{
cout << "seven ";
};
break;
case eight:
{
cout << "eight ";
};
break;
case nine:
{
cout << "nine ";
};
break;
case ten:
{
cout << "ten ";
};
break;
case jack:
{
cout << "jack ";
};
break;
case queen:
{
cout << "queen ";
};
break;
case king:
{
cout << "king ";
};
break;
};
cout << "of ";
switch ( hand [ i ].cardSuite )
{
case clubs:
{
cout << "clubs" << endl;
};
break;
case diamonds:
{
cout << "diamonds" << endl;
};
break;
case hearts:
{
cout << "hearts" << endl;
};
break;
case spades:
{
cout << "spades" << endl;
};
break;
};
i ++;
}

return;
}
/******************************* FUNCTION DEFINITION ******************************

Name : createHand
Parameters :

hand a(n) card * ( card * ) ,
deck a(n) card * ( card * )


Returns: Void type
Comments:



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void createHand ( card * hand , card * deck )
{

int i = 0;
int cardIndex;

while ( i < 5 )
{
cardIndex = drawCard ( deck );
hand [ i ].cardType = deck [ cardIndex ].cardType;
hand [ i ].cardSuite = deck [ cardIndex ].cardSuite;
i ++;
}
return;
}
/******************************* FUNCTION DEFINITION ******************************

Name : rebuildDeck
Parameters :

deck a(n) card * ( card * )


Returns: Void type
Comments:



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void rebuildDeck ( card * deck )
{

int i = 0;

while ( i < 52 )
{
deck [ i ].drawn = false;
i ++;
}


return;
}