Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 14th, 2006, 9:37 PM   #1
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 378
Rep Power: 3 King is on a distinguished road
Updating my old blackjack program

I just finished my second year of my three year programming course at college. On the break I am gonna go back and update some old programs I have done in the past to keep my skills fresh. I am gonna start with a blackjack program I did a couple years ago. I want to add inheritance to my classes, and wanted a bit of input b4 I do my overhaul. Here is the previous structure :

class Dealer
{
private:
  std::vector<Card> vecShoe;
  std::vector<Card> vecHand;
  int total;
public:
  Dealer(); 
  std::vector<Card> GetHand();
  void RecieveCard(); 
  int GetTotal();
  void ShuffleDeck();
  void LoadDeck();
  Card DealCard();
};

class Player
{
private:
  std::vector<Card> vecHand;
  int total;
  int money;
public:
  Player();
  std::vector<Card> GetHand();
  void RecieveCard(Card card);
  int GetTotal();
  int GetMoney();
  void SetMoney(int money);
};

If you need more info on the functions let me know. I want to add some inheritance. Do you guys think there is even a point to doing inheritance on this example? I guess there is a couple similar functions, but is there enough to even bother making a base class and all that stuff? Let me know what you guys would do with this to clean it up and make it better.
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old May 14th, 2006, 10:08 PM   #2
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 378
Rep Power: 3 King is on a distinguished road
I guess if I simply wanted to add inheritance I could just go:

class Dealer
{
private:
  std::vector<Card> vecShoe;
protected:
  std::vector<Card> vecHand;
  int total;
public:
  Dealer(); 
  virtual std::vector<Card> GetHand();
  virtual void RecieveCard(); 
  virtual int GetTotal();
  void ShuffleDeck();
  void LoadDeck();
  void PrintDeck();
  Card DealCard();
};

class Player: public Dealer
{
private:
  int money;
public:
  Player();
  std::vector<Card> GetHand();
  void RecieveCard(Card card);
  int GetTotal();
  int GetMoney();
  void SetMoney(int money);
};
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old May 15th, 2006, 2:46 AM   #3
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 316
Rep Power: 4 andro is on a distinguished road
Send a message via AIM to andro
Well, a dealer is just a player with a special set of rules.. so start there.
andro is offline   Reply With Quote
Old May 15th, 2006, 2:48 AM   #4
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 769
Rep Power: 3 Jimbo is on a distinguished road
I think you've got your inheritance backwards. A Dealer is a form of a Player, but a Player is not a form of a Dealer.
Jimbo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:10 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC