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