Question: I have this issue with my program Everything works good but when I run it it only shows Player 1 But what it should do
I have this issue with my program
Everything works good but when I run it it only shows Player 1
But what it should do is after Player 1 turn it should switch to Player 2.
THE QUESTION IS ASKING:
Using Classes
1.Define the functions declared in TicTacToe.h so that main.cpp produces results similar to when .obj is included in the project
Three files are provided to you.
Main.cpp contains the driver that will run the declared functions to ensure they work properly, it does not need to be altered or submitted.
.h contains the declarations and function prototypes related to the class, it does not need to be altered or submitted.
.obj contains a compiled solution that will allow you to test existing functionality. It needs to be removed from your project for you to test your own implementation. This file is not needed to complete the project, I will demo the program at the beginning of the lab session.
Functions to be defined:
//Returns 1 or 2 if the respective player has won, 0 if there is no winner, or 3 if the game ends without a winner
int checkWin();
//Default constructor, begins game with an empty board
TicTacToe();
//Displays the current state of the board
void displayBoard();
//Returns -1 to indicate an invalid move, or the results of checkWin if the move is valid
int makeMove(int position);
Class variables:
//Board stores a 0 to indicate an empty position, or 1/2 if a player is occupying it
int board[3][3];
//Used to indicate if the next move will be performed by player 1 or player 2
int nextPlayer;
Submission:
You will submit a file named
For example, my assignment would be named MayElabFinal.cpp
Main Function:
//Eric May //CPSC 121 Final Lab //5/8/2016 #include "TicTacToe.h" #include
int main() { //The instance of our class that will be used TicTacToe game; int res = 0; do { //Tell user if the last move was invalid if (res == -1) std::cout > pos; //Attempt to make provided move res = game.makeMove(pos); } while (res
TicTacToe.h Function:
//Eric May //CPSC 121 Final Lab //5/8/2016 #pragma once
//Contains methods allowing for a user to play a game of tic-tac-toe class TicTacToe { private: //Board stores a 0 to indicate an empty position, or 1/2 if a player is occupying it int board[3][3]; //Returns 1 or 2 if the respective player has won, 0 if there is no winner, or 3 if the game ends without a winner int checkWin(); public: //Used to indicate if the next move will be performed by player 1 or player 2 int nextPlayer; //Default constructor, begins game with an empty board TicTacToe(); //Note: Since we aren't dynamically allocating memory, there's no need for a deconstructor //Displays the current state of the board void displayBoard(); /* Returns -1 to indicate an invalid move, or the results of checkWin if the move is valid Board Position Mapping 0 1 2 3 4 5 6 7 8 Use 1-9 if that's easier for you, but make sure you document it! */ int makeMove(int position); };



#include "TicTacToe .h" #include Kiostream> #include Kcstdlib> include ctime.h> using namespace std; TicTacToe:: TicTacToe() //empty board nextPlayer 1; for (int i e; ic3; i++) for (int j 0; j
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
