Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions