Home › Forums › C Programming › waah!
- This topic has 1 reply, 2 voices, and was last updated 15 years, 5 months ago by GWILouisaxwzkla.
Viewing 1 reply thread
- AuthorPosts
- July 25, 2009 at 6:03 am #2215MercedeSlempParticipant
another problem..
“create a program having a menu of drawing 5 cards from a shuffled deck. after drawing cards..identify them as follows: high card, pair, three of a kind, full house, straight, flush, four of a kind, straight flush, and royal flush.”
help! :?:
- July 27, 2009 at 5:18 pm #3595GWILouisaxwzklaParticipant
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 ) :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378<br />/****************************************************************<br />* File Name : c:programstempCG.cpp<br />* Date : July,27,2009<br />* Comments : new project<br />* Compiler/Assembler : Visual C++ 6.0<br />* Modifications :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 12:13:49 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include <br />#include <br />#include <br />//#include <br />//#include <br />//#include <br /><br />using namespace std;<br /><br /><br />enum type { one , two , three , four , five , six , seven , eight , nine , ten , jack , queen , king };<br />enum suite { clubs , diamonds , hearts , spades };<br /><br /><br />struct card<br />{<br /><br />type cardType;<br />suite cardSuite;<br />bool drawn;<br />void initialize ( type thisCardType , suite thisCardSuite );<br />};<br /><br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br /><br />void initializeDeck ( card * deck );<br />int drawCard ( card * deck );<br />void printHand ( card * hand );<br />void createHand ( card * hand , card * deck );<br />void rebuildDeck ( card * deck );<br /><br />//##################################################################################<br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />card deck [ 52 ];<br />card hand [ 5 ];<br /><br />initializeDeck ( deck );<br />createHand ( hand , deck );<br />printHand ( hand );<br /><br />return 0 ;<br />}<br /><br /><br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : initialize<br />Parameters :<br /><br />thisCardType a(n) type ( type ) ,<br />thisCardSuite a(n) suite ( suite )<br /><br /><br />Class/Struct associations : struct card<br /><br />Returns: Void type<br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void card :: initialize ( type thisCardType , suite thisCardSuite )<br />{<br /><br />cardType = thisCardType;<br />cardSuite = thisCardSuite;<br />drawn = false;<br />return;<br />}<br /><br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : initializeDeck<br />Parameters :<br /><br />deck a(n) cards * ( cards * )<br /><br /><br />Returns: Void type<br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void initializeDeck ( card * deck )<br />{<br /><br />deck [ 0 ].initialize ( one , clubs);<br />deck [ 1 ].initialize ( two , clubs );<br />deck [ 2 ].initialize ( three , clubs );<br />deck [ 3 ].initialize ( four , clubs );<br />deck [ 4 ].initialize ( five , clubs );<br />deck [ 5 ].initialize ( six , clubs );<br />deck [ 6 ].initialize ( seven , clubs);<br />deck [ 7 ].initialize ( eight , clubs );<br />deck [ 8 ].initialize ( nine , clubs);<br />deck [ 9 ].initialize ( ten , clubs);<br />deck [ 10 ].initialize ( jack , clubs );<br />deck [ 11 ].initialize ( queen ,clubs );<br />deck [ 12 ].initialize ( king , clubs );<br />deck [ 13 ].initialize ( one , diamonds );<br />deck [ 14 ].initialize ( two , diamonds );<br />deck [ 15 ].initialize ( three , diamonds );<br />deck [ 16 ].initialize ( four , diamonds );<br />deck [ 17 ].initialize ( five , diamonds );<br />deck [ 18 ].initialize ( six , diamonds );<br />deck [ 19 ].initialize ( seven , diamonds );<br />deck [ 20 ].initialize ( eight , diamonds );<br />deck [ 21 ].initialize ( nine , diamonds );<br />deck [ 22 ].initialize ( ten , diamonds );<br />deck [ 23 ].initialize ( jack , diamonds );<br />deck [ 24 ].initialize ( queen , diamonds );<br />deck [ 25 ].initialize ( king , diamonds );<br />deck [ 26 ].initialize ( one , hearts );<br />deck [ 27 ].initialize ( two , hearts );<br />deck [ 28 ].initialize ( three , hearts );<br />deck [ 29 ].initialize ( four , hearts );<br />deck [ 30 ].initialize ( five , hearts );<br />deck [ 31 ].initialize ( six , hearts );<br />deck [ 32 ].initialize ( seven , hearts );<br />deck [ 33 ].initialize ( eight , hearts );<br />deck [ 34 ].initialize ( nine , hearts );<br />deck [ 35 ].initialize ( ten , hearts );<br />deck [ 36 ].initialize ( jack , hearts );<br />deck [ 37 ].initialize ( queen , hearts );<br />deck [ 38 ].initialize ( king , hearts );<br />deck [ 39 ].initialize ( one , spades );<br />deck [ 40 ].initialize ( two , spades );<br />deck [ 41 ].initialize ( three , spades );<br />deck [ 42 ].initialize ( four , spades );<br />deck [ 43 ].initialize ( five , spades );<br />deck [ 44 ].initialize ( six , spades );<br />deck [ 45 ].initialize ( seven , spades );<br />deck [ 46 ].initialize ( eight ,spades );<br />deck [ 47 ].initialize ( nine , spades );<br />deck [ 48 ].initialize ( ten , spades );<br />deck [ 49 ].initialize ( jack , spades );<br />deck [ 50 ].initialize ( queen , spades );<br />deck [ 51 ].initialize ( king , spades );<br /><br />return;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : drawCard<br />Parameters :<br /><br />deck a(n) cards * ( cards * )<br /><br /><br />Returns: Void type<br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />int drawCard ( card * deck )<br />{<br />srand ( time(NULL) );<br /><br /><br />int i = rand () % 52;<br />while ( deck [ i ].drawn == true )<br />{<br /><br />i = rand () % 52;<br /><br />}<br />deck [ i ].drawn = true;<br /><br />return i;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : printHand<br />Parameters :<br /><br />hand a(n) cards * ( cards * )<br /><br /><br />Returns: Void type<br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void printHand ( card * hand )<br />{<br />int i = 0;<br /><br />cout << "hand drawn :" << endl;<br /><br />while ( i < 5 )<br />{<br /><br />cout << " ";<br />switch ( hand [ i ].cardType )<br />{<br />case one:<br />{<br />cout << "one ";<br />};<br />break;<br />case two:<br />{<br />cout << "two ";<br />};<br />break;<br />case three:<br />{<br />cout << "three ";<br />};<br />break;<br />case four:<br />{<br />cout << "four ";<br />};<br />break;<br />case five:<br />{<br />cout << "five ";<br />};<br />break;<br />case six:<br />{<br />cout << "six ";<br />};<br />break;<br />case seven:<br />{<br />cout << "seven ";<br />};<br />break;<br />case eight:<br />{<br />cout << "eight ";<br />};<br />break;<br />case nine:<br />{<br />cout << "nine ";<br />};<br />break;<br />case ten:<br />{<br />cout << "ten ";<br />};<br />break;<br />case jack:<br />{<br />cout << "jack ";<br />};<br />break;<br />case queen:<br />{<br />cout << "queen ";<br />};<br />break;<br />case king:<br />{<br />cout << "king ";<br />};<br />break;<br />};<br />cout << "of ";<br />switch ( hand [ i ].cardSuite )<br />{<br />case clubs:<br />{<br />cout << "clubs" << endl;<br />};<br />break;<br />case diamonds:<br />{<br />cout << "diamonds" << endl;<br />};<br />break;<br />case hearts:<br />{<br />cout << "hearts" << endl;<br />};<br />break;<br />case spades:<br />{<br />cout << "spades" << endl;<br />};<br />break;<br />};<br />i ++;<br />}<br /><br />return;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : createHand<br />Parameters :<br /><br />hand a(n) card * ( card * ) ,<br />deck a(n) card * ( card * )<br /><br /><br />Returns: Void type<br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void createHand ( card * hand , card * deck )<br />{<br /><br />int i = 0;<br />int cardIndex;<br /><br />while ( i < 5 )<br />{<br />cardIndex = drawCard ( deck );<br />hand [ i ].cardType = deck [ cardIndex ].cardType;<br />hand [ i ].cardSuite = deck [ cardIndex ].cardSuite;<br />i ++;<br />}<br />return;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : rebuildDeck<br />Parameters :<br /><br />deck a(n) card * ( card * )<br /><br /><br />Returns: Void type<br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void rebuildDeck ( card * deck )<br />{<br /><br />int i = 0;<br /><br />while ( i < 52 )<br />{<br />deck [ i ].drawn = false;<br />i ++;<br />}<br /><br /><br />return;<br />}<br /><br /><br />
- AuthorPosts
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.