Question: C++ that is, do not use break or continue statements in a loop Let's get some practice in writing simple functions, and a challenge in

C++

that is, do not use "break" or "continue" statements in a loop

Let's get some practice in writing simple functions, and a challenge in nested repetition. Follow the provided steps to produce a custom checkerboard on the screen:

  1. Define a global symbolic constant MAX_WIDTH to be 40, and MAX_HEIGHT to be MAX_WIDTH/2
  2. Create a main program to display a rectangle with MAX_HEIGHT rows and MAX_WIDTH columns of alternating '.' and '*' characters. They must alternate across each row, as well as down each column.
  3. Output looks like
    .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.
  4. Modify your program so that all code is placed into the function checkerboard(). This function accepts an input integer argument width and does not return anything. (The argument is just ignored at this time.)
  5. Create getWidth() that accepts a single integer pass by reference argument. It prompts the user for an integer in the range of 1 to MAX_WIDTH and stores it in the provided argument. Re-prompt the user until a valid value is given. This function does not have a return value.
  6. Check the failbit to verify a valid integer has been input in getWidth().
  7. Modify the main program to first call getWidth(), then call checkerboard() passing the width obtained by getWidth().
  8. Make sure to compile and run your program to make sure everything is still working fine.
  9. Modify checkerboard() to use the input parameter. Instead of single alternating '.' and '*' characters, you will produce width characters at a time, making larger squares. As before, you are also producing alternating squares vertically.
  10. For instance, your final output if the user enters 3 for width will appear as:
    ...***...***...***...***...***...***...* ...***...***...***...***...***...***...* ...***...***...***...***...***...***...* ***...***...***...***...***...***...***. ***...***...***...***...***...***...***. ***...***...***...***...***...***...***. ...***...***...***...***...***...***...* ...***...***...***...***...***...***...* ...***...***...***...***...***...***...* ***...***...***...***...***...***...***. ***...***...***...***...***...***...***. ***...***...***...***...***...***...***. ...***...***...***...***...***...***...* ...***...***...***...***...***...***...* ...***...***...***...***...***...***...* ***...***...***...***...***...***...***. ***...***...***...***...***...***...***. ***...***...***...***...***...***...***. ...***...***...***...***...***...***...* ...***...***...***...***...***...***...*

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!