Description
Tic Tac Toe Game
You will implement several functions in a Tic Tac Toe game. I have already implemented the main that will call the functions you have to write. The board will be stored in a 2 dimensional 3×3 array of char.
Implement the following functions:
initBoard(char board[3][3]) – This function initializes the 3×3 board array to space characters representing unmarked positions.
displayBoard(char board[3][3]) – This displays the tic-tac-toe board with vertical and horizontal grid lines formed with dashes and vertical bars, using the characters in the 3×3 board array.
————-
| X | O | |
————-
| | O | |
————-
| O | X | X |
————-
markTheBoard(char board[3][3], char mark, int position) – This function marks the board based on the position (1-9) and marker character passed in.
hasWon(char board[3][3], char mark) – Returns true if the marker character of the player passed in as won the game by examining the values in the 3×3 board array.
isTie(char board[3][3]) – Tells if the board is currently a tie.
You will use the code in your repository, which is under 2018FACS5001SV/assignment-4-CCIS_ID.
Additional Exercises
Here are additional exercises that will give you more practice with the subject material in this module.
Pointers
Write a function void minMax(unsigned n, int array[n], unsigned *minVal, unsigned *maxVal) that returns the minimum and maximum values in the array to the locations pointed to by minVal and maxVal.
Write a function int *farthestFrom(unsigned n, int array[n], int val) that returns a pointer to the element of array whose value is farthest in absolute value from the value passed in. For example, given [3,8,7,14] and the value 5, the function returns a pointer to the array entry for n=14.
1D and 2D Arrays
Write a function swapUpperLower(unsigned n, int array[n]) that swaps the upper and lower subarrays of an array. If n is even, the lower- and upper-subarrays are swapped. If n is odd, subarrays to the left and right of the center element are swapped and the center value stays fixed. For example, [1,3,5,7,2,4,6,8] becomes [2,4,6,8,1,3,5,7].
Write a function double avg(unsigned n, double array[]) that computes the average of the values in the array. If the number of elements is 0, return the double constnat NaN.
Write a function void rotateLeft(unsigned n, int array[n]) that shifts the elements in the n element array left by one position and moves the first element to the end position. For example, [10, 5, 2, 16] becomes [5, 2, 16, 10].
Write a function void mask(unsigned n, int array[n], bool maskArray[n], int val) that sets all elements in array to to val if the corresponding value in maskArray is true and leaves it unchanged if the corresponding value in maskArray is false.
Write a function void addToAll(unsigned n, int array[n], int val) that given an int array of size n, adds val to every entry.
Write a function transpose(unsigned nRows, unsigned nCols, int to[ncols][nrows], int from[nrows][ncols]); that given an nRows x nCols array from, transposes it into a nCols x nRows array to. The first row of from becomes the first column of to, and so forth.
Strings
Write a function void toUpper(char *str) that replaces any lower-case letters in the input string with their upper-case versions. Other characters are not changed.
Write a function void toLower(char *str) that replaces any upper-case letters in the input string with their lower-case versions. Other characters are not changed.
Implement a version of the C string function char *strcpy(char *s1, const char *s2) that copies string s2 into string s1, return s1 pointer
Implement a version of the C string function char *stpcpy(char *s1, const char *s2) that copies string s2 into string s1, return a pointer to the ‘\0’ character in s1.
Implement a version of the C string function char *strcat(char *s1, const char *s2) that concatenates string s2 onto the end of string s1, and return s1 pointer.
Implement a version of the C string function int strcmp(const char *s1, const char *s2) that returns 0 if s1 and s2 are the same; less than 0 if s1 is lexically less than s2; greater than 0 if s1 is lexically greater than s2. A string s1 is lexically less than s2.
Implement a version of the C string function char* strchr(const char*s1, char ch) that returns a pointer to the first occurrence of character ch in string s1.
Implement a version of the C string function char* strstr(s1, s2) that returns a pointer to the first occurrence of string s2 in string s1.