Created
December 16, 2021 12:52
-
-
Save saxbophone/ae312a77cc3280c61d69b5943ea07d8c to your computer and use it in GitHub Desktop.
On the twelfth day of Christmas, my true love sent to me: A program written in CPP!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <array> | |
#include <iostream> | |
#include <string> | |
#include <cstddef> | |
std::array<std::string, 12> ORDINAL_DAYS = { | |
"first", | |
"second", | |
"third", | |
"fourth", | |
"fifth", | |
"sixth", | |
"seventh", | |
"eighth", | |
"ninth", | |
"tenth", | |
"eleventh", | |
"twelfth", | |
}; | |
std::array<std::string, 12> MY_TRUE_LOVE_GAVE_TO_ME = { | |
"A partridge in a pear tree", | |
"Two turtle doves", | |
"Three French hens", | |
"Four calling birds", | |
"FIVE GOLD RINGS", | |
"six geese a-laying", | |
"seven swans a-swimming", | |
"eight maids a-milking", | |
"nine ladies dancing", | |
"ten lords a-leaping", | |
"eleven pipers piping", | |
"twelve drummers drumming", | |
}; | |
std::string on_the_nth_day_of_christmas(std::size_t day) { | |
std::string verse = "On the " + ORDINAL_DAYS[day] + " day of Christmas my true love sent to me\n"; | |
for (std::size_t d = day + 1; d --> 0;) { | |
if (day > 0 and d == 0) { | |
verse += "And "; | |
} | |
verse += MY_TRUE_LOVE_GAVE_TO_ME[d]; | |
if (d != 0) { | |
verse += ",\n"; | |
} | |
} | |
return verse; | |
} | |
int main() { | |
for (std::size_t day = 0; day < 12; day++) { | |
std::cout << on_the_nth_day_of_christmas(day) << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment