0% found this document useful (0 votes)
19 views

Implemetation of Tic Tac Toe Using C++ (Mini Skill Project Computer Programming)

The program implements the Tic-Tac-Toe game using C++. It defines a function to check for a winner, a function to draw the board and take player input, and a main function that runs the game loop until there is a winner or a draw.

Uploaded by

Æyan Khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Implemetation of Tic Tac Toe Using C++ (Mini Skill Project Computer Programming)

The program implements the Tic-Tac-Toe game using C++. It defines a function to check for a winner, a function to draw the board and take player input, and a main function that runs the game loop until there is a winner or a draw.

Uploaded by

Æyan Khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

MADHAV INSTITUTE OF TECHNOLOGY & SCIENCE, GWALIOR

(M.P.), INDIA
A GOVT. AIDED UGC AUTONOMOUS INSTITUTE, AFFILIATED TO R.G.P.V. BHOPAL (M.P.)
NAAC ACCREDITED WITH A++ GRADE

Centre for Internet of Things


B.Tech Internet of Things(IOT)
Computer Programming (3230122)
1st Year 1st Semester

Skill Based Mini Project

SUBMITTED TO: SUBMITTED BY:


Dr. Sanjiv Sharma Ayan Ahmed Khan
Prof. Surbhi Gupta 0901IO231015
DEPARTMENT Of IT

DECLARATION

I hereby declare that the Mini skill-based project for the course COMPUTER
PROGRAMMING (3230122) is being submitted in the partial fulfilment of the
requirement for the award of Bachelor of Technology in Internet Of Things.

All the information in this document has been obtained and presented in
accordance with academic rule and ethical conduct.

Date: 05 Jan 2024


Place: Gwalior
Devanshu Gupta
0901IO231015
ACKNOWLEDGEMENT

I would like to express my greatest appreciation to all the individuals who have
helped and supported me throughout this lab file. I am thankful to whole
Information Technology department for their ongoing support during the Program
making, from initial advice and provision of contact in the first stages through
ongoing advice and encouragement, which led to the finals report of this lab file.
A special acknowledgement goes to my colleagues who help me in completing the
file and by exchanging interesting ideas to deal with problems and sharing the
experience.
I wish to thank our professor Dr.Sanjiv Sharma as well for his undivided support
and interests which inspired me and encouraged me to go my own way without
whom I would be unable to complete my project.
At the end, I want to thank my friends who displayed appreciation to my work and
motivated me to continue my work.

Devanshu Gupta
SKILL-BASED MINI PROJECT

Problem : Implement the Tic-Tac-Toe game using C++.

Code:

#include<iostream>
using namespace std;
char square[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

//function to return the game status


int checkwin (){
if (square[1] == square[2] && square[2] == square[3])
{
return 1;
}
else if (square[4] == square[5] && square[5] == square[6])
{
return 1;
}
else if(square[7]==square[8] && square[8]==square[9])
{
return 1;
}
else if(square[1]==square[4] && square[4]==square[7]){
return 1;
}
else if(square[2]==square[5] && square[5]==square[8])
{
return 1;
}
else if (square[3]==square[6] && square[6]==square[9])
{
return 1;
}
else if( square[1]==square[5] && square[5]==square[9])
{
return 1;
}
else if(square[3]==square[5] && square[5]==square[7])
{
return 1;
}
else if(square[1]!='1' && square[2]!='2' && square[3]!='3' &&
square[4]!='4' && square[5]!='5' && square[6]!='6' &&
square[7]!='7' && square[8]!='8' && square[9]!='9')
{
return 0;
}
else{
return -1;
}
}
//this function will draw the board with the players mark
void board(){
system("cls");
cout<<"\n\n\t Tic Tac Toe game \n\n";
cout<<"player 1(X) -player 2(0)"<<endl<<endl;
cout<<endl;
//drawing of the board
cout<<" | | "<<endl;
cout<<" "<<square[1]<<" | "<<square[2]<<"| "<<square[3]<<endl;
cout<<"___|___|___"<<endl;
cout<<" | | "<<endl;
cout<<" "<<square[4]<<" | "<<square[5]<<"| "<<square[6]<<endl;
cout<<"___|___|___"<<endl;
cout<<" | | "<<endl;
cout<<" "<<square[7]<<" | "<<square[8]<<"| "<<square[9]<<endl;
cout<<" | | "<<endl;
}
int main(){
int player= 1, i, choice;
char mark;
do{
board();
player=(player%2)?1:2;
cout<<"player"<<player<<" ,enter the number: ";
cin>>choice;
mark=(player==1)?'X':'0';
if(choice==1 && square[1]=='1')
{
square[1]=mark;
}
else if(choice==2 && square[2]=='2')
{
square[2]=mark;
}
else if(choice==3 && square[3]=='3')
{
square[3]=mark;
}
else if(choice==4 && square[4]=='4')
{
square[4]=mark;
}else if(choice==5 && square[5]=='5')
{
square[5]=mark;
}else if(choice==6 && square[6]=='6')
{
square[6]=mark;
}else if(choice==7 && square[7]=='7')
{
square[7]=mark;
}else if(choice==8 && square[8]=='8')
{
square[8]=mark;
}else if(choice==9 && square[9]=='9')
{
square[9]=mark;
}
else{
cout<<"invalid move! ";
player--;
cin.ignore();
cin.get();
}
i=checkwin();
player++;
}
while(i== -1);
board();
if(i==1)
{
cout<<" \a congratulation! player "<<--player<< " win!";
}
else{
cout<<"\a game draw!";
}
cin.ignore();
cin.get();
return 0;
}
Output:

You might also like