Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,572 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,927 people online right now. Registration is fast and FREE... Join Now!




bridge program

 
Reply to this topicStart new topic

bridge program, deals with setting, dealing, shuffling, and sorting cards

mrkwlortie
11 Apr, 2008 - 08:19 AM
Post #1

New D.I.C Head
*

Joined: 10 Mar, 2008
Posts: 11

I have a start to my program but I am struggling with several things. I need to write the setcard() logic to reveal cards in my output rather than error messages. I tried to cout << rankNames[rnk] but it did not work. I also need to think about logic for sorting and shuffling. As always, thanks a lot.

CODE

//
#include <iostream>
#include <string>

using namespace std;

string rankNames[] = { "Error", "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
                          "Nine", "Ten", "Jack", "Queen", "King" };
string suitNames[] = { "Error", "Diamonds", "Clubs", "Hearts", "Spades"};

class Card
{    
        private:
        int rank;
        int suit;
        public:
        // Constructor for a Card
        Card(int rk, int st)
        {
                rank = rk;
                suit = st;
        }
      
        // A default Constructor is needed to declare an array of Cards
        Card()
        {
                rank = 0;
                suit = 0;
        }
      
        // A string that represents the card
        string toString()
        {
                return rankNames[rank] + " of " + suitNames[suit];
        }
      
        // Compare two cards.  Write this.
        bool greater(Card other) { }

        // Write this
        void setCard(int st, int rnk)
       {
          
       }
};

// Routine to write a set of cards
void printCards(Card deck[], int size)
{
        for (int i = 0; i < size; i++)
                cout << deck[i].toString() << endl;
}

// Write a routine to jumble an array of cards
void shuffle(Card deck[], int size) { }

// Write a routine to sort an array of cards
void sort(Card deck[], int size) { }

int main()
{
        Card deck[52];                // Creates 52 cards using default constructor
        // Create a regulation deck of cards
        int pos = 0;
        for (int suit = 1; suit <= 4; suit++)
                for (int rank = 1; rank <= 13; rank++, pos++)
                        deck[pos].setCard(suit, rank);

        // Has the deck been created?
        cout << "\nInitial deck\n";
        printCards(deck, 52);

        shuffle(deck, 52);
        cout << "\nShuffled deck\n";
        printCards(deck, 52);

        // Deal a hand
        // This is not regulation dealing.  Rather than getting the
        // first 13 cards, I should get every fourth card.
        Card hand[13];
        for (pos = 0; pos < 13; pos++)
                hand[pos] = deck[pos];

        // Display my hand
        cout << "\nMy hand as dealt\n";
        printCards(hand, 13);
      
        // Organize my hand
        sort(hand, 13);
        cout << "\nMy Hand after sorting\n";
        printCards(hand, 13);
        
        return 0;
}


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 11:59PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month