Lab 7

For lab this week we'll be practicing using arrays, functions, passing by value, and passing by reference.

The code given to you for this lab is 3 copies of the same source file, which allow a user to select a board position, and then place an X there.  In the first version, the board is stored in global variables, and we give you the code which will accomplish the described task.

Your job is to take the other two files, and implement the same functionality.

For 1 point, implement the function setPiece(int, char, char&, char&, char&, char&, char&, char&, char&, char&, char&) in tictactoe2.c.  The code is equivalent to the one in tictactoe1.c, but instead of representing the board with global variables, we instead have 9 char variables local in main, which we pass by reference to the function.

For 2 points, implement the function setPiece(int, char, char*) in tictactoe3.c.  In this version of the code, the board is stored in a character array in main, and we pass that array to the function.  Note that I catch the array as a pointer, but it would be equivalent to say setPiece(int, char, char[]) or setPiece(int, char, char[9]).

For a point of extra credit, implement the setPiece in tictactoe3.c in a single line without using any decision statements, loops, or function calls.  If you're not sure whether your solution satisfies this requirement, ask one of the TAs.

For this lab, submit your modified tictactoe2.c and tictactoe3.c files.

Please be sure to put your name in a comment at the top of the code (replacing where I have mine is fine).  If you work alone, then I expect one name, and if you work as a pair I expect both.  Also be sure to submit on time, lab ends at the 50 minute mark and neither of us want to give you a late penalty.

We'll also be around so if you're confused about the differences between char, char *, char[], and char &, we can go into more detail about that as well.  You'll see it more in class, and some part is getting used to it, but you should have enough information at this point to use them all appropriately.