#include #include "coin.h" using namespace std; // constructors Coin::Coin() : randNumGen(), tossed(false) { } Coin::Coin(int seed) : randNumGen(seed), tossed(false) { } // public accessing functions bool Coin::Heads() // precondition: coin has been tossed at least once // postcondition: returns true if last toss turned up heads { if ( tossed ) return showingHeads; } bool Coin::Tails() // precondition: coin has been tossed at least once // postcondition: returns true if last toss turned up tails { if ( tossed ) return not showingHeads; } // public modifying functions void Coin::Toss() // postcondition: 50/50 chance that Heads is true { tossed = true; showingHeads = (randNumGen.RandInt(0, 1) == 1); }