Sha256: b384199811bf8fff893ace4f57f642372261cd37201c01fcd26b1814ce0828a9
Contents?: true
Size: 1.69 KB
Versions: 396
Compression:
Stored size: 1.69 KB
Contents
#include "beer_song.h" #include <sstream> using namespace std; namespace beer { namespace { struct bottles { bottles(unsigned num) : count(num), suffix(num > 1 ? "s" : "") {} unsigned const count; string const suffix; }; ostream& operator<<(ostream& stream, bottles const& b) { if (b.count) { stream << b.count << " bottle" << b.suffix; } else { stream << "no more bottles"; } return stream << " of beer"; } void bottles_of_beer_on_the_wall(ostream& stream, unsigned count) { if (count) { stream << bottles(count) << " on the wall, " << bottles(count) << ".\n"; } else { stream << "No more bottles of beer on the wall, " << bottles(count) << ".\n"; } } void take_one_down_and_pass_it_around(ostream& stream, unsigned count) { if (count > 1) { stream << "Take one down and pass it around, " << bottles(count - 1) << " on the wall.\n"; } else if (count) { stream << "Take it down and pass it around, " << bottles(count - 1) << " on the wall.\n"; } else { stream << "Go to the store and buy some more, 99 bottles of beer on the wall.\n"; } } void verse(ostream& stream, unsigned count) { bottles_of_beer_on_the_wall(stream, count); take_one_down_and_pass_it_around(stream, count); } } string verse(unsigned num) { ostringstream stream; verse(stream, num); return stream.str(); } string sing(unsigned begin, unsigned end) { ostringstream stream; for (unsigned num = begin; num > end; --num) { verse(stream, num); stream << '\n'; } verse(stream, end); return stream.str(); } string sing(unsigned num) { return sing(num, 0); } }
Version data entries
396 entries across 396 versions & 1 rubygems