Embercode
✕
C++ PatternsQuick quiz

Zigzag and tables

7 questions. Covers Aligned tables.

Questions 1 to 5 of 7

  1. 1. What does this program print? ``cpp #include <iostream> #include <string> #include <vector> std::string zigzag_convert(const std::string& text, int num_rows) { if (num_rows < 2) { return text; } std::vector<std::string> rows(num_rows); int row = 0; int dir = 1; for (char c : text) { rows[row] += c; int next = row + dir; if (next < 0 || next >= num_rows) { dir = -dir; } row += dir; } std::string result; for (const std::string& r : rows) { result += r; } return result; } int main() { std::cout << zigzag_convert("ABCDEFG", 3) << '\n'; } ``
  2. 2. This program uses std::left with std::setw(6). What does it print? ``cpp #include <iomanip> #include <iostream> int main() { std::cout << std::left << std::setw(6) << "ab" << "|\n"; } ``
  3. 3. Which header must be included to use std::setw? Type the name between the angle brackets.

    Type your answer.

  4. 4. The price list in the lesson sets std::fixed and std::setprecision(2) before printing the prices. With those two settings, the double value 2.5 prints as what text? Type it exactly.

    Type your answer.

  5. 5. Why does zigzag_convert return the text unchanged when num_rows < 2?

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.