Weekly Quiz number: 50

Solve the quiz and collect tokens!

Type your nickname in the field below before submitting your solution. If you select the correct answer and submit it with your nick-name a token will be generated for you. Collect tokens and the corresponding nickname(s). If you get at least 10 of them you might be rewarded ;-)


Coding Quiz: Santa Claus and the [[fallthrough]] attribute

Ho ho ho! Santa Claus is developing an algorithm for gift distribution, and he's using C++17's [[fallthrough]] attribute to make his code extra nice!

Let's check it out!

Question: Santa Claus's Gift Distribution Switch

void distributeGifts(ChildBehavior childBehavior)
{
    switch (childBehavior)
    {
    case ChildBehavior::VeryGood:
        std::cout << "🎁 Big present!" << '\n';
        break;
    case ChildBehavior::Good:
        std::cout << "πŸͺ Cookies!" << '\n';
        [[fallthrough]];  // Santa Claus wants good children to also get candy
    case ChildBehavior::NeedsImprovement:
        std::cout << "🍬 Candy!" << '\n';
        break;
    case ChildBehavior::Naughty:
        std::cout << "πŸ”” Just a bell" << '\n';
        break;
    default:
        std::cout << "πŸ“‹ Check the list again!" << '\n';
    }
}

int main()
{
    distributeGifts(ChildBehavior::Good);
    return 0;
}

What will Santa Claus's program output when a child has been "good"?

πŸͺ Cookies!
πŸͺ Cookies! followed by 🍬 Candy!
πŸͺ Cookies! followed by 🍬 Candy! followed by πŸ“‹ Check the list again!
Compilation error - Santa Claus made a mistake with [[fallthrough]]

Santa Claus coding with C++

Interesting Links to Sharpen Your Knowledge During Advent

1. InnerSource Advent Calendar

by COSIS (Center of Excellence Open and InnerSource)

A delightful way to find out about great work happening across the InnerSource community at Bosch. Each door is dedicated to one project.

Link (Bosch internal only): https://bos.ch/innersource-advent-calendar

QR Code

2. Advent of Compiler Optimisations

By Matt Godbolt

Matt demonstrates and explains a compiler optimisation or code generation trick each day.

YouTube Playlist: https://bos.ch/advent-of-compiler

QR Code

3. Advent of Code

By Eric Wastl

Widely known and very popular! Small programming puzzles for a variety of skill levels that can be solved in any programming language you like.

Link: https://adventofcode.com/

Want to level up your and your team's software craftsmanship?

We work hands-on with your actual codebase.

Visit https://bos.ch/sw-coaching


Make sure your nickname contains at least 8 characters and is a unique as possible.




Disclaimer: