Please also review and follow one additional guideline that may be relevant to this lab: B.18 (copy constructor and assignment operator).
Note: the details of this assignment are again intentionally somewhat under-specified, leaving you some room to choose what you think is the best way to implement them, as long as what you do is reasonable and you explain your design decisions in comments in the code and in your Readme.txt file.
Deck
) to represent a
deck of cards, with a private
member variable that is an STL-supplied random access sequence container
containing the card type you created in your
previous labs
(e.g., of type vector<Card>
but not list<Card>
).
The public interface for
this deck class should be:
Card
) corresponding to them into the
container member variable. Feel free to reuse or modify code from your previous
labs in your implementation of this method.As in the previous labs, if the input file cannot be opened an appropriate error message should be printed and the entire program should terminate and return a non-zero value to indicate failure. Since this method is called from the deck class constructor, and since constructors don't have return values, if this method fails it should either throw an exception which the constructor allows to propagate upward and the main function catches and handles, or this method could return an appropriate non-zero value, which the constructor then detects and throws, etc.
shuffle
algorithm (with begin and end iterators
for the entire range of elements in the container and a callable object that
returns random numbers, per the example in the C++ reference page for the shuffle
algorithm noted above).
operator<<
) that takes a
reference to an ostream and a reference to a const deck object, and uses the
passed ostream to print out valid card definition strings on separate lines,
for each card in the deck object's container member variable. Note that your
implementation may use a friend declaration to grant this operator access to
the deck object's private container member variable.
Hand
) to
represent a card player's hand of cards. This class should have
a private
member variable that is an STL-supplied container of cards
(e.g., of type vector<Card>
or
list<Card>
). The public interface for
this class should be:
operator<<
) that takes a
reference to an ostream and a reference to a const hand object, and uses the
passed ostream to print out space-separated valid card definition strings on
the same line,
for each card in the hand object's container member variable. Note that your
implementation may use a friend declaration to grant this operator access to
the hand object's private container member variable.
operator<<
) that takes a
reference to a hand object and a reference to a deck object, removes the card from
the back of the deck object's container member variable, and adds it to the hand
object's container member variable in such a manner that
the cards in the hand object are kept in sorted order (according to the card's
less than operator). Note that depending on which STL container you used,
either pushing back and then sorting (e.g., for vector
or
list
) or iterating until the right spot is reached and then
inserting (e.g., for list
but not vector since that would result
in an inefficient re-copying of stored values) are reasonable approaches.
Note that your implementation may use friend declarations to grant this
operator access to the hand object's and deck object's private member variables.
vector<Hand>
or list<Hand>
).
sort
algorithm to order the hands
in the container (according to the hand class less than operator which is what it
will do if you just call it with the begin and end iterator positions of the container),
and then again print out the hand objects in the order they now appear in the container.
sort
algorithm to order the hands
in the container, but this time it should do so according to the poker hand ranking
function you defined (see above) by passing the name of that function as a third
parameter to the sort algorithm; the program should then again print out the hand
objects in the order they now appear in the container.
Send the zip file containing your lab 2 solution as an e-mail attachment to the course e-mail account (cse332@seas.wustl.edu) so that it arrives by the submission deadline for this assignment. If you need to make changes to your lab solution you are welcome to send a new zip file, and we will grade the latest one received prior to the deadline (according to the receipt time stamp the server puts on the e-mail).