/* dryBones.cpp displays the lyrics of the song "Dry Bones."
 *
 * Output: lyrics of "Dry Bones"
 ****************************************************************/

#include <iostream>                         // cin, cout, <<, >>
#include <string>                           // string class
using namespace std;

void printChorus(const string& variation);
void printLastLine();
void printBoneLyrics(const string & bone);

int main()
{
  printChorus("Ezekiel cried, \"Dem dry bones!\"\n");
  printBoneLyrics("foot");
  printLastLine();
  printChorus("Dem bones, dem bones gonna walk aroun'\n");
}

/* printChorus displays the lyrics of the chorus of the song, of
 * which there are two variations.
 *
 * Receive: variation, a string
 * Output:  the chorus with the specified variation.
 ****************************************************************/

void printChorus(const string& variation)
{
   cout << variation << variation << variation;
   printLastLine();
}

/* printLastLine displays the last line of each verse and the chorus.
 *
 * Output:  the last line
 ****************************************************************/

void printLastLine()
{
   cout << "Oh, hear the word of the Lord!\n\n";
}

/* printBoneLyrics displays the lyrics for a given bone.
 *
 * Receive: bone, a string.
 * Output:  the lyrics for that bone and (recursively) the lyrics
 *          for the bones "beneath" it (during winding) and then
 *          for the bones "above" it (during unwinding).
 ****************************************************************/

string getNext(const string& aBone);

void printBoneLyrics(const string& bone)
{
   if (bone == "head")                   // Anchor: bone == head
                                         //  sing chorus variation
      printChorus("Dem bones, dem bones gonna walk aroun'\n");

   else
   {                                     // Ind-Step: bone < head
      string nextBone = getNext(bone);   //  find next body part

      cout << "The " << bone             //  do 'upward' lyric
           << " bone connected to the "  //  before recursion
           << nextBone << " bone,\n";    //  (winding)

      printBoneLyrics(nextBone);         //  do rest recursively

      cout << "The " << nextBone         //  do 'downward' lyric
           << " bone connected to the "  //  after recursion
           << bone << " bone,\n";        //  (unwinding)
   }
}

/* getNext() gets the next bone.
 *
 * Receive:      aBone, a string.
 * Precondition: aBone is a valid bone (in the song).
 * Return:       the bone above aBone.
 ****************************************************************/

string getNext(const string& aBone)
{
   if (aBone == "foot")
      return "leg";
   else if (aBone == "leg")
      return "knee";
   else if (aBone == "knee")
      return "thigh";
   else if (aBone == "thigh")
      return "back";
   else if (aBone == "back")
      return "neck";
   else if (aBone == "neck")
      return "head";
   else
      cerr << "\n*** GetNext(): "
           << aBone << " is unknown!" << endl;
   return "";
}

