ALSO I CAN\'T USE ARRAYS OR VECTOR THANK YOU. The purpose of this challenge is t
ID: 3591211 • Letter: A
Question
ALSO I CAN'T USE ARRAYS OR VECTOR THANK YOU.
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.
Arrays or Vectors
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):
Explanation / Answer
---------------Christmas.cpp---------------
#include <iostream>
#include <sstream>
using namespace std;
void show_ordinal(int a){
string num;
stringstream out;
out << a;
num = out.str();
if(a==11 || a==12){
num += "th";
}else{
switch(a%10){
case 1: num+="st"; break;
case 2: num+="nd"; break;
case 3: num+="rd"; break;
default: num+="th";
}
}
cout << num;
}
void show_verse(int a){
cout << "On the "; show_ordinal(a); cout << " day of Christmas," << endl;
cout << "My true love gave to me," << endl;
if(a>=12){cout << "12 drummers drumming," << endl;}
if(a>=11){cout << "11 pipers piping," << endl;}
if(a>=10){cout << "10 lords-a-leaping," << endl;}
if(a>=9){cout << "9 ladies dancing," << endl;}
if(a>=8){cout << "8 maids-a-milking," << endl;}
if(a>=7){cout << "7 swans-a-swimming," << endl;}
if(a>=6){cout << "6 geese-a-laying," << endl;}
if(a>=5){cout << "5 golden rings," << endl;}
if(a>=4){cout << "4 colly birds," << endl;}
if(a>=3){cout << "3 french hens," << endl;}
if(a>=2){cout << "2 turtle doves," << endl;}
if(a>=1){
if(a==1){
cout << "A";
}else{
cout << "And a";
}
cout << " partridge in a pear true." << endl;
}
cout << endl;
}
int main(){
for(int i=1;i<=12;i++){
show_verse(i);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.