Aryabhatta International College
of Technical Education
Ajmer, Rajasthan
A
PROJECT REPORT
ON
Tic Tac Toe: C++
Submitted in partial fulfilment for the
Award of the Degree of
BACHELOR OF COMPUTER APPLICATIONS
2017-2018
Submitted to:
Aryabhatta International College of Technical Education
Submitted by:
Harshita Bhargava
ACKNOWLEDGEMENT
I am thankful to Kriti Sankhla Ma’am for her valuable time she has devoted to
me and given me a lot of knowledge and help for the project. I am also thankful
to other teachers for their expert guidance. It was a great experience for me to
work and learn under their guidance.
Words defeat us in expressing our deep sense of gratitude for our friends, whose
continued resourceful support and guidance enabled me to overcome all the
challenges that I have faced while developing the project.
Harshita Bhargava
TIC TAC TOE
#include<iostream.h>
#include<conio.h>
char a[10]={'0','1','2','3','4','5','6','7','8','9'};
class Tic_tac
{
private:
int player,choice,i;
char mark;
public:
void board();
void game();
int checkwin();
};
Tic_tac obj;
void Tic_tac::game()
{
clrscr();
int player=1;
int choice,i;
char mark;
obj.board();
do
{
player=(player%2==1)?1:2;
cout<<endl<<"Player "<<player<<endl<<"Enter a number:";
cin>>choice;
mark=(player==1)?'X':'O';
if(choice==1 && a[1]=='1')
{
a[1]=mark;
}
else if(choice==2 && a[2]=='2')
{
a[2]=mark;
}
else if(choice==3 && a[3]=='3')
{
a[3]=mark;
}
else if(choice==4 && a[4]=='4')
{
a[4]=mark;
}
else if(choice==5 && a[5]=='5')
{
a[5]=mark;
}
else if(choice==6 && a[6]=='6')
{
a[6]=mark;
}
else if(choice==7 && a[7]=='7')
{
a[7]=mark;
}
else if(choice==8 && a[8]=='8')
{
a[8]=mark;
}
else if(choice==9 && a[9]=='9')
{
a[9]=mark;
}
else
{
cout<<"Invalid Move";
player--;
}
player++;
i=checkwin();
clrscr();
board();
}while(i==-1);
if(i==1)
{
player--;
cout<<endl<<"---Player "<<player<<" win--- "<<endl;
}
else
{
cout<<"Game Draw"<<endl;
}
}
int Tic_tac::checkwin()
{
if(a[1]==a[2] && a[2]==a[3])
{
return 1;
}
else if(a[4]==a[5] && a[5]==a[6])
{
return 1;
}
else if(a[7]==a[8] && a[8]==a[9])
{
return 1;
}
else if(a[1]==a[4] && a[4]==a[7])
{
return 1;
}
else if(a[2]==a[5] && a[5]==a[8])
{
return 1;
}
else if(a[3]==a[6] && a[6]==a[9])
{
return 1;
}
else if(a[1]==a[5] && a[5]==a[9])
{
return 1;
}
else if(a[3]==a[5] && a[5]==a[6])
{
return 1;
}
else if(a[1]!='1' && a[2]!='2' && a[3]!='3' && a[4]!='4' && a[5]!='5' &&
a[6]!='6' && a[7]!='7' && a[8]!='8'&& a[9]!='9')
{
return 0;
}
else
{
return -1;
}
}
void Tic_tac::board()
{
cout<<endl;
cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
*-*-*-*-*-*-*-*-*"<<endl;
cout<<" TIC TAC TOE "<<endl;
cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
*-*-*-*-*-*-*-*-*"<<endl<<endl;
cout<<" Player 1(X) Player 2(O)"<<endl<<endl<<endl;
cout<<" | | "<<endl;
cout<<" "<<a[1]<<" | "<<a[2]<<" | "<<a[3]<<endl;
cout<<" | | "<<endl;
cout<<" -----------------"<<endl;
cout<<" | | "<<endl;
cout<<" "<<a[4]<<" | "<<a[5]<<" | "<<a[6]<<endl;
cout<<" | | "<<endl;
cout<<" -----------------"<<endl;
cout<<" | | "<<endl;
cout<<" "<<a[7]<<" | "<<a[8]<<" | "<<a[9]<<endl;
cout<<" | | "<<endl;
}
void main()
{
clrscr();
obj.board();
obj.game();
obj.checkwin();
getch();
}
Output :-
Created by:
Harshita Bhargava

Tic tac toe

  • 1.
    Aryabhatta International College ofTechnical Education Ajmer, Rajasthan A PROJECT REPORT ON Tic Tac Toe: C++ Submitted in partial fulfilment for the Award of the Degree of BACHELOR OF COMPUTER APPLICATIONS 2017-2018 Submitted to: Aryabhatta International College of Technical Education Submitted by: Harshita Bhargava
  • 2.
    ACKNOWLEDGEMENT I am thankfulto Kriti Sankhla Ma’am for her valuable time she has devoted to me and given me a lot of knowledge and help for the project. I am also thankful to other teachers for their expert guidance. It was a great experience for me to work and learn under their guidance. Words defeat us in expressing our deep sense of gratitude for our friends, whose continued resourceful support and guidance enabled me to overcome all the challenges that I have faced while developing the project. Harshita Bhargava
  • 3.
    TIC TAC TOE #include<iostream.h> #include<conio.h> chara[10]={'0','1','2','3','4','5','6','7','8','9'}; class Tic_tac { private: int player,choice,i; char mark; public: void board(); void game(); int checkwin(); }; Tic_tac obj; void Tic_tac::game() { clrscr(); int player=1; int choice,i; char mark; obj.board(); do { player=(player%2==1)?1:2; cout<<endl<<"Player "<<player<<endl<<"Enter a number:";
  • 4.
    cin>>choice; mark=(player==1)?'X':'O'; if(choice==1 && a[1]=='1') { a[1]=mark; } elseif(choice==2 && a[2]=='2') { a[2]=mark; } else if(choice==3 && a[3]=='3') { a[3]=mark; } else if(choice==4 && a[4]=='4') { a[4]=mark; } else if(choice==5 && a[5]=='5') { a[5]=mark; } else if(choice==6 && a[6]=='6') { a[6]=mark; } else if(choice==7 && a[7]=='7') {
  • 5.
    a[7]=mark; } else if(choice==8 &&a[8]=='8') { a[8]=mark; } else if(choice==9 && a[9]=='9') { a[9]=mark; } else { cout<<"Invalid Move"; player--; } player++; i=checkwin(); clrscr(); board(); }while(i==-1); if(i==1) { player--; cout<<endl<<"---Player "<<player<<" win--- "<<endl; } else { cout<<"Game Draw"<<endl;
  • 6.
    } } int Tic_tac::checkwin() { if(a[1]==a[2] &&a[2]==a[3]) { return 1; } else if(a[4]==a[5] && a[5]==a[6]) { return 1; } else if(a[7]==a[8] && a[8]==a[9]) { return 1; } else if(a[1]==a[4] && a[4]==a[7]) { return 1; } else if(a[2]==a[5] && a[5]==a[8]) { return 1; } else if(a[3]==a[6] && a[6]==a[9]) { return 1;
  • 7.
    } else if(a[1]==a[5] &&a[5]==a[9]) { return 1; } else if(a[3]==a[5] && a[5]==a[6]) { return 1; } else if(a[1]!='1' && a[2]!='2' && a[3]!='3' && a[4]!='4' && a[5]!='5' && a[6]!='6' && a[7]!='7' && a[8]!='8'&& a[9]!='9') { return 0; } else { return -1; } } void Tic_tac::board() { cout<<endl; cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- *-*-*-*-*-*-*-*-*"<<endl; cout<<" TIC TAC TOE "<<endl; cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- *-*-*-*-*-*-*-*-*"<<endl<<endl; cout<<" Player 1(X) Player 2(O)"<<endl<<endl<<endl;
  • 8.
    cout<<" | |"<<endl; cout<<" "<<a[1]<<" | "<<a[2]<<" | "<<a[3]<<endl; cout<<" | | "<<endl; cout<<" -----------------"<<endl; cout<<" | | "<<endl; cout<<" "<<a[4]<<" | "<<a[5]<<" | "<<a[6]<<endl; cout<<" | | "<<endl; cout<<" -----------------"<<endl; cout<<" | | "<<endl; cout<<" "<<a[7]<<" | "<<a[8]<<" | "<<a[9]<<endl; cout<<" | | "<<endl; } void main() { clrscr(); obj.board(); obj.game(); obj.checkwin(); getch(); }
  • 9.
  • 10.