food_chain: variables are renamed

This commit is contained in:
Dmitry Kokorin 2016-02-29 23:53:09 +03:00
parent c80a6294e1
commit 83939d8584

View file

@ -1,12 +1,10 @@
#include "food_chain.h"
#include <string>
namespace food_chain {
using namespace std;
#define ANIMAL_TABLE \
#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") \
@ -17,20 +15,20 @@ 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 Animal {
ANIMAL_TABLE
enum Verse {
VERSE_TABLE
};
#undef X
#define X(a, b, c) b,
static const char *animal_name[] = {
ANIMAL_TABLE
static const char *food_name[] = {
VERSE_TABLE
};
#undef X
#define X(a, b, c) c,
static const char *verse_phrase[] = {
ANIMAL_TABLE
VERSE_TABLE
};
#undef X
@ -42,20 +40,20 @@ string verse(int index)
--index;
result += string("I know an old lady who swallowed a ")
+ animal_name[index]
+ food_name[index]
+ ".\n"
+ verse_phrase[index];
if (index != Animal::Horse) {
if (index != Verse::Horse) {
for (int i = index; i > Animal::Fly; --i) {
for (int i = index; i > Verse::Fly; --i) {
result += string("She swallowed the ")
+ animal_name[i]
+ food_name[i]
+ " to catch the "
+ animal_name[i-1];
+ food_name[i-1];
if (i == Animal::Bird)
if (i == Verse::Bird)
result += string(" that wriggled and jiggled and "
"tickled inside her");