Challenge: Output with Lambda Expressions

Complete this hands-on exercise to test your knowledge.

Problem statement

Write a C++20 program that defines a function braces that returns a lambda function which takes a parameter v and returns a string composed of the characters a, v, and b. The main function should then create four such lambda functions using different pairs of characters for a and b: ( and ), [ and ], { and }, and | and |.

It should loop over the integers from 11 to nn (inclusive), where nn is an integer provided by the user. It should then apply each of the four lambda functions to each integer, printing the resulting string on a single line, with spaces between the strings and a newline at the end of each line.

Input

The user is prompted to enter an integer nn, which represents the maximum integer value to apply the lambda functions.

Get hands-on with 1200+ tech skills courses.