CMIS 315, I have attached files the professor had included with the assignment.
CodeFiles/.DS_Store
__MACOSX/CodeFiles/._.DS_Store
CodeFiles/card.cpp
#include "card.h" #include <iostream> using namespace std; ostream& operator<<( ostream &stream, const Card &card ) { stream << Card::rank_str[ card.rank ] << " of " << Card::suit_str[ card.suit ]; return stream; }
__MACOSX/CodeFiles/._card.cpp
CodeFiles/card.h
#ifndef CARD_H #define CARD_H #include <iostream> using namespace std; class Card { friend ostream& operator<<( ostream &stream, const Card &card ); public: private: static char *suit_str[4]; // output strings for suit static char *rank_str[14]; // output strings for rank }; #endif
__MACOSX/CodeFiles/._card.h
CodeFiles/deck.cpp
#include "deck.h" #include <iostream> #include <ctime> using namespace std; void StandardDeck::shuffle() { for (Uint i=0; i < deck.size()-1; i++) swap( deck[i], deck[ r.rand(i,deck.size()-1) ] ); top = 0; } void StandardDeck::swap( Card &c1, Card &c2 ) { Card temp = c1; c1 = c2; c2 = temp; }
__MACOSX/CodeFiles/._deck.cpp
CodeFiles/deck.h
#ifndef DECK_H #define DECK_H #include <vector> #include "card.h" #include "rands.h" class StandardDeck { public: void shuffle(); // shuffle the deck private: vector<Card> deck; // the deck of cards Rands r; // random numbers used for shuffling void swap( Card &, Card & ); // used for shuffling }; #endif
__MACOSX/CodeFiles/._deck.h
CodeFiles/hand.h
#ifndef HAND_H #define HAND_H #include <vector> #include "card.h" class Hand { public: private: }; #endif
__MACOSX/CodeFiles/._hand.h
CodeFiles/rands.cpp
#include "rands.h" Rands::Rands() { SEED_X = 521288629; // default seeds SEED_Y = 362436069; // default seeds } void Rands::rand_seed( Uint seed ) { if (seed == 0) return; // use default seeds; SEED_X = seed; // use a good linear congruential generator to get second seed SEED_Y = 16807*(seed%127773) - 2836*(seed/127773); } Uint Rands::rand() { /* Use any pair of non-equal numbers from this list for "a" and "b" 18000 18030 18273 18513 18879 19074 19098 19164 19215 19584 19599 19950 20088 20508 20544 20664 20814 20970 21153 21243 21423 21723 21954 22125 22188 22293 22860 22938 22965 22974 23109 23124 23163 23208 23508 23520 23553 23658 23865 24114 24219 24660 24699 24864 24948 25023 25308 25443 26004 26088 26154 26550 26679 26838 27183 27258 27753 27795 27810 27834 27960 28320 28380 28689 28710 28794 28854 28959 28980 29013 29379 29889 30135 30345 30459 30714 30903 30963 31059 31083 */ static Uint a = 18000, b = 30903; // Marsaglia's favorite pair SEED_X = a*(SEED_X&65535) + (SEED_X>>16); SEED_Y = b*(SEED_Y&65535) + (SEED_Y>>16); return ((SEED_X<<16) + (SEED_Y&65535)); } double Rands::rand_float() { return (double)rand() / 4294967296.0; } int Rands::rand( int lo, int hi ) { return (rand() % (hi - lo + 1)) + lo; }
__MACOSX/CodeFiles/._rands.cpp
CodeFiles/rands.h
/******************************************************************/ /* concatenation of the two 16-bit multiply with carry generators */ /* x(n)=a*x(n-1)+carry mod 2^16 and y(n)=b*y(n-1)+carry mod 2^16, */ /* with the number and carry packed within the same 32 bit */ /* integer. Algorithm due to Marsaglia */ /******************************************************************/ #ifndef RANDS_H #define RANDS_H typedef unsigned int Uint; class Rands { public: Rands(); void rand_seed( Uint ); // seed the generator Uint rand(); // returns a random 32-bit integer double rand_float(); // returns a random float in (0,1] int rand( int lo, int hi ); // returns a random int from lo through hi private: Uint SEED_X; Uint SEED_Y; }; #endif