Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Array Problem
Rating 1 V
alexviii
post Feb 3 2007, 10:55 AM
Post #1


Member [Level 1]
****

Group: Members
Posts: 70
Joined: 5-August 06
From: Rome (born only)
Member No.: 27,852



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:
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:
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:
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 list

class 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.
Go to the top of the page
 
+Quote Post
osknockout
post Feb 7 2007, 01:45 AM
Post #2


Super Member
*********

Group: Members
Posts: 396
Joined: 14-November 04
From: Elysium
Member No.: 2,280



smile.gif 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.
Go to the top of the page
 
+Quote Post
rajibbd
post Jul 31 2007, 06:18 PM
Post #3


Newbie [Level 3]
***

Group: Members
Posts: 47
Joined: 22-July 07
From: Dhaka, Bangladesh
Member No.: 46,859



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];
Go to the top of the page
 
+Quote Post
ankneo
post Sep 19 2007, 04:26 AM
Post #4


Newbie
*

Group: Members
Posts: 7
Joined: 18-September 07
Member No.: 50,196



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.
Go to the top of the page
 
+Quote Post
larryf
post Jan 28 2008, 06:07 PM
Post #5


Newbie
*

Group: Members
Posts: 3
Joined: 25-January 08
Member No.: 56,859



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 0x3

Then, as each byte represents a card, you could even define the mask values as such.

#define SUIT_MASK 0x30
#define CARD_MASK 0xF

Then, 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

QUOTE(alexviii @ Feb 3 2007, 02:55 AM) *
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:
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:
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:
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 list

class 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.

Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Dotworlds Free Domain Problem!(24)
  2. Girls Problem(10)
  3. Auto Webpage Resolution Format(7)
  4. I Have A Girl Problem Here(24)
  5. Kitten Born With Only One Eye And No Nose(27)
  6. My Dog Pukes Regularly(16)
  7. Remote Assistance Problem(7)
  8. Laptop Keyboard Problem(6)
  9. How To Reformat Your Harddrive...(10)
  10. Problem With My External Hard Disk(7)
  11. Remove A Value From A Php Array Based On Its Value(5)
  12. Two Lan Ports Problem(2)
  13. Rpg Maker 2003 Music Problem(2)
  14. Mysql-essential-5.0.51 Installion Problem(2)
  15. Can Anyone Help Me With My Graphic Card - 8600 Gt [resolved](15)
  1. Flash Problem(9)
  2. I'm Having A Strange Problem With My Ping In Cs:s(27)
  3. Cannot Connect To Mail Server(3)
  4. Credits Problem(14)
  5. Sql Problem(2)
  6. Why My Computer Freezez(4)
  7. Phpmyadmin Problem [resolved](2)
  8. Weird Write Problem(3)
  9. Fantastico And Cpanel Skin Problem.(1)
  10. Harddrive "open With..." Problem(1)
  11. [chsupport #ecn-115724]: Ftp/cpanel Login Problem(7)
  12. Need Help: Problem Seeing My Site(3)
  13. Postage Costs Problem For My Website(4)


 



- Lo-Fi Version Time is now: 25th July 2008 - 07:43 PM