Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please explain each line of code, I want to each line of code. In the final exam question can form from any line . Please

Please explain each line of code, I want to each line of code. In the final exam question can form from any line . Please focus on the details inside the function specially

// final.cpp *preparation version* Copyright (c) 2023 #include

/* **** Start of lines from file DaysOfChristmas_smallCode.cpp **** */ // Assignment 3: DaysOfChristmas_smallCode.cpp sample solution // Copyright (c) 2023 Katy Liu, Dominic Maddalozzo, and W. Craig Scratchley // Should occupy 522 bytes if you remove comments and any allowable whitespace.

// preprocessor # directives must each be on their own line #include // Includes most if not all C++ header files, including // #include // #include

// A preprocessor macro for inserting onto std::cout -- whitespace on next line needed #define C std::cout<< int /*whitespace*/ d, q; // day and quantity counters -- here each default to 0 std::vector /* must leave whitespace here */ s { "st", "nd", "rd" }, // suffixes for first 3 ordinal numbers g { "a Partridge in a Pear Tree", "Turtle Doves and ", "French Hens", "Calling Birds", "Golden Rings", "Geese a Laying", "Swans a Swimming", "Maids a Milking", "Ladies Dancing", "Lords a Leaping", "Pipers Piping", "Drummers Drumming" }; // gifts void DaysOfChristmas_smallCode() // ..() is the same as ..( void ) { C "The 12 Days of Christmas"; // macro C is expanded here and other locations while (d < 12) { C " On the " << d + 1 << (d < 3 ? s[d] : "th") << " day of Christmas my true love sent to me:"; if (!d) C " "; for (q = ++d; q;) q - 1 ? C " " << q << " " : C "", C /*whitespace*/ g[--q]; // comma operator at top level of expression } } /* **** End of lines from file DaysOfChristmas_smallCode.cpp **** */

// The below is Copyright (c) 2023 W. Craig Scratchley using namespace std;

void processGift(const int &day) { static int count; count += 1; cout << fmt::format("{:>2} {} ", day, g.at(day - 1)); }

inline void DaysOfChristmas_switch2 (int dayLimit = 6 ) { // This function outputs to standard output the lyrics for "The X Days of Christmas".

cout << "The " << dayLimit << " Days of Christmas" << flush; // Title for (int day{1}; day <= dayLimit; ++day) { cout << " On the " << day << flush;

// Determining day's ordinal suffix ie. st, nd, rd depending on day switch (day) { case 1: cout << "st" << flush; break; case 2: cout << "nd" << flush; break; case 3: cout << "rd" << flush; break; default: cout << "th" << flush; }

cout << " day of Christmas my true love sent to me: " << flush;

switch (day) { // note starting at case 6 here case 6: processGift(12); // note 12 as argument [[fallthrough]]; case 5: processGift(5); [[fallthrough]]; case 4: processGift(4); [[fallthrough]]; case 3: processGift(3); [[fallthrough]]; case 2: cout << " 2 Turtle Doves and " << flush; [[fallthrough]]; case 1: cout << g.at(1 - 1) << flush; } } }

int main( ) { cout << "a) q is " << q << endl; // don't let the debugger trick you constexpr long long q{1}; try { cout << "b) q is " << q << endl; // don't let the debugger trick you const double q{2.2}; cout << "c) q is " << q << endl; array s; // 'a' is an example literal for datatype char for (char q{'a'}; auto &e : s) // Not a syntax error e = q++; cout << "s[10][0] is " << s[10][0] << endl; cout << std::accumulate(begin(s), end(s), ""s) << endl;

cout << " The gifts are: "; cout << std::accumulate(rbegin(g), rend(g), ""s, // iterators rbegin and rend are 'reverse' iterators [](const auto& x, const auto& y){return x + (y[0]=='a'?"":" ") + y;} );

cout << " "; DaysOfChristmas_smallCode( );

cout << " "; DaysOfChristmas_switch2();

cout << " "; processGift(13); } catch (const std::out_of_range& ex) { cout << "An exception occurred: " << ex.what() << ' '; return 3; }

return q; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

5-8 What are the advantages and disadvantages of the BYOD movement?

Answered: 1 week ago