CS10L - Laboratory Exercise #5 - 2nd Term - 20122013

Problem Statement: "The Twelve Days of Christmas" is a cumulative song, meaning that each verse is built on top of the previous verses. There are twelve verses, each describing a gift given by "my true love" on on of the twelve days of Christmas.
...and so forth, until the last verse:
On the twelve 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 Geeese-a-Laying
5 Gold Rings
4 Colly Birds
3 French Hens
2 Turtle Doves
And a Partridge in a Pear Tree.
 
Create a program that accepts the day of Christmas and displays the given in each day cumulatively.
 
Sample output:
 
***Twelve Days of Christmas**
Enter day: 3
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
 
***Twelve Days of Christmas**
Enter day: 5
On the 3rd day of Christmas my true love gave to me...
5 Gold Rings
4 Colly Birds
3 French Hens
2 Turtle Doves
And a Partridge in a Pear Tree.
 
CODE:
 
/**
    Laboratory Exercise #5
    CS10-B5
   
    @author Red Berroy
*/
#include <iostream.h>
int main ()
{
 int day;
 //Variable names
 cout<<"***Twelve Days of Christmas***"<<endl;
 cout<<"Enter day: ";
 cin>>day;
 if ( !cin || (day < 0) ) //Checks for negative number
 {
  cout <<"Please enter numbers 1-12 only"<<endl;
 }
 else if ( day >=13 )
 {
  cout<<"Please enter numbers 1-12 only"<<endl;
 }
 else if ( day <= 0 ) 
 {
  cout<<"Please enter numbers 1-12 only"<<endl;
 }
 else if ( day==1 )
 {
  cout<<"On the 1st day of Christmas my true love gave to me..."<<endl;
  cout<<"Partridge in a Pear Tree."<<endl;
 }
 
 else if ( day==2 )
 {
  cout<<"On the 2nd day of Christmas my true love gave to me..."<<endl;
  cout<<"2 Turtle Doves"<<endl;
  cout<<"And a Partridge in Pear Tree."<<endl;
 }
 else if ( day==3 )
 {
  cout<<"On the 3rd day of Christmas my true love gave to me..."<<endl;
  cout<<"3 French Hens"<<endl;
  cout<<"2 Turtle Doves"<<endl;
  cout<<"And a Partridge in Pear Tree."<<endl;
 }
 else if ( day==4 )
 {
  cout<<"On the 4th day of Christmas my true love gave to me..."<<endl;
  cout<<"4 Colly Birds"<<endl;
  cout<<"3 French Hens"<<endl;
  cout<<"2 Turtle Doves"<<endl;
  cout<<"And a Partridge in Pear Tree."<<endl;
 }
 else if ( day==5 )
 {
  cout<<"On the 5th day of Christmas my true love gave to me..."<<endl;
  cout<<"5 Gold Rings"<<endl;
  cout<<"4 Colly Birds"<<endl;
  cout<<"3 French Hens"<<endl;
  cout<<"2 Turtle Doves"<<endl;
  cout<<"And a Partridge in Pear Tree."<<endl;
 }
 else if ( day==6 )
 {
  cout<<"On the 6th day of Christmas my true love gave to me..."<<endl;
  cout<<"6 Geese-a-Laying"<<endl;
  cout<<"5 Gold Rings"<<endl;
  cout<<"4 Colly Birds"<<endl;
  cout<<"3 French Hens"<<endl;
  cout<<"2 Turtle Doves"<<endl;
  cout<<"And a Partridge in Pear Tree."<<endl;
 }
 else if ( day==7 )
 {
  cout<<"On the 7th day of Christmas my true love gave to me..."<<endl;
  cout<<"7 Swans-a-Swimming"<<endl;
  cout<<"6 Geese-a-Laying"<<endl;
  cout<<"5 Gold Rings"<<endl;
  cout<<"4 Colly Birds"<<endl;
  cout<<"3 French Hens"<<endl;
  cout<<"2 Turtle Doves"<<endl;
  cout<<"And a Partridge in Pear Tree."<<endl;
 }
 else if ( day==8 )
 {
  cout<<"On the 8th day of Christmas my true love gave to me..."<<endl;
  cout<<"8 Maids-a-Milking"<<endl;
  cout<<"7 Swans-a-Swimming"<<endl;
  cout<<"6 Geese-a-Laying"<<endl;
  cout<<"5 Gold Rings"<<endl;
  cout<<"4 Colly Birds"<<endl;
  cout<<"3 French Hens"<<endl;
  cout<<"2 Turtle Doves"<<endl;
  cout<<"And a Partridge in Pear Tree."<<endl;
 }
 else if ( day==9 )
 {
  cout<<"On the 9th day of Christmas my true love gave to me..."<<endl;
  cout<<"9 Ladies Dancing"<<endl;
  cout<<"8 Maids-a-Milking"<<endl;
  cout<<"7 Swans-a-Swimming"<<endl;
  cout<<"6 Geese-a-Laying"<<endl;
  cout<<"5 Gold Rings"<<endl;
  cout<<"4 Colly Birds"<<endl;
  cout<<"3 French Hens"<<endl;
  cout<<"2 Turtle Doves"<<endl;
  cout<<"And a Partridge in Pear Tree."<<endl;
 }
 else if ( day==10 )
 {
  cout<<"On the 10th day of Christmas my true love gave to me..."<<endl;
  cout<<"10 Lords-a-Leaping"<<endl;
  cout<<"9 Ladies Dancing"<<endl;
  cout<<"8 Maids-a-Milking"<<endl;
  cout<<"7 Swans-a-Swimming"<<endl;
  cout<<"6 Geese-a-Laying"<<endl;
  cout<<"5 Gold Rings"<<endl;
  cout<<"4 Colly Birds"<<endl;
  cout<<"3 French Hens"<<endl;
  cout<<"2 Turtle Doves"<<endl;
  cout<<"And a Partridge in Pear Tree."<<endl;
 }
 else if ( day==11 )
 {
  cout<<"On the 11th day of Christmas my true love gave to me..."<<endl;
  cout<<"11 Pipers Piping"<<endl;
  cout<<"10 Lords-a-Leaping"<<endl;
  cout<<"9 Ladies Dancing"<<endl;
  cout<<"8 Maids-a-Milking"<<endl;
  cout<<"7 Swans-a-Swimming"<<endl;
  cout<<"6 Geese-a-Laying"<<endl;
  cout<<"5 Gold Rings"<<endl;
  cout<<"4 Colly Birds"<<endl;
  cout<<"3 French Hens"<<endl;
  cout<<"2 Turtle Doves"<<endl;
  cout<<"And a Partridge in Pear Tree."<<endl;
 }
 else if ( day==12 )
 {
  cout<<"On the 12th day of Christmas my true love gave to me..."<<endl;
  cout<<"12 Drummers Drumming"<<endl;
  cout<<"11 Pipers Piping"<<endl;
  cout<<"10 Lords-a-Leaping"<<endl;
  cout<<"9 Ladies Dancing"<<endl;
  cout<<"8 Maids-a-Milking"<<endl;
  cout<<"7 Swans-a-Swimming"<<endl;
  cout<<"6 Geese-a-Laying"<<endl;
  cout<<"5 Gold Rings"<<endl;
  cout<<"4 Colly Birds"<<endl;
  cout<<"3 French Hens"<<endl;
  cout<<"2 Turtle Doves"<<endl;
  cout<<"And a Partridge in Pear Tree."<<endl;
 }
 return 0;
}

0 comments:

Post a Comment

ADVERTISEMENT