Question: tl;dr Using functions and a 2D array of characters, students will create a program which reads input from a file representing a chessboard and prints

tl;dr Using functions and a 2D array of characters, students will create a program which reads input from a file representing a chessboard and prints that chessboard to the terminal.

Student will create a program which prompts the user for an input file path. The input file will contain 64 characters representing a chess board. The characters read in are in order from left to right, top to bottom. Below is a reference to what characters represent what pieces in the input.

'0' -> Empty Space 'K' -> King 'Q' -> Queen 'B' -> Bishop 'N' -> Knight 'R' -> Rook 'p' -> Pawn

Students programs will contain the following functions:

  • promptUser() will print a prompt for the user, get their input file path, and return the path as a string.
  • readFile() accepts a file path and a 2D array (2D arrays are automatically by reference) and populates the 2D array with characters from the file. It returns nothing.
  • printBoard() accepts a 2D array meant to represent a chess board and prints it to the terminal.

Even though the file does not contain characters which distinguish black and white spaces, the function should print non-piece spaces in a chessboard pattern. (where spaces alternate between black/white) Take some time to consider this, there is an easy mathematical approach.

Students can assume that all input files will contain exactly 64 non-whitespace characters. Additionally students may assume that each line will contain exactly 8 non-whitespace characters and each line will end with a newline character. (for a total of 9 characters per line)

Small Note: I'd really like it if students would use special ascii characters that resemble chess pieces (see starter code) but I know that some systems have trouble displaying these characters. Students are welcome to use simple characters in place of the special ones if it causes them trouble, it's just much less fun.

Starter code for copy/paste:

// Convenient way to use special characters, if your terminal supports it #define KING "" #define QUEEN "" #define BISHOP "" #define KNIGHT "" #define ROOK "" #define PAWN "" #define DARK_BLOCK "" #define LIGHT_BLOCK " " #include  #include  #include  using namespace std; // Functions must be prototyped string promptUser(); void readFile(string filepath, char board[8][8]); void printBoard(char board[8][8]); int main() { }
 tl;dr Using functions and a 2D array of characters, students will create

Example Input 000000NO BR00000 00000000 Opo00000 000000po 0000000B 900K0000 00000000 Example Outputs Output with special characters : input.txt 1 2 3 4 5 6 7 8 1 21 000VWN Output without special characters : input.txt 1 2 3 4 5 6 7 8 1 [10/10[]KN[ ] 2 110RKO[1000 3 [10[]Qu[101) 4 []pn[10010010 5 OCTO[][]pn[] 6 [00000[]Bi 7 ODTOKO[101] 8 [1001001000

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!