What am I supposed to do here? Please help!

This is a discussion on What am I supposed to do here? Please help! within the C++ Programming forums, part of the General Programming Boards category; Hi, I have the following program: #include <iostream.h> #include <stdlib.h> // for randomize(), rand #include <time.h> // for randomize() #include ...

  1. #1
    Registered User marCplusplus's Avatar
    Join Date
    Nov 2001
    Posts
    68

    What am I supposed to do here? Please help!

    Hi,

    I have the following program:

    #include <iostream.h>
    #include <stdlib.h> // for randomize(), rand
    #include <time.h> // for randomize()
    #include <conio.h> // for getche()

    enum Suit { clubs, diamonds, hearts, spades };

    const int jack = 11; // from 2 to 10 are
    const int queen = 12; // integers without names
    const int king = 13;
    const int ace = 14;

    class card
    {
    private:
    int number; // 2 to 10, jack, queen, king, ace
    Suit suit; // clubs, diamonds, hearts, spades
    public:
    void init(int n, Suit s) // initialize card
    { suit = s; number = n; }
    void display() // display the card
    {
    if( number >= 2 && number <= 10 )
    cout << number;
    else
    switch(number)
    {
    case jack: cout << "J"; break;
    case queen: cout << "Q"; break;
    case king: cout << "K"; break;
    case ace: cout << "A"; break;
    }
    switch(suit)
    {
    case clubs: cout << 'c'; break;
    case diamonds: cout << 'd'; break;
    case hearts: cout << 'h'; break;
    case spades: cout << 's'; break;
    }
    } // end display()
    }; // end class card

    void main()
    {
    card deck[52]; // deck of cards
    int j = 0; // counts thru deck
    int num; // card number

    cout << endl;
    for(num=2; num<=14; num++) // for each number
    {
    deck[j].init(num, clubs); // set club
    deck[j+13].init(num, diamonds); // set diamond
    deck[j+26].init(num, hearts); // set heart
    deck[j++ +39].init(num, spades); // set spade
    }

    cout << "\nOrdered deck:\n";
    for(j=0; j<52; j++) // display ordered deck
    {
    deck[j].display();
    cout << " ";
    if( !( (j+1) % 13) ) // newline every 13 cards
    cout << endl;
    }

    srand(time(0)); // seed random number generator
    for(j=0; j<52; j++) // for each card in the deck,
    {
    int k = 1 + rand() % 52; // pick another card at random
    card temp = deck[j]; // and swap them
    deck[j] = deck[k];
    deck[k] = temp;
    }

    cout << "\nShuffled deck:\n";
    for(j=0; j<52; j++) // display shuffled deck
    {
    deck[j].display();
    cout << " ";
    if( !( (j+1) % 13) ) // newline every 13 cards
    cout << endl;
    }
    getch(); // wait for keypress
    } // end main



    This is from a book I am doing. Now, at the end of the chapter, there's this excersize and I can't find a way to do it.

    Exercise 1
    Revise the main() part of the CARDADAY program so that, after shuffling the deck, it deals a hand of 13 cards to each of four players (as in bridge). A player can be represented by an array holding that player’s cards. After dealing the four hands, display them.

    The part were I have to create an array for each player without editing the class is confusing me

    Anybody kind enough to show me at least what I should do? ( not the actual code )

    Thanks,
    Marc
    No matter how much you know, you NEVER know enough.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Create 4 player arrays which will hold 13 cards.
    Then use a loop which will deal each player 13 cards. Deal one card to player 1, then player 2, then player 3, then player 4. Repeat this until each player has 13 cards.

    A second option is to create a two-dimensional player array, enough to hold 4 players of 13 cards each.

  3. #3
    Registered User marCplusplus's Avatar
    Join Date
    Nov 2001
    Posts
    68

    Unhappy Thanks but...

    How may I assign the 13 cards to the array?
    To do that I need to access the data in the class. However, there in no member function that returns them.

    What should I do?

    Marc
    No matter how much you know, you NEVER know enough.

  4. #4
    rm3
    Guest

    = D

    Then make the method.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How am I supposed to do this without a structure?
    By drty2 in forum C Programming
    Replies: 8
    Last Post: 01-21-2009, 05:57 PM
  2. Anybody know the # in PA if you didn't get a stimulous check but were supposed to?
    By gucci_shoes in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-29-2008, 07:13 AM
  3. Subclassed edit not doing what it's supposed to
    By tyouk in forum Windows Programming
    Replies: 8
    Last Post: 01-21-2005, 09:25 PM
  4. Replies: 1
    Last Post: 04-02-2003, 06:50 PM
  5. My program is not doing what it's supposed to do, help!!
    By TrazPFloyd in forum C++ Programming
    Replies: 5
    Last Post: 11-08-2002, 10:25 PM

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