#include "food_chain.h" namespace food_chain { using namespace std; #define VERSE_TABLE \ X(Fly, "fly", "") \ X(Spider, "spider", "It wriggled and jiggled and tickled inside her.\n") \ X(Bird, "bird", "How absurd to swallow a bird!\n") \ X(Cat, "cat", "Imagine that, to swallow a cat!\n") \ X(Dog, "dog", "What a hog, to swallow a dog!\n") \ X(Goat, "goat", "Just opened her throat and swallowed a goat!\n") \ X(Cow, "cow", "I don't know how she swallowed a cow!\n") \ X(Horse, "horse", "She's dead, of course!\n") #define X(a, b, c) a, enum Verse { VERSE_TABLE }; #undef X #define X(a, b, c) b, static const char *food_name[] = { VERSE_TABLE }; #undef X #define X(a, b, c) c, static const char *verse_phrase[] = { VERSE_TABLE }; #undef X string verse(int index) { string result; --index; result += string("I know an old lady who swallowed a ") + food_name[index] + ".\n" + verse_phrase[index]; if (index != Verse::Horse) { for (int i = index; i > Verse::Fly; --i) { result += string("She swallowed the ") + food_name[i] + " to catch the " + food_name[i-1]; if (i == Verse::Bird) result += string(" that wriggled and jiggled and " "tickled inside her"); result += string(".\n"); } result += "I don't know why she swallowed the fly. " "Perhaps she'll die.\n"; } return result; } string verses(int from_index, int to_index) { string result; for (int i = from_index; i <= to_index; ++i) result += verse(i) + '\n'; return result; } string sing() { return verses(1, 8); } }