This is my first time posting, I hope I got it right
This is my header:
Code:
#ifndef TTT_H
#define TTT_H
#include <iostream>
#include <stdlib.h>
using namespace std;
class TicTacToe
{
public:
static const size_t rows = 3;
static const size_t cols = 3;
//These are static constants to represent the number of rows and columns in our Tic-Tac-Toe board.
TicTacToe ();
// This is the default constructor for the class.
// It will call a function to initialize the Tic-Tac-Toe board to blank spaces (i.e. the ' ' character).
void InitializeBoard();
//This function will initialize the board to blank spaces.
//It is also called by the default constructor above.
void PrintBoard();
// This function will print the Tic-Tac-Toe board.
bool OccupySquare(size_t x, size_t y, char value);
//This function will occupy a square on the board.
//It takes in two coordinates and a value which should be either 'X' or 'O'.
//It returns true if the square was occupied, false if the square wasn't occupied
char CheckForWinner();
//This function will check the board for a winner.
//It will return a ' ' to indicate no winner, an 'X' to indicate that X has won,
//an 'O' to indicate that O has won, or an 'S' to indicate a scratch.
private:
char board[rows][cols];
//This is a two-dimensional character array to represent the board.
bool IsValidLocation(size_t x, size_t y);
//This function will take in two coordinates and decide if they are valid.
//Valid coordinates are those within the range of the board indices and not already occupied.
//This function will be called by OccupySquare(). It will return true if the coordinates are valid, false otherwise.
bool IsScratch();
//This function will decide if the game is a scratch.
//It will be called by CheckForWinner().
//Note that you should call this function after checking the winning possibilities.
};
#endif
these are my implementation definitions
Code:
#include <iostream>
using namespace std;
#include "ttt.h"
TicTacToe::TicTacToe ()
{
InitializeBoard ();
}
void TicTacToe::InitializeBoard()
{
for (rows = 0; rows < 3; rows ++)//outer loop for row
{
for (cols = 0; cols <3; cols ++) //inner loop for column
{
board [rows][cols] = NULL ;} //board intialized
}
}
void TicTacToe::PrintBoard()
{
for ( rows = 0; rows < 3; rows ++)//outer loop for row
{cout << " ", board[rows][0], board [rows][1], board[rows][2];
if (rows != 2)
{
cout << "\n ___I___I___\n" <<endl;
}
}
}
}
My Problem is that the constants rows and variables wont be assigned values