Challenge 5

Description

The purpose of this challenge is to employ the use of basic functions. This challenge will display the lyrics to the Twelve Days of Christmas.

Do Not Use

Arrays or Vectors

Requirements

  1. You may have heard the classic Christmas song that goes like this:
    On the 1st day of Christmas,
    My true love gave to me,
    A partridge in a pear tree.
    
    On the 2nd day of Christmas, 
    My true love gave to me, 
    2 turtle doves,
    And a partridge in a pear tree.
    
    On the 3rd day of Christmas,
    My true love gave to me,
    3 french hens,
    2 turtle doves,
    And a partridge in a pear tree. 
    
    On the 4th day of Christmas,
    My true love gave to me,
    4 colly birds,
    3 french hens,
    2 turtle doves,
    And a partridge in a pear tree
    
    …and so on…
    
    The complete and final verse is: 
    
    On the 12th day of Christmas,
    My true love gave to me,
    12 drummers drumming,
    11 pipers piping,
    10 lords-a-leaping,
    9 ladies dancing,
    8 maids-a-milking,
    7 swans-a-swimming,
    6 geese-a-laying,
    5 golden rings,
    4 colly birds,
    3 french hens,
    2 turtle doves,
    And a partridge in a pear tree.
    
    
  2. Write a program that will display the complete lyrics of the song.
  3. The final output will display all twelve verses. Do not prompt the user to display only one verse.
  4. Create a function that will display a number with its ordinal suffix, show_ordinal(int). It will take a single integer parameter. It will output to the screen the number with its suffix. For example, if you call show_ordinal(5), it will output 5th. Remember that 11 and 12 are special cases if you choose to use modulo division by 10. It’s ok to use cout in this function since that’s what it’s supposed to do.
  5. Create a function, show_verse(int), that will display a single verse. If you pass in 3, it will display the third verse counting down from 3 french hens, down to the partridge in a pear tree. Don’t forget the beginning of the verse: “On the xx day of Christmas, my true love gave to me..”. Do not hard-code each verse in the function for display.
  6. Call the show_verse() function-from step #5 above-in a loop to display all 12 verses
  7. Remember to add a blank line after each verse
  8. Remember that the 1st verse is special in that it says “and a partridge in a pear tree”. There is no and.

Extra Challenge

At the start of the program, ask the user a choice of displaying numeric or descriptive words in the verse. Then based on the user’s choice, display the lyric.

You will have to create two new functions show_num_text(int) and show_ordinal_text(int). When this function is called as show_ordinal_text(1), it will output first instead of 1st, second instead of 2nd, and so on. show_num_text(3) will output the word three, instead of the number 3, for example.

The descriptive output of the lyric then becomes (sample excerpt below):

On the third day of Christmas, 
my true love gave to me, 
three French hens,
two turtle doves,
and a partridge in a pear tree.

LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT

CATALOG ID: CPP-CHAL0005

Print Requirements