Thread: C++ Implementation of a Class

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    2

    C++ Implementation of a Class

    Hello fellow programmers!

    Im trying to answer the following very short question but am unsure if im doing so properly or not.

    Specify, design and implement a class for a card in a deck of playing cards. The object should contain methods for setting and retrieving the suit and rank of a card.

    I have the following:
    =======================================
    class Card{
    enum FACE{
    ACE=1, TWO, THREE, FOUR, etc, JACK, QUEEn, KING
    };
    enum SUIT{
    HEARTS, CLUBS, SPADES, DIAMONDS
    };
    private:
    SUIT suit; //declaring two instance variables
    FACE face;
    };
    =======================================
    Any help is appreciated!

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    13
    Well you still need the public methods for getting the SUIT and FACE.

    I'm not the best person to help anyone with this stuff, but I think you'd just need to add something like:

    public:

    FACE GetFace() {return face;}
    SUIT GetSuit() {return suit;}



    If I'm wrong someone please shut me up. ;o)
    "Why not go mad?"

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    2
    ehhehe.
    Im starting to program again and am extremely rusty! I havent coded in several years and am attempting to get back into it and hopefully become knowledgable enough this time around

    I learn really well by example, as you can see I did infact attempt to answer the question, I just have no clue if im right or wrong or whats up so would need some expert advice/corrections/explanations so I can better myself.

    Thanks

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Objects usually have data members to hold information and methods to manipulate that information. If the data members are private then you need public methods to manipulate it. If the data is public then even functions outside the class can manipulate it. Constructors are often described separately from methods, but they are nothing more than methods that are never called directly. They are most often used to set the initial data values when a given object is initialized. Depending what you want to do with your card/card class, you will probably need a variety of methods to use the data members effectively. If you have trouble setting up methods to use your class, post what you can do, and what you are having problems with and we can go from there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Default class template problem
    By Elysia in forum C++ Programming
    Replies: 5
    Last Post: 07-11-2008, 08:44 AM
  2. class schema implementation doubt
    By newbie007 in forum C++ Programming
    Replies: 1
    Last Post: 06-15-2008, 04:42 PM
  3. Implementation of set class in C++
    By hay_man in forum C++ Programming
    Replies: 10
    Last Post: 09-21-2006, 03:33 PM
  4. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  5. Hide class implementation from driver?
    By wbeasl in forum C++ Programming
    Replies: 5
    Last Post: 09-13-2004, 05:38 PM