DEPARTMENT OF COMPUTER TECHNOLOGY
Sanjivani rural education society
SANJIVANI K.P.B POLYTECHNIC, KOPARGOAN
A MICROPROJECT REPORT ON
“TIC TAC TOE GAME USING C++”
SUBMITTED BY
[Link] Ajinkya[229]
[Link] Vedika[241]
[Link] Yashraj[242]
[Link] Shreya [245]
DEPARMENT OF COMPUTER TECHNOLOGY
SANJIVNI [Link] ,KOPARGOAN
(2020-2021)
1|Page
DEPARTMENT OF COMPUTER TECHNOLOGY
Sanjivani rural education sosiety’s
SANJIVANI K.P.B POLYTECHNIC, KOPARGOAN
CRETIFICATE
This is to certify that the microproject report entitled
“TIC TAC TOE GAME USING C++”
SUBMITTED BY
[Link] Ajinkya[229]
[Link] Vedika[241]
[Link] Yashraj[242]
[Link] Shreya[245]
Under our supervision and guidance for pratical fulfillment pop the
requirements for diploma in computer technology located to Maharashtra,
board of technical education ,Mumbai
[Link] [Link] [Link]
Project Guided H.O.D principal
2|Page
Rationale
This report is an introduction to the
Tic Tac Toe game in C++ programming. Anybody, who
doesn’t know even the basics of Tic Tac Toe in C++,will be
certainly able to understand and gain the great knowledge
from this report. The core theme of the report focuses on the
development of TicTac Toe game in C++ language.
The report also contains the strategy
of making Tic Tac Toe game which serve a good idea to make
a Tic Tac Toe game program in C++ language to the
programmer.
The most of the idea of making this game
and report is taken from “Object-Oriented Programming with
C++ by E Balagurusamy’’and Internet
(Wikipedia ,Google,Yahoo .etc.)
3|Page
AIM :-
To devlop operating system ,browsers and game using
object oriented languages ;and many concepts using c++
language.
Benefits of TIC TAC TOE game:-
Easy to implement using c++ language.
Course outcome achieved:-
Devlop c++ program to solve problem using procedure
oriented approach.
Devlop c++ program using classes and object.
Implement inheritances in a program.
Liturature review :-
Object-Oriented Programming With C++[7e] By E
Balaguruswamy
Google
Wikipedia
Github
4|Page
Actual Methodology Followed :-
The Project Code is implemented using Object Oriented
Programming Using C++ Language.
Following are the details of Concepts used in the
program and the software used to run this program.
The OOP Concepts:
[Link] and Objects
[Link]
[Link]
Resources used :-
[Link] Name of resources specification QTY.
1. Hardware: computer Computer(i3-i5)RAM 01
system minimum 2gb and
onwards
2. Operating system Windows 10 01
5|Page
3. Software used Turbo c++ version 3.0 01
Micro project source code :-
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class TicTacToe
{
public:
TicTacToe();
int Pick_Player();
int Pick_Row();
int Pick_Column();
int Check_Board();
void Choice_by_Player(int);
void Choice_of_Row(int);
void Choice_of_Column(int);
void Tic_Tac_Toe_Board();
bool Check_Move (int, int);
private:
int row;
int column;
int player;
int board[3][3];
char display_board[3][3];
};
TicTacToe::TicTacToe()
{
row=0;
column=0;
player=1;
6|Page
int i=0; //where i is row and j will be columns
int j=0;
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
board[i][j] =0;
display_board[i][j] = ' ';
}
}
}
int TicTacToe::Pick_Player()
{
return player;
}
int TicTacToe::Pick_Row()
{
return row;
}
int TicTacToe::Pick_Column()
{
return column;
}
void TicTacToe::Choice_by_Player(int a)
{
player=a;
}
void TicTacToe::Choice_of_Row(int b)
{
row=b;
}
void TicTacToe::Choice_of_Column(int c)
{
column=c;
}
7|Page
bool TicTacToe::Check_Move(int row, int column)
{
if (row!=0 && row!=1 && row!=2 )
{
cout<<"Invalid choice!!"<<endl;
return 0;
}
else if (column!=0 && column!=1 && column!=2 )
{
cout<<"Invalid choice!!"<<endl;
return 0;
}
else if (board[row][column] ==1 || board[row][column] ==2)
{
cout<<"Space already used. Try Again." <<endl;
return 0;
}
else
{
board[row][column] = player;
return 1;
}
}
int TicTacToe::Check_Board()
{
int i=0;
int j=0;
int sum= 0;
int test= 0;
int count= 0;
for (i= 0; i<3; i++)
{
sum=0;
for(j=0; j<3; j++)
{
8|Page
if (board[i][j] ==0)
{
count++;
}
sum +=(board[i][j]*board[i][j]);
}
if (sum==3 ||sum==12)
{
test=sum;
break;
}
sum=0;
}
for (j=0; j<3; j++)
{
sum=0;
for (i=0; i<3; i++)
{
sum+=(board[i][j]*board[i][j]);
}
if (sum==3 || sum==12)
{
test=sum;
break;
}
sum=0;
}
if(test!=3 ||test!=12)
{
sum = (board[0][0] * board[0][0])+ (board[1][1] * board[1]
[1]) +
(board[2][2] * board[2][2]);
if ( sum == 3 || sum == 12)
{
test=sum;
9|Page
}
}
if (test != 3 || test != 12)
{
sum = (board[2][0] * board[2][0])+ (board[1][1] * board[1]
[1]) +
(board[0][2] * board[0][2]);
if (sum==3||sum==12)
{
test=sum;
}
}
if (test==3)
{
test=1;
}
else if (test==12)
{
test=2;
}
else if (count==0)
{
test=3;
}
else
{
test=0;
}
return test;
}
void TicTacToe::Tic_Tac_Toe_Board()
{
for ( int row = 0; row < 3; row ++)
{
for ( int column = 0; column < 3; column++)
10 | P a g e
{
if ( board[row][column] == 0)
{
display_board[row][column] = ' ';
}
if ( board[row][column] == 1)
{
display_board[row][column] = 'X';
}
if ( board[row][column] == 2)
{
display_board[row][column] = 'O';
}
}
}
cout<<"Welcome to tic-tac-toe!"<<endl<<endl;;
cout<< " Current Player: X Current Player: O " <<
endl<<endl<<endl;
cout << " | | " << endl;
cout << " | | " << endl;
cout <<display_board[0][0] << " "<<display_board[0][1]<<" |
" << display_board[0][2] << " " << endl;
cout << " | | " << endl;
cout << "-----------------------------------------------" << endl;
cout << " | | " << endl;
cout << " | | " << endl;
cout <<display_board[1][0] << " "<<display_board[1][1]<<" |
" << display_board[1][2] << " " << endl;
cout << " | | " << endl;
cout << "-----------------------------------------------" << endl;
cout << " | | " << endl;
cout <<display_board[2][0] << " "<<display_board[2][1]<<" |
" << display_board[2][2] << " " << endl;
cout << " | | " << endl;
cout << " | | " << endl;
11 | P a g e
}
int main()
{
TicTacToe game;
bool test;
bool more=true;
int row=0;
int column=0;
int player;
int check=0;
TicTacToe();
while (more)
{
game.Tic_Tac_Toe_Board();
player= game.Pick_Player();
cout<<" Current Player "<<player;
cout<< endl;
cout<< "Enter Row Index (0, 1, or 2): " <<endl;
cin>>row;
cout<<"Enter Column Index (0, 1, or 2): "<<endl;
cin>>column;
game.Choice_of_Row(row);
game.Choice_of_Column(column);
test= game.Check_Move( game.Pick_Row(),
game.Pick_Column());
if (test==1)
{
check=game.Check_Board();
}
else
{
while (test==0)
{
cout<<"Current player"<<game.Pick_Player()<<"Invalid
Choice"<<endl;
12 | P a g e
cout<<"Enter Row Index (0, 1, or 2): "<<endl;
cin>>row;
cout<<"Enter Column Index (0, 1, or 2): "<<endl;
cin>>column;
game.Choice_of_Row(row);
game.Choice_of_Column(column);
test=game.Check_Move(game.Pick_Row(),
game.Pick_Column());
}
check= game.Check_Board();
}
if (check==1 ||check==1)
{
break;
}
else if (check==3)
{
game.Tic_Tac_Toe_Board();
cout<<"The game is tied. "<<endl;
}
if (player ==1)
{
player==2;
}
else
{
player=1;
}
game.Choice_by_Player(player);
}
game.Tic_Tac_Toe_Board();
cout<<"Player "<<check<<" wins! "<<endl;
return 0;
}
13 | P a g e
Output of TIC TAC TOE c++ program code :-
Figure 1:-Starting view of the Game…
Figure 2:- Player 1 Win view…
14 | P a g e
Figure 3:-Game Draw view…
Figure 4:-Player 2 Win view…
15 | P a g e
Conclusion
It was a great experience to design
and implement the Tic Tac Toe by using Object Oriented
Programming language C++ and to work on its
[Link] working on this project,we have learned
many things especially how to apply the concepts of OOP
paradigm in modelling of real world systems.
This assignment helped me to get
the better understanding to develop and derive new class
structures and organise them such that they will model real
world systems within [Link] also helped me in getting
in the better understanding of basic programming concepts of
C++ language such as loops,control structure,arrays.
In this project,we have used almost
every concepts of C++ language,we have learned .We have
also provided validations throughout the system for avoiding
logical errors,used excellent logic related comments with
proper indentation and the OOP’s concept in an excellent
manner.
After doing this project,We are in position to explain Object
Oriented Programming concepts and apply them to the
modelling of real world systems by utilizing its offered
facilities
16 | P a g e