#include #include "Doughnut.h" using namespace std; Doughnut::Doughnut() : m_donutType( BostonCream ), m_bitesLeft(6) { /* empty constructor body */ } Doughnut::Doughnut( dType doughnut ) : m_donutType( doughnut ), m_bitesLeft(6) { /* empty constructor body */ } Doughnut::dType Doughnut::getType() const { return m_donutType; } void Doughnut::dunk() const { dunk( "coffee" ); } void Doughnut::dunk( string drink ) const { if ( m_bitesLeft > 0 ) cout << "Dunking the doughnut in " << drink << "." << endl; else cout << "The doughnut is all gone!" << endl; } void Doughnut::bite() { if ( m_bitesLeft > 0 ) { m_bitesLeft--; if ( m_bitesLeft == 0 ) cout << "You took the last bite." << endl; } else { cout << "The doughnut is all gone!" << endl; } } bool operator< ( const Doughnut &d1, const Doughnut &d2 ) { return d1.getType() < d2.getType(); } bool operator> ( const Doughnut &d1, const Doughnut &d2 ) { return d1.getType() > d2.getType(); } ostream& operator<< (ostream& outStream, const Doughnut& d) { switch ( d.m_donutType ) { case Doughnut::Plain: outStream << "Plain"; break; case Doughnut::PowderedSugar: outStream << "Powdered Sugar"; break; case Doughnut::Cinnamon: outStream << "Cinnamon"; break; case Doughnut::Glazed: outStream << "Glazed"; break; case Doughnut::Chocolate: outStream << "Chocolate"; break; case Doughnut::Jelly: outStream << "Jelly"; break; case Doughnut::ChocolateFrosted: outStream << "Chocolate Frosted"; break; case Doughnut::Fudgie: outStream << "Fudgie"; break; case Doughnut::BostonCream: outStream << "Boston Cream"; break; default: outStream << "Mystery Doughnut"; } // outStream << " has " << d.m_bitesLeft << " bites left."; return outStream; }