Project 0 - War Card game

Project 0 - War Card game - Robert J. England II COS 221...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Robert J. England II COS 221 Project 0 War Card Game Project done for Prof. Larry Latour Monday, September 25, 2006
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The following is the actual code used in the program. The bulk of the code came with the original program; I added the PRE and POST comments and the Test class. // // WAR card game // // Described in Chapter 2 of // Data Structures in C++ using the STL // Published by Addison-Wesley, 1997 // Written by Tim Budd, budd@cs.orst.edu // Oregon State University // // Edited by Robert J. England II // (Comments and Test class added) // for COS 221 with Larry Latour // at the University of Maine // Monday, September 25, 2006 #include "stdafx.h" #include <iostream> #include <algorithm> using namespace std; enum suits {diamond, club, heart, spade}; class Card { public : // constructors Card ( ); // POST: A new card, the ace of spades, // is created. Card (suits, int ); // PRE: 0 < rv < 14 // POST: A new card is created with suit sv // and rank rv. // data fields int rank; // hold rank of card suits suit; // hold suit of card }; Card::Card ( ) // POST: A new card, the ace of spades, // is created. { rank = 1; suit = spade; } Card::Card (suits sv, int rv) // PRE: 0 < rv < 14 // POST: A new card is created with suit sv // and rank rv. { rank = rv; suit = sv;
Background image of page 2
} ostream & operator // POST: The information about a card is printed // to the screen, and the original ostream is // returned. { // first output rank switch (aCard.rank) { case 1: out << "Ace" ; break ; case 11: out << "Jack" ; break ; case 12: out << "Queen" ; break ; case 13: out << "King" ; break ; default : // output number out << aCard.rank; break ; } // then output suit switch (aCard.suit) { case diamond: out << " of Diamonds" ; break ; case spade: out << " of Spades" ; break ; case heart: out << " of Hearts" ; break ; case club: out << " of Clubs" ; break ; } return out; } class randomInteger { public : unsigned int operator () ( unsigned int ); // POST: A random integer between 0 and max is returned. // The same sequence of integers is returned every runtime. } randomizer; unsigned int randomInteger:: operator () ( unsigned int max) // POST: A random integer between 0 and max is returned. // The same sequence of integers is returned every runtime. { unsigned int rval = rand(); return rval % max; } class Deck { public : // constructor Deck ( ); // POST: A standard, unshuffled deck of 52 cards is created. // operations void shuffle ( ) // PRE: The deck is still full // POST: The deck is randomly shuffled { random_shuffle (cards, cards+52, randomizer); } bool isEmpty ( ) // POST: True is returned if the deck is empty; otherwise // false is returned { return topCard <= 0; }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Card draw ( ); // PRE: The deck must still have cards. // POST: If the deck still has cards left, the top card is
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

Project 0 - War Card game - Robert J. England II COS 221...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online