Answered step by step
Verified Expert Solution
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:
- Define a global symbolic constant MAX_WIDTH to be 40, and MAX_HEIGHT to be MAX_WIDTH/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.
- Output looks like
.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. .*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.* *.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.
- 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.)
- 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.
- Check the failbit to verify a valid integer has been input in getWidth().
- Modify the main program to first call getWidth(), then call checkerboard() passing the width obtained by getWidth().
- Make sure to compile and run your program to make sure everything is still working fine.
- 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.
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started