Monday, July 27, 2009

C++ question?

How could I create a program that would deal a deck of 52 cards into 4 random hands of 5 cards each and store them as an array? The hands would have to be sorted from the lowest (2) to highest (Ace) and be displayed listing the card face and suit, so basically the number and the suit (heart, spade etc).





The only viable example I could find was one using classes, and I haven't learned that or object oriented programming yet. I'm going to need to use "struct" but I'm not sure how to start. Could anyone give a clear example on how to do this. I can't seem to find information anywhere.....

C++ question?
Make a struct for cards holding value and suit. Fill an array with 52 card initialized to the suits/value of a real deck. Make a function to shuffle the cards (say, use a for loop set for like 100 and each iteration swap two random card positions in the array) . Then just take cards from the array and put them into the hand arrays. Keep a counter so you know what cards in the deck array have been dealt thus far. Then just sort the hands by card value (bubblesort function would be easy).
Reply:See Robert Lafore's Object Oriented Programming book Report It

Reply:Hello , I just bought this book you might to know about .


C++ Programming from Barnes %26amp; Noble for $9.95


ISBN 0-7607-4773-3 see page 98 What is a class ?





Im new to C++ , but this is a good book to read for all levels of users .


No comments:

Post a Comment