alexviii 0 Report post Posted February 3, 2007 I'm having trouble with an assignment for my data structures class. I have to simulate a card player getting a a pile of 52 cards (a full deck). I need to print the cards so that they are printed on 4 lines (1 line for each suit) 13 cards to a line. (I.E. AC (Ace of clubs) KC QC etc.) The first two files where provided in class: Code: /** @file Card.h * */class Card{ private: char rank; char suit; public: void printMe(); void setRank(char); void setSuit(char); char getRank(); char getSuit(); int getBridgeValue();}; Code: /** @file Card.cpp * */#include "Card.h"#include <iostream>using namespace std;void Card::printMe(){ cout << getRank() << getSuit();}void Card::setRank(char whatrank){ rank = whatrank; }void Card::setSuit(char whatsuit){ suit = whatsuit;}char Card::getRank(){ return rank;}char Card::getSuit(){ return suit;} We must code ourselves at least a Pile.h, Pile.cpp Hand.h, Hand.cpp, pr1.cpp, and build.sh I have attempted to code the some of the Pile.h and Pile.cpp ising the required Array-Based Implentation of the ADT List. Here is my Pile.h file Code: /** @ Pile.h * *///#include "Card.h"const int MAX_LIST = 52;typedef Card ListItemtype; // List item data type//ListItemType items[MAX_LIST]; //Array of list items */Card items[MAX_LIST]; //array of cards int size; // LOGICAL length of the listclass Pile{ private: Card items[MAX_LIST]; public: Pile(); // void createDeck();/* void orderCards(); void dealCard(); void randomize(); void printMe();*/}; I keep getting syntax errors on the typedef statement and the "Card items[MAX_LIST]; " Please help? P.S. If I seem inept I haven't coded in C++ in a year so while I know all the very basic things I've forgotten a lot too. Share this post Link to post Share on other sites
osknockout 0 Report post Posted February 7, 2007 You haven't defined any ListItemtype. - That is to say 'ListItemtype' doesn't exist as a type, so you can't specify 'Card' as type 'ListItemtype'. Just specify it, you probably just forgot to encode it. Nice operator overloading btw. Share this post Link to post Share on other sites
rajibbd 0 Report post Posted July 31, 2007 Why you declare "Card items[MAX_LIST]" as an Array type. You can use it as pointer type. What i know about programming is Declare any data in Globally is back dated idea. But any way Try to create a pointer type array of Card object. The code may be like this. Card *items = new Card[MAX_LIST]; Share this post Link to post Share on other sites
ankneo 0 Report post Posted September 19, 2007 Using pointers is always a good thing, but to make sure ur pointers work well don't forget to allocate memory to them as most of the people don't do so and in some systems it creates a problem. Share this post Link to post Share on other sites
larryf 0 Report post Posted January 28, 2008 I did this for a Texas Hold'em game once... I found it pretty simple to represent the cards using a single integer. (You're only talking about 52 cards.. Come on..). So, for 4 suits, you need two bits. Then, value the cards from 1 to 14 using 4 bits. Now, you are only using 6 bits, even in byte you have left over data that you COULD use to hold simple flags like "Face Card" etc. Store your numbers in your array, and get the values like this:#define SUIT_SPADES 0x0#define SUIT_CLUBS 0x1#define SUIT_HEARTS 0x2#define SUIT_DIAMOND 0x3Then, as each byte represents a card, you could even define the mask values as such.#define SUIT_MASK 0x30#define CARD_MASK 0xFThen, just AND these with your card values. So, the Ace Of Spades would equal 1, the ace of clubs would equal 17, the ace of hearts would equal 33 and the Ace of Diamonds would be 49.So, what would the Queen of Hearts be? 44... (Starting at bit 6, the value is 2 for Hearts, and 12 for the Queen. (A,2,3,4,5,6,7,8,9,10,J,Q,K).Larry I'm having trouble with an assignment for my data structures class. I have to simulate a card player getting a a pile of 52 cards (a full deck). I need to print the cards so that they are printed on 4 lines (1 line for each suit) 13 cards to a line. (I.E. AC (Ace of clubs) KC QC etc.) The first two files where provided in class: Code: /** @file Card.h * */class Card{ private: char rank; char suit; public: void printMe(); void setRank(char); void setSuit(char); char getRank(); char getSuit(); int getBridgeValue();}; Code: /** @file Card.cpp * */#include "Card.h"#include <iostream>using namespace std;void Card::printMe(){ cout << getRank() << getSuit();}void Card::setRank(char whatrank){ rank = whatrank; }void Card::setSuit(char whatsuit){ suit = whatsuit;}char Card::getRank(){ return rank;}char Card::getSuit(){ return suit;} We must code ourselves at least a Pile.h, Pile.cpp Hand.h, Hand.cpp, pr1.cpp, and build.sh I have attempted to code the some of the Pile.h and Pile.cpp ising the required Array-Based Implentation of the ADT List. Here is my Pile.h file Code: /** @ Pile.h * *///#include "Card.h"const int MAX_LIST = 52;typedef Card ListItemtype; // List item data type//ListItemType items[MAX_LIST]; //Array of list items */Card items[MAX_LIST]; //array of cards int size; // LOGICAL length of the listclass Pile{ private: Card items[MAX_LIST]; public: Pile(); // void createDeck();/* void orderCards(); void dealCard(); void randomize(); void printMe();*/}; I keep getting syntax errors on the typedef statement and the "Card items[MAX_LIST]; " Please help? P.S. If I seem inept I haven't coded in C++ in a year so while I know all the very basic things I've forgotten a lot too. Share this post Link to post Share on other sites