SlideShare a Scribd company logo
PROJECT OF ITCS
By
Fatima batool & nimra mazhar
qudsiya yousaf & omama snober
to
sir tahir
TICK TAC TOE GAME
•INTRODUCTION:
Tic-toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for
two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who
succeeds in placing three of their marks in a horizontal, vertical, or diagonal row wins the
game.
The following example game is won by the first player, X:
Players soon discover that best play from both parties leads to a draw. Hence, tic-tac-toe is
most often played by young children.
TICK TAC TOE IN C++
• #include <iostream>
• using namespace std;
• char board[3][3] = {{'1','2','3'},{'4','5','6'},{'7','8','9'}};
• char turn = 'x';
• int row,column;
• bool draw = false;
• void display_board()
• {
• system("cls");
• cout<<"nn Tick Cross Game"<<endl;
• cout<<"tPlayer1 [x] n tPlayer2 [O]nn";
• cout<<"tt | | n";
TICK TAC TOE IN C++
• cout<<"tt "<<board[0][0]<<" | "<<board[0][1]<<" | "<<board[0][2]<<" n";
• cout<<"tt_____|_____|_____n";
• cout<<"tt | | n";
• cout<<"tt "<<board[1][0]<<" | "<<board[1][1]<<" | "<<board[1][2]<<" n";
• cout<<"tt_____|_____|_____n";
• cout<<"tt | | n";
• cout<<"tt "<<board[2][0]<<" | "<<board[2][1]<<" | "<<board[2][2]<<" n";
• cout<<"tt | | n";
• }
• void player_turn()
• {
• int choice;
• int row,column;
TICK TAC TOE IN C++
• if(turn =='x')
• cout<<"ntplayer1 [x] turn:";
•
• if(turn == 'k')
• cout<<"ntplayer2 [O] turn;";
•
• cin>>choice;
• switch(choice)
• {
• case 1 : row=0; column=0; break;
• case 2 : row=0; column=1; break;
• case 3 : row=0; column=2; break;
• case 4 : row=1; column=0; break;
• case 5 : row=1; column=1; break;
• case 6 : row=1; column=2; break;
• case 7 : row=2; column=0; break;
• case 8 : row=2; column=1; break;
• case 9 : row=2; column=2; break;
•
• default:
• cout<<"invalid choicen";
• break;
•
• }
• if(turn == 'x' && board[row][column]!='x' && board[row][column]!='x')
• {
• board[row][column]= 'x';
• turn = 'O';
• }
• else if(turn == 'O' && board[row][column]!='O' && board[row][column]!='O')
• {
• board[row][column]= 'O';
• turn= 'x';
• }
• else
• {
• cout<<"box already fielled!n please try again!!nn";
• player_turn();
• }
• cout<<" Player1 [x] turn:";
• }
• bool gameover()
• {
• //check win
• for(int i=0;i<3;i++)
• if(board[i][0] == board [i][1] && board[i][0] == board[i][2] || board[0][i] ==
board[1][i] && board[0][i] == board[2][i])
• return false;
• if(board[0][0] == board [1][1] && board[0][0] == board[2][2] || board[0][2] ==
board[1][1] && board[0][0] == board[0][2])
• return false;
•
• for(int i=0; i<3; i++)
• for(int j=0; j<3; j++)
• if(board[i][j] !='x' && board[i][j]!='O')
• return true;
• draw = true;
• return false;
• }
• main()
• {
• while(gameover())
• {
• display_board();
• player_turn();
• display_board();
• gameover();
• }
• if(turn=='O')
• cout<<"player1[x] wins!! congratulationn";
• else if(turn=='x')
• cout<<"player2[O] wins!! congratulationn”;
• }
• program end
INTRO OF FUNCTIONS IN C++
• In this article, you'll learn everything about functions in C++; what type of functions
are there, how to use them with examples. In programming, function refers to a segment
that groups code to perform a specific task.
• Depending on whether a function is predefined or created by programmer; there are two
types of function:
• Library Function
• User-defined Function
•Library Function
• Library functions are the built-in function in C++ programming.
• Programmer can use library function by invoking function directly; they don't need to write it
themselves.
INTRO OF FUNCTIONS IN C++
User-defined Function
• C++ allows programmer to define their own function.
• A user-defined function groups code to perform a specific task and that group of code is
given a name(identifier).
• When the function is invoked from any part of program, it all executes the codes defined in
the body of function
FOR LOOP
syntax
For(initializing statement;test expression;update statement;)
• The initialization statement is executed only once at the beginning
• Then, the test expression is evaluated.
• If the test expression is false, for loop is terminated. But if the test expression is
true, codes inside body of for loop is executed and update expression is updated
• Again the test expression is evaluated and this process repeats until the test
expression is false
WHILE LOOP
syntax
While(condition)
• {
statements
• }
• The while loop evaluates the test expression.
• If the test expression is true, codes inside the body of while loop is evaluated.
• Then, the test expression is evaluated again. This process goes on until the test
expression is false.
When the test expression is false, while loop is terminated.
SWITCH STATEMENT
•Syntax of switch statement:
• switch(expression)
• {
• Case constant1:
• Break;
• Case constant2:
• Break;
• Default:
• }
• When a case constant is found that matches the switch expression, control of the program passes to the
block of code associated with that case.
• In the above psedocode suppose the value of n is equal to constant2. The compiler will execute the block of
code associated with the case statement until the end of switch block, or until the break statement is
encountered.
• The break statement is used to prevent the code running into the next case.
ARRAY
• In programming, one of the frequently arising problem is to handle numerous data
of same type.
• Consider this situation, you are taking a survey of 100 people and you have to store
their age. To solve this problem in C++, you can create an integer array having 100
elements.
• An array is a collection of data that holds fixed number of values of same type. For
example: int age[100]
• Here, the age array can hold maximum of 100 elements of integer type.
• The size and type of arrays cannot be changed after its declaration.

More Related Content

What's hot

C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
Mohammad Shaker
 
Common mistakes in C programming
Common mistakes in C programmingCommon mistakes in C programming
Common mistakes in C programming
Larion
 
[MOSUT] Format String Attacks
[MOSUT] Format String Attacks[MOSUT] Format String Attacks
[MOSUT] Format String Attacks
Aj MaChInE
 
Python
PythonPython
Evgeniy Muralev, Mark Vince, Working with the compiler, not against it
Evgeniy Muralev, Mark Vince, Working with the compiler, not against itEvgeniy Muralev, Mark Vince, Working with the compiler, not against it
Evgeniy Muralev, Mark Vince, Working with the compiler, not against it
Sergey Platonov
 
A comparison between C# and Java
A comparison between C# and JavaA comparison between C# and Java
A comparison between C# and Java
Ali MasudianPour
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
Mohammad Shaker
 
Comp102 lec 6
Comp102   lec 6Comp102   lec 6
Comp102 lec 6
Fraz Bakhsh
 
Антон Бикинеев, Reflection in C++Next
Антон Бикинеев,  Reflection in C++NextАнтон Бикинеев,  Reflection in C++Next
Антон Бикинеев, Reflection in C++Next
Sergey Platonov
 
C++ L07-Struct
C++ L07-StructC++ L07-Struct
C++ L07-Struct
Mohammad Shaker
 
Python programing
Python programingPython programing
Python programing
hamzagame
 
.NET 2015: Будущее рядом
.NET 2015: Будущее рядом.NET 2015: Будущее рядом
.NET 2015: Будущее рядом
Andrey Akinshin
 
2.Format Strings
2.Format Strings2.Format Strings
2.Format Strings
phanleson
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control Structure
Mohammad Shaker
 
Антон Бикинеев, Writing good std::future&lt; C++ >
Антон Бикинеев, Writing good std::future&lt; C++ >Антон Бикинеев, Writing good std::future&lt; C++ >
Антон Бикинеев, Writing good std::future&lt; C++ >
Sergey Platonov
 
Python - Lecture 6
Python - Lecture 6Python - Lecture 6
Python - Lecture 6
Ravi Kiran Khareedi
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processing
Intro C# Book
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
Mohammad Shaker
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Yandex
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorial
nikomatsakis
 

What's hot (20)

C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 
Common mistakes in C programming
Common mistakes in C programmingCommon mistakes in C programming
Common mistakes in C programming
 
[MOSUT] Format String Attacks
[MOSUT] Format String Attacks[MOSUT] Format String Attacks
[MOSUT] Format String Attacks
 
Python
PythonPython
Python
 
Evgeniy Muralev, Mark Vince, Working with the compiler, not against it
Evgeniy Muralev, Mark Vince, Working with the compiler, not against itEvgeniy Muralev, Mark Vince, Working with the compiler, not against it
Evgeniy Muralev, Mark Vince, Working with the compiler, not against it
 
A comparison between C# and Java
A comparison between C# and JavaA comparison between C# and Java
A comparison between C# and Java
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
Comp102 lec 6
Comp102   lec 6Comp102   lec 6
Comp102 lec 6
 
Антон Бикинеев, Reflection in C++Next
Антон Бикинеев,  Reflection in C++NextАнтон Бикинеев,  Reflection in C++Next
Антон Бикинеев, Reflection in C++Next
 
C++ L07-Struct
C++ L07-StructC++ L07-Struct
C++ L07-Struct
 
Python programing
Python programingPython programing
Python programing
 
.NET 2015: Будущее рядом
.NET 2015: Будущее рядом.NET 2015: Будущее рядом
.NET 2015: Будущее рядом
 
2.Format Strings
2.Format Strings2.Format Strings
2.Format Strings
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control Structure
 
Антон Бикинеев, Writing good std::future&lt; C++ >
Антон Бикинеев, Writing good std::future&lt; C++ >Антон Бикинеев, Writing good std::future&lt; C++ >
Антон Бикинеев, Writing good std::future&lt; C++ >
 
Python - Lecture 6
Python - Lecture 6Python - Lecture 6
Python - Lecture 6
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processing
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorial
 

Similar to tick cross game

c++ Data Types and Selection
c++ Data Types and Selectionc++ Data Types and Selection
c++ Data Types and Selection
Ahmed Nobi
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 
Basics of Python
Basics of PythonBasics of Python
Basics of Python
Ease3
 
Mit6 094 iap10_lec04
Mit6 094 iap10_lec04Mit6 094 iap10_lec04
Mit6 094 iap10_lec04
Tribhuwan Pant
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second session
Ahmad Bashar Eter
 
C++ process new
C++ process newC++ process new
C++ process new
敬倫 林
 
Pi j1.2 variable-assignment
Pi j1.2 variable-assignmentPi j1.2 variable-assignment
Pi j1.2 variable-assignment
mcollison
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
Hawkman Academy
 
CSC PPT 13.pptx
CSC PPT 13.pptxCSC PPT 13.pptx
CSC PPT 13.pptx
DrRavneetSingh
 
Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)
Thinkful
 
Android course session 2 ( java basics )
Android course session 2 ( java basics )Android course session 2 ( java basics )
Android course session 2 ( java basics )
Keroles M.Yakoub
 
Variables
VariablesVariables
Exception handling and function in python
Exception handling and function in pythonException handling and function in python
Exception handling and function in python
TMARAGATHAM
 
ASSIGMENT.PY.pptx
ASSIGMENT.PY.pptxASSIGMENT.PY.pptx
ASSIGMENT.PY.pptx
KathiriyaPath
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1
Amr Alaa El Deen
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 Certifications
Giacomo Veneri
 
Klee and angr
Klee and angrKlee and angr
Klee and angr
Wei-Bo Chen
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
Wei-Yuan Chang
 
Unit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptxUnit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptx
SreeLaya9
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
sandeshshahapur
 

Similar to tick cross game (20)

c++ Data Types and Selection
c++ Data Types and Selectionc++ Data Types and Selection
c++ Data Types and Selection
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Basics of Python
Basics of PythonBasics of Python
Basics of Python
 
Mit6 094 iap10_lec04
Mit6 094 iap10_lec04Mit6 094 iap10_lec04
Mit6 094 iap10_lec04
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second session
 
C++ process new
C++ process newC++ process new
C++ process new
 
Pi j1.2 variable-assignment
Pi j1.2 variable-assignmentPi j1.2 variable-assignment
Pi j1.2 variable-assignment
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
CSC PPT 13.pptx
CSC PPT 13.pptxCSC PPT 13.pptx
CSC PPT 13.pptx
 
Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)
 
Android course session 2 ( java basics )
Android course session 2 ( java basics )Android course session 2 ( java basics )
Android course session 2 ( java basics )
 
Variables
VariablesVariables
Variables
 
Exception handling and function in python
Exception handling and function in pythonException handling and function in python
Exception handling and function in python
 
ASSIGMENT.PY.pptx
ASSIGMENT.PY.pptxASSIGMENT.PY.pptx
ASSIGMENT.PY.pptx
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 Certifications
 
Klee and angr
Klee and angrKlee and angr
Klee and angr
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
 
Unit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptxUnit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptx
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
 

Recently uploaded

University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
soxrziqu
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
manishkhaire30
 
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
Social Samosa
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
nuttdpt
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
aqzctr7x
 
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
u86oixdj
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
rwarrenll
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
74nqk8xf
 
Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...
Bill641377
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
slg6lamcq
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
Lars Albertsson
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
zsjl4mimo
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
v3tuleee
 
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
mzpolocfi
 
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
dwreak4tg
 
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataPredictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Kiwi Creative
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
apvysm8
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
Sm321
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
sameer shah
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
Walaa Eldin Moustafa
 

Recently uploaded (20)

University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
 
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
 
Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
 
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
 
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
 
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataPredictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
 

tick cross game

  • 1. PROJECT OF ITCS By Fatima batool & nimra mazhar qudsiya yousaf & omama snober to sir tahir
  • 2. TICK TAC TOE GAME •INTRODUCTION: Tic-toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row wins the game. The following example game is won by the first player, X: Players soon discover that best play from both parties leads to a draw. Hence, tic-tac-toe is most often played by young children.
  • 3. TICK TAC TOE IN C++ • #include <iostream> • using namespace std; • char board[3][3] = {{'1','2','3'},{'4','5','6'},{'7','8','9'}}; • char turn = 'x'; • int row,column; • bool draw = false; • void display_board() • { • system("cls"); • cout<<"nn Tick Cross Game"<<endl; • cout<<"tPlayer1 [x] n tPlayer2 [O]nn"; • cout<<"tt | | n";
  • 4. TICK TAC TOE IN C++ • cout<<"tt "<<board[0][0]<<" | "<<board[0][1]<<" | "<<board[0][2]<<" n"; • cout<<"tt_____|_____|_____n"; • cout<<"tt | | n"; • cout<<"tt "<<board[1][0]<<" | "<<board[1][1]<<" | "<<board[1][2]<<" n"; • cout<<"tt_____|_____|_____n"; • cout<<"tt | | n"; • cout<<"tt "<<board[2][0]<<" | "<<board[2][1]<<" | "<<board[2][2]<<" n"; • cout<<"tt | | n"; • } • void player_turn() • { • int choice; • int row,column;
  • 5. TICK TAC TOE IN C++ • if(turn =='x') • cout<<"ntplayer1 [x] turn:"; • • if(turn == 'k') • cout<<"ntplayer2 [O] turn;"; • • cin>>choice;
  • 6. • switch(choice) • { • case 1 : row=0; column=0; break; • case 2 : row=0; column=1; break; • case 3 : row=0; column=2; break; • case 4 : row=1; column=0; break;
  • 7. • case 5 : row=1; column=1; break; • case 6 : row=1; column=2; break; • case 7 : row=2; column=0; break; • case 8 : row=2; column=1; break; • case 9 : row=2; column=2; break; • • default:
  • 8. • cout<<"invalid choicen"; • break; • • } • if(turn == 'x' && board[row][column]!='x' && board[row][column]!='x') • { • board[row][column]= 'x';
  • 9. • turn = 'O'; • } • else if(turn == 'O' && board[row][column]!='O' && board[row][column]!='O') • { • board[row][column]= 'O'; • turn= 'x';
  • 10. • } • else • { • cout<<"box already fielled!n please try again!!nn"; • player_turn(); • } • cout<<" Player1 [x] turn:"; • }
  • 11. • bool gameover() • { • //check win • for(int i=0;i<3;i++) • if(board[i][0] == board [i][1] && board[i][0] == board[i][2] || board[0][i] == board[1][i] && board[0][i] == board[2][i]) • return false;
  • 12. • if(board[0][0] == board [1][1] && board[0][0] == board[2][2] || board[0][2] == board[1][1] && board[0][0] == board[0][2]) • return false; • • for(int i=0; i<3; i++) • for(int j=0; j<3; j++) • if(board[i][j] !='x' && board[i][j]!='O') • return true;
  • 13. • draw = true; • return false; • } • main() • { • while(gameover()) • { • display_board();
  • 14. • player_turn(); • display_board(); • gameover(); • } • if(turn=='O') • cout<<"player1[x] wins!! congratulationn"; • else if(turn=='x') • cout<<"player2[O] wins!! congratulationn”; • } • program end
  • 15. INTRO OF FUNCTIONS IN C++ • In this article, you'll learn everything about functions in C++; what type of functions are there, how to use them with examples. In programming, function refers to a segment that groups code to perform a specific task. • Depending on whether a function is predefined or created by programmer; there are two types of function: • Library Function • User-defined Function •Library Function • Library functions are the built-in function in C++ programming. • Programmer can use library function by invoking function directly; they don't need to write it themselves.
  • 16. INTRO OF FUNCTIONS IN C++ User-defined Function • C++ allows programmer to define their own function. • A user-defined function groups code to perform a specific task and that group of code is given a name(identifier). • When the function is invoked from any part of program, it all executes the codes defined in the body of function
  • 17. FOR LOOP syntax For(initializing statement;test expression;update statement;) • The initialization statement is executed only once at the beginning • Then, the test expression is evaluated. • If the test expression is false, for loop is terminated. But if the test expression is true, codes inside body of for loop is executed and update expression is updated • Again the test expression is evaluated and this process repeats until the test expression is false
  • 18. WHILE LOOP syntax While(condition) • { statements • } • The while loop evaluates the test expression. • If the test expression is true, codes inside the body of while loop is evaluated. • Then, the test expression is evaluated again. This process goes on until the test expression is false. When the test expression is false, while loop is terminated.
  • 19. SWITCH STATEMENT •Syntax of switch statement: • switch(expression) • { • Case constant1: • Break; • Case constant2: • Break; • Default: • } • When a case constant is found that matches the switch expression, control of the program passes to the block of code associated with that case. • In the above psedocode suppose the value of n is equal to constant2. The compiler will execute the block of code associated with the case statement until the end of switch block, or until the break statement is encountered. • The break statement is used to prevent the code running into the next case.
  • 20. ARRAY • In programming, one of the frequently arising problem is to handle numerous data of same type. • Consider this situation, you are taking a survey of 100 people and you have to store their age. To solve this problem in C++, you can create an integer array having 100 elements. • An array is a collection of data that holds fixed number of values of same type. For example: int age[100] • Here, the age array can hold maximum of 100 elements of integer type. • The size and type of arrays cannot be changed after its declaration.