// CS201 HW09 // Problem #01 #include using namespace std; bool win(const char x[3][3]) { for (int i=0; i<3;i++) if((x[0][i]=='O' && x[1][i]=='O' && x[2][i]=='O') || (x[0][i]=='X' && x[1][i]=='X' && x[2][i]=='X')) { return 1; exit(1); } for (int ii=0;ii<3;ii++) if((x[ii][0]=='O' && x[ii][1]=='O' && x[ii][2]=='O') || (x[ii][0]=='X' && x[ii][1]=='X' && x[ii][2]=='X')) { return 1; exit(1); } if((x[0][0]=='O' && x[1][1]=='O' && x[2][2]=='O') || (x[0][0]=='X' && x[1][1]=='X' && x[2][2]=='X')) { return 1; exit(1); } if((x[0][2]=='O' && x[1][1]=='O' && x[2][0]=='O') || (x[0][2]=='X' && x[1][1]=='X' && x[2][0]=='X')) { return 1; exit(1); } return 0; } void printboard(char x[3][3]) { cout << "-----\n"; cout << x[0][0] << " " << x[0][1] << " " << x[0][2] << endl; cout << x[1][0] << " " << x[1][1] << " " << x[1][2] << endl; cout << x[2][0] << " " << x[2][1] << " " << x[2][2] << endl; cout << "-----\n"; } int main() { char board[3][3]; { for (int ii=0;ii<3;ii++) { for(int jj=0;jj<3;jj++) { board[ii][jj]=' '; } } } int horiz, vert; for(int moves=1; moves<=9; moves++) { if (moves%2==0) { cout << "Player TWO enter your move coordinates " << "\n\n"; cin >> horiz >> vert; while (board[horiz][vert]=='X' || board[horiz][vert]=='O') { cout << "That space already has been used. Please input another space."; cin >> horiz >> vert; } board[horiz][vert]='X'; } else { cout << "Player ONE enter your move coordinates " <<"\n\n"; cin >> horiz >> vert; while (board[horiz][vert]=='X' || board[horiz][vert]=='O') { cout << "That space already has been used. Please input another space."; cin >> horiz >> vert; } board[horiz][vert]='O'; } printboard(board); if (win(board)) { cout << "You win!" << endl; break; } } cout << "Game over!" << endl; return 0; } // CS201 HW9 // Problem #02 #include #include using namespace std; void backwards(char x[], int size) { if (size == 0) { cout << x[size]; } else { if (x[size] == '#') { } else { cout << x[size]; } backwards(x, --size); // recursion } } int main() { cout << "Please enter a string to print backwards under 10 characters" << endl; char x[11]; for (int i=0; i<=11; i++) { x[i]='#'; // the string of #s as the initial string } cin >> x; cout << "The string " << x << " printed backwards is "; backwards(x, 11); cout << endl; return 0; }