Embercode
✕
C++ PatternsQuick quiz

Shapes

6 questions. Covers Hourglass, arrow and cross shapes.

Questions 1 to 5 of 6

  1. 1. What does this program print? ``cpp #include <iostream> void print_row(int width, int field) { int pad = (field - width) / 2; for (int i = 0; i < pad; ++i) std::cout << ' '; for (int i = 0; i < width; ++i) std::cout << '*'; std::cout << '\n'; } int main() { print_row(4, 7); print_row(2, 5); } ``
  2. 2. What does this program print? ``cpp #include <iostream> void print_row(int width, int field) { int pad = (field - width) / 2; for (int i = 0; i < pad; ++i) std::cout << ' '; for (int i = 0; i < width; ++i) std::cout << '*'; std::cout << '\n'; } void print_arrow(int head_rows, int shaft_rows, int shaft_width) { const int field = 2 * head_rows - 1; for (int row = 0; row < head_rows; ++row) print_row(1 + 2 * row, field); for (int row = 0; row < shaft_rows; ++row) print_row(shaft_width, field); } int main() { print_arrow(3, 1, 1); } ``
  3. 3. The hourglass program loops over its rows with for (int row = 0; row < 2 * half; ++row). What goes wrong with this line?
  4. 4. The cross program marks a cell with (row == mid) || (col == mid). Why is || the right operator here?
  5. 5. In pad = (field - width) / 2, the / is ___ division, which throws away the fraction.

    Type your answer.

5 question(s) left on this page.

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