伊莉討論區
標題: 救命C++ 撲克牌洗牌與發牌 (看不懂英文 慘) [打印本頁]
作者: adewawa 時間: 2012-5-15 02:51 PM 標題: 救命C++ 撲克牌洗牌與發牌 (看不懂英文 慘)
The problem - Card Shuffling and DealingCreate a program to shuffle and deal a deck of cards. The program should consist of class Card, class DeckOfCards, a driver program, and an utility module.
class Card should provide:
- Data members face and suit of type int.
- A constructor that receives two ints representing the face and suit and uses them to initialize the data members.
- Two static arrays of strings representing the faces and suits.
- A toString function that returns the Card as a string in the form "face of suit." You can use the + operator to concatenate strings.
class DeckOfCards should contain:
- A vector of Cards named deck to store the Cards.
- An integer currentCard representing the next card to deal.
- A default constructor that initializes the Cards in the deck. The constructor should use vector function push_back to add each Card to the end of the vector after the Card is created and initialized. This should be done for each of of the 52 Cards in the deck.
- A shuffle function that shuffles the Cards in the deck. The shuffle algorithm should iterate through the vector of Cards. For each Card, randomly select another Card in the deck and swap the two Cards.
- A dealCard function that returns the next Card object from the deck.
- A moreCards function that returns a bool value indicating whether there are more Cards to deal.
The driver program deals a five-card poker hand, and calls the utility functions to determine the status of the cards.
The utility module contains functions to accomplish each of the following:
- Determine whether the hand contains a pair.
- Determine whether the hand contains two pairs.
- Determine whether the hand contains three of a kind (e.g., three jacks).
- Determine whether the hand contains four of a kind (e.g., four aces).
- Determine whether the hand contains a flush (i.e., all five cards of the same suit).
- Determine whether the hand contains a straight (i.e., five cards of consecutive face values).
Project organization:- Class Card and class DeckOfCards are declared in two header files. They are also implemented in two modules.
- The utility module should consists a header file and a source file.
- The driver program should contain the main function.
- The configuration file should be generated by the autoconf and automake tools.
- The tutorial should contain three sections:
- The key points of implementing the program.
- The tutorial about how to generate the configuration script.
- The tutorial about how a user builds the program.
歡迎光臨 伊莉討論區 (http://a401.file-static.com/) |
Powered by Discuz! |