Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that outputs the lyrics for the song “Ninety-Nine Bottles of Bee

ID: 675025 • Letter: W

Question

Write a program that outputs the lyrics for the song “Ninety-Nine Bottles of Beer on the Wall.” Your program should print the number of bottles in English, not as a number. For example:

Ninety-nine bottles of beer on the wall, Ninety-nine bottles of beer, Take one down, pass it around, Ninety-eight bottles of beer on the wall. … One bottle of beer on the wall, One bottle of beer, Take one down, pass it around, Zero bottles of beer on the wall. Design your program with a function that takes as an argument an integer between 0 and 99 and returns a string that contains the integer value in English. Your function should not have 100 different if-else statements! Instead, use % and / to extract the tens and ones digits to construct the English string. You may need to test specifically for values such as 0, 10–19, etc.

I need c++ code

Explanation / Answer


/**C++ program that prints the beer song of user specified
number of beers .*/
#include<iostream>
#include<string>
using namespace std;

//function prototype
void displaySong(int n) ;
void displaySongLine(int n) ;
void convertToString(int n);

int main()
{

   //set number of bottles to print beer song
   int numBottles=10;

   //cal the method displaySong with input bottle count
   displaySong(numBottles) ;

   system("pause");
   return 0;
}

/**Convert places values in the bottles number into english words*/
void convertToString(int bottles)
{
   //get tens place value
   int tenPlace = bottles/10;
   //get one place value
   int>    //declare two string variables to write the equivalent ones and tens place values
   //in english
   string tenPlaceInEnglish ;
   string onesPlaceInEnglish ;


   switch (tenPlace)
   {  

   case 0:
      ;
       break;
   case 1:
       switch (onePlace)
       {
       case 0:
          ;
           break;
       case 1:
          ;
           break;
       case 2:
          ;
           break;
       case 3:
          ;
           break;
       case 4:
          ;
           break;
       case 5:
          ;
           break;
       case 6:
          ;
           break;
       case 7:
          ;
           break;
       case 8:
          ;
           break;
       case 9:
          ;
           break;
       }
       break;

   case 2:
       tenPlaceInEnglish = "Twenty";
       break;
   case 3:
       tenPlaceInEnglish = "Thirty";
       break;
   case 4:
       tenPlaceInEnglish = "Forty";
       break;
   case 5:
       tenPlaceInEnglish = "Fifty";
       break;
   case 6:
       tenPlaceInEnglish = "Sixty";
       break;
   case 7:
       tenPlaceInEnglish = "Seventy";
       break;
   case 8:
       tenPlaceInEnglish = "Eighty";
       break;
   case 9:
       tenPlaceInEnglish = "Ninety";
       break;
   }      
   if (tenPlace != 1)
   {
       switch (onePlace)
       {
       case 1:
          ;
           break;
       case 2:
          ;
           break;
       case 3:
          ;
           break;
       case 4:
          ;
           break;
       case 5:
          ;
           break;
       case 6:  
          ;
           break;
       case 7:
          ;
           break;
       case 8:
          ;
           break;
       case 9:
          ;
           break;
       }

   }

   cout<<tenPlaceInEnglish+" " + onesPlaceInEnglish + " ";

}

/**The method displaySongLine that takes number , n as input
argument and call the method convertToString with n value
that prints the tens and ones place values in string and
print songs line for */
void displaySongLine(int n)
{
   // output n in English
   convertToString(n);
   // account for "one bottle" vs. many "BOTTLES"
   if (n == 1)
       cout<<"bottle of beer on the wall, "<<endl;
   else
       cout<<"bottles of beer on the wall, "<<endl;
   convertToString(n);

   if (n == 0)
       cout<<"bottle of beer, "<<endl;
   else
       cout<<"bottles of beer,"<<endl;
      
       cout<<"Take one down, pass it around,"<<endl;
       //subtract one from n value
   n=n-1;
   convertToString(n);    
   if (n == 0)
       cout<<"bottle of beer on the wall."<<endl;
   else
       cout<<"bottles of beer on the wall."<<endl;
  
   cout<<endl;
}


/*Method that calls the displaySongLine that takes the number of
bottles in each line of song*/
void displaySong(int bottles)
{  
   for (int num = bottles; num > 0; num--)
   {
       displaySongLine(num);
   }
}

------------------------------------------------------------------------------------------------------------------------------

Sample Output:

Ten bottles of beer on the wall,
Ten bottles of beer,
Take one down, pass it around,
Nine bottles of beer on the wall.

Nine bottles of beer on the wall,
Nine bottles of beer,
Take one down, pass it around,
Eight bottles of beer on the wall.

Eight bottles of beer on the wall,
Eight bottles of beer,
Take one down, pass it around,
Seven bottles of beer on the wall.

Seven bottles of beer on the wall,
Seven bottles of beer,
Take one down, pass it around,
Six bottles of beer on the wall.

Six bottles of beer on the wall,
Six bottles of beer,
Take one down, pass it around,
Five bottles of beer on the wall.

Five bottles of beer on the wall,
Five bottles of beer,
Take one down, pass it around,
Four bottles of beer on the wall.

Four bottles of beer on the wall,
Four bottles of beer,
Take one down, pass it around,
Three bottles of beer on the wall.

Three bottles of beer on the wall,
Three bottles of beer,
Take one down, pass it around,
Two bottles of beer on the wall.

Two bottles of beer on the wall,
Two bottles of beer,
Take one down, pass it around,
One bottles of beer on the wall.

One bottle of beer on the wall,
One bottles of beer,
Take one down, pass it around,
zero bottle of beer on the wall.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote