I am new to programming and i have this big problem to present tomorrow. But i dont have the slightest clue on how to solve this problem. Could someone help me out? Thanks so much.
The Question is:
(ADT implementation) To prepare for the upcoming Integrated Resort, Ms.Betting has implemented the following
Card ADT in C++ to represent a single poker card:
class Card
{
public:
Card(Suit s, Rank r);
Suit getSuit( );
Rank getRank( );
void print( ); //Example: “Spade A”, “Diamond 10” etc.
};
For your information, Suit is an enumeration with 4 values representing the four
different suits in poker {Spade, Heart, Club, Diamond}, Rank is another
enumeration with values {Ace, Two, …, Ten, Joker, Queen, King} to
represent the poker card’s rank.
Make use of the Card ADT above to implement a Deck ADT which represents a
deck of 52 poker cards. The major operations supported by the Deck ADT are
summarized below:
class Deck
{
public:
Deck( ); //Initialize the deck
void shuffle( ); //shuffle the remaining cards in the deck
Card takeOneCard( ); //take one card from the top of deck
unsigned int remainingCard( ); //get number of remaining cards
void print( ); //show each remaining cards from top to bottom
}
When the deck is first initialized, the 52 cards are arranged nicely from Spade to
Diamond, and in each suit, from Ace to King. User of the ADT can use
takeOneCard( ) to remove one card from the deck. Whenever shuffle( ) is
called, the remaining cards in the deck are randomized.
I was actually only able to do remainingCard(); the rest i was not really sure. And no, we are not allowed to use stls cause we have not been taught that yet. Just started on ADTs and other basic stuff on C++. Thanks!
So if you are able to do remainingCard(), what kind of data type are you storing the cards in? An array would probably be what your teacher wants, if you are in an ADT level class.
The next thing you will have to come up with is how to store information inside the array that represents the cards. Ex: You could represent the cards as numbers 1 through 13 and then maybe attach the a decimal .1, .2, .3, or .4 to represent the suits for each card.
(Also notice so far I have not written a single line of code. A little planning is actually required for some programs.)
Now that you have an idea for how to store the cards... (You could come up with another method, like instead of using a decimal for suit you could just add 100, 200, 300, or 400) You can begin coding for the functions that are part of your Card class.
Well now I feel stupid I just typed all that and remembered you are using enumerators ::bangs head::
I suppose I can help you with the initialization just to get you started, but to use the types of data you teacher wants you to you need to include all of the class Card and class Deck private data too. I do not mind helping you out with initializing a deck of cards for you, but I will need the whole Card class.
Please use the forum [code] tags to make your code easier to read.
i think i kind of got what u were trying to tell me! thanks so much...i am trying it out on my own right now...if ive still got doubts i will post it on the forum again! THANKS so much for your help!
1. print() will fail if the deck is empty.
2. You probably don't want to call srand every time to make up a new deck.
3. In shuffle, if you declared temp where you used it, you wouldn't need to intialise it as a dummy Ace of Spade.
4. Function div does a divide giving you a divisor and modulus in one go. You could use that in your constructor rather than doing the calculation twice.
Hey guys am just new and wanted to say hi
i wanna learn everthing about C++ am 15 yrs and i
find this very interestring just wanted to say hi to the community :)
am reading all the tuts in the page so far so good did u uys read all the tuts?
Welcome to the forums tOoOxiiCc.
Please read the top 2 sticky posts on this forum and the articles section is really good for learning about what not to do, and how to do things properly. Also the tutorial is short and sweet but well documented.
Have fun.
PS. if you post code please you code tags for formatting.
edit: it's important if you teaching yourself via the tutorial, to try and make as many little sample programs as you read. As this will enforce what you reading.
Yes i checked with my tutor later he said we were allowed to use vectors as long as we know how to use it properly because we just started on ADTs. so thanks again so much for all helping me edit my code. All the tips were useful. Btw...i'm a 'she' not a 'he'...hhahaa..