Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need a c++ program that does the following: Let's get some practice in writing simple functions, and a challenge in nested repetition. Follow the

I need a c++ program that does the following:

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 MaxWidth to be 40, and MaxHeight to be MaxWidth/2

Create a main program to display a rectangle with MaxHeight rows and MaxWidth columns of alternating '.' and '*' characters. They must alternate across each row, as well as down each column.

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 MaxWidth 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.

(Bonus) 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 link your program to make sure everything is still working fine.

(Bonus) 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

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

Step: 3

blur-text-image

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

Students also viewed these Databases questions