Question: C++ ONLY. Each square on a chess board can be described by a letter and number, such as g5 in this example. Write a function

C++ ONLY. Each square on a chess board can be described by a letter and number, such as g5 in this example.

Write a function chessBoard which determines if a square with a given letter or number on a chessboard, is dark (black) or light (white).

  • Your function MUST be named chessBoard

  • Your function takes two input arguments: a character, and an integer

  • If your function receives as input a valid character and number, then it must print either black or white, depending on the color of the square given by those coordinates. (Note: the darker squares on the example board above should be considered as black and the lighter squares should be considered as white; non-white/black is used to distinguish between text, pieces and squares.)

  • If your function receives as input anything other than a-h for character, and 1-8 for number, then it must print Chessboard squares can only have letters between a-h and numbers between 1-8. Note that your function should discern between the valid lowercase letters and the invalid uppercase ones.

  • Your function should NOT return anything.

Examples:

  • If the input arguments are (g, 5), the function should print black

  • If the input arguments are (c, 4), the function should print white

  • If the input arguments are (a, 1), the function should print black

  • If the input arguments are (A, 10), the function should print Chessboard squares can only have letters between a-h and numbers between 1-8

For example:

Test Result
chessBoard ('g', 5);
black
chessBoard ('d', 3);
white
chessBoard ('a', 1);
black
87654321 9 43 2 1 4 3 2 1 43 2 1 43 21 2 87654321

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!