Dynamically linked blackjack, need help with a class

This is a discussion on Dynamically linked blackjack, need help with a class within the C++ Programming forums, part of the General Programming Boards category; Hi, I have created 2 classes for a blackjack game: A deck class and a players class. In the players ...

  1. #1
    *this
    Join Date
    Mar 2005
    Posts
    498

    Dynamically linked blackjack, need help with a class

    Hi, I have created 2 classes for a blackjack game: A deck class and a players class. In the players class I have a linked list which contains a pointer for the first and last structure on the list. I now want to be able to create a print class which can take an argument of a player, or a players hand, and print the hand to the screen. I dont know if this is the best idea, maybe to print a card at a time. If you have any suggestions let me know, I have attatched the classes and a demo program so you can see whats going on.

    Thanks,
    Josh
    Attached Files Attached Files
    Last edited by JoshR; 05-21-2005 at 12:31 AM.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Code:
    ///Player.h
    ////////////
    ...
    struct handData
    {
    	card* myCard;
    	handData* next;
    };
    typedef handData *handPtr;
    handPtr first, last;
    ...
    Whether you write your own list or use the STL list container you will need to write a function to run the list printing out each card's information as you go. I'd start out by writing a function, or overloading the << operator, in the card class to display the information in a given card. Then I'd change myCard in handData to be a simple card rather than a card*. I'd declare function to display the hand (that is, display the list) and within the function I'd declare another handPtr called current. I'd assign first to current and then while current != NULL (assuming first and last are card holding nodes and not dummy nodes like some authors use) I'd display the card in current by doing this:

    cout << current->myCard << endl;

    or this:

    display(current->myCard);

    depending on whether you overload << or write a display function for the card class.

    If you feel reasonably confortable writing your own list functions, fine. If not, I'd encourage you to use the STL list class, unless you want to take this ocassion to foray into the wonderful world of lists to see what's under the hood of the STL list class. IMHO, writing your own list functions is one of the everlasting "joys" of learning C/C++--so frustrating yet so fulfilling at the same time.
    You're only born perfect.

  3. #3
    *this
    Join Date
    Mar 2005
    Posts
    498
    thanks for your advice!!!

    I have overloaded the operator << and also have stuck the deck structure outside of the class so it can be used to print, let me know if this is a good plan:

    the reason i re-included the headers is because they have been changed a tid bit.
    Attached Files Attached Files

  4. #4
    *this
    Join Date
    Mar 2005
    Posts
    498
    Here is the demo and the print function:
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    In quickly reviewing the posted code I have no real problems with the function bodies, but there were some irregularities, some consistent, some not.

    In Demo.cpp function() you use a Print object without declaring it, that I can see anyway.

    At least for the Player and Print classs you include the cpp file in the h file rather than including the h file in the print file.

    You don't appear to include user declared header files in current file when necessary.

    I don't see the Card class declared or included anywhere.

    In Print.cpp you don't use the scope resolution operator when defining the methods.

    I realize the stuff posted may be representative and not be paste/copy from what you are using, but if it is copy/paste, then it will need to be cleaned up a bit.
    You're only born perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  2. Need help to build network class
    By weeb0 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2006, 11:33 AM
  3. Dynamically Linked mySQLProgram
    By SpiderHawk in forum Linux Programming
    Replies: 0
    Last Post: 06-30-2002, 02:09 PM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM
  5. Replies: 4
    Last Post: 09-12-2001, 03:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21