Tic Tack Toe game

TECHNIQUE:-


A player can play a good game of tic-tac-toe to follow some rule. 
  1. Win: If the player has two sign in a row, they can place a third sign to get three in a row.
  2. Block: If the opponent has two sign in a row, the player must play the third sign themselves to block the opponent.
  3. Fork: Create an opportunity where the player has two way the win. 
  4. play with rules is the major property of the game.

tic



RUN THE CODE IN C++ COMPILER AND ENJOY THE GAME:-

CODE:-

#include<iostream>
using namespace std;
int main()
{
int arr[11],turn2=0,true2,b,s[11],g=1;  for(b=1; b<=9; b++) {  arr[b]=7;  s[b]=17; }   
while(1)
{
int n;
true2=0; int linux=0;
turn2++;
if((turn2%2)!=0){  cout<<endl<<"player 1 turn enter position"<<endl;
uppe: if(linux==1) {
     cout<<endl<<"dyan se"<<endl;  }
cin>>n; for(b=1; b<=9;  b++) if(s[b]==n) {
  linux=1;  goto uppe;  }   s[g]=n; g++;
arr[n]=1;  }
else
{  cout<<endl<<"player 2 turn enter  position"<<endl;
upper: if(linux==1){       cout<<endl<<"dyan se"<<endl;   }
cin>>n;     for(b=1; b<=9;  b++) if(s[b]==n) {
   linux=1;  goto upper;  }  s[g]=n; g++; arr[n]=2;
} cout<<endl; 
for(b=1; b<=9; b++)

cout<<arr[b]<<" ";  if((b)%3==0) cout<<endl;
}
if(arr[1]==1&&arr[2]==1&&arr[3]==1||arr[4]==1&&arr[5]==1&&arr[6]==1||
arr[7]==1&&arr[8]==1&&arr[9]==1||arr[1]==1&&arr[4]==1&&arr[7]==1||
arr[2]==1&&arr[5]==1&&arr[7]==1||arr[3]==1&&arr[6]==1&&arr[9]==1||
arr[1]==1&&arr[5]==1&&arr[9]==1||arr[9]==1&&arr[3]==1&&arr[5]==1&&arr[7]==1)
{ true2=1;  }
if(arr[1]==2&&arr[2]==2&&arr[3]==2||arr[4]==2&&arr[5]==2&&arr[6]==2||
arr[7]==2&&arr[8]==2&&arr[9]==2||arr[1]==2&&arr[4]==2&&arr[6]==2||
arr[2]==2&&arr[5]==2&&arr[7]==2||arr[3]==2&&arr[6]==2&&arr[9]==2||
arr[1]==2&&arr[5]==2&&arr[9]==2||arr[9]==2&&arr[3]==2&&arr[5]==2&&arr[7]==2)
{ true2=1; }
if(true2==1&&turn2%2!=0)   { cout<<"player1"<<endl;    break; }
if(true2==1&&turn2%2==0)    {
cout<<"player2"<<endl;    break;  } }
}


Calender Using C++

Calender project Implementation using c++

#include<iostream>

using namespace std;
int leapcheck(int y);
int get(int y,int m,int *);
int main()
{
int d,m,y,mt,dt,yt,k;
char day_name[7][5]={"sun","mon","tue","wed","thur","fri","sat"};
int month[12]={6,2,2,5,0,3,5,1,4,6,2,4};
int century[4]={0,5,3,1};
cin>>d>>m>>y;
dt=d%7; 
mt=get(y,m,month);
k=y%100;
yt=k%7+k/4+century[((y/100)%4)];
int sum=(yt+mt+dt)%7;
cout<<day_name[sum];

}
int leapcheck(int year){
if(year%4==0)
if(year%100==0)
if(year%400==0) return 1;
else return 0;
else return 1;
return 0;
}
int get(int y,int m,int *month)
{
int mt;
if(leapcheck(y)==1)
{ if(m==1) mt=5; else if(m==2) mt=1; else mt=month[m-1];}
else
return month[m-1];
return mt;
}




--------------------------------------------------------------------------------------------------------------



#include<iostream>
#include<conio.h>
using namespace std;
int leapcheck(int y);
int get(int y,int m,int *);
void print(int date,int day,int year,int month);
int days(int year,int mo)
{
int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
months[1] = 29;
return months[mo-1];

}
int main()
{
int d,m,y,mt,dt,yt,k;
char day_name[7][5]={"sun","mon","tue","wed","thur","fri","sat"};
int month[12]={6,2,2,5,0,3,5,1,4,6,2,4};
int century[4]={0,5,3,1};
cin>>d>>m>>y;
dt=d%7; 
mt=get(y,m,month);
k=y%100;
yt=k%7+k/4+century[((y/100)%4)];
int sum=(yt+mt+dt)%7;
//cout<<day_name[sum];
print(d,sum,y,m);
getch();
}
int leapcheck(int year){
if(year%4==0)
if(year%100==0)
if(year%400==0) return 1;
else return 0;
else return 1;
return 0;
}
int get(int y,int m,int *month)
{
int mt;
if(leapcheck(y)==1)
{ if(m==1) mt=5; else if(m==2) mt=1; else mt=month[m-1];}
else
return month[m-1];
return mt;
}
void print(int date,int day,int year,int month)
{
int row_find=7,ir=0,p;
int arr[6][7]={0};
while(row_find<date) { row_find+=7; ir++;}
arr[ir][day]=date;
int test=date-1; int testpos=day-1; int c=0;
int irtemp=ir;
while(irtemp>=0)
{
if(testpos>=0){
testpos--;
c++;
} else {testpos=6; irtemp--;}
}
if(c<test) ir++;
cout<<ir<<endl;
p=date+1;
int day_month=days(year,month);
for(int t=day+1;t<7;t++,p++)
arr[ir][t]=p;
for(int i=ir+1;i<5;i++){
for(int j=0;j<7;j++){
arr[i][j]=p;
p++;
if(p>day_month) break;
}
if(p>day_month) break;
}
p=date-1; int k=day-1;
while(ir>=0)
{
if(k>=0){
arr[ir][k]=p;
k--;
}
else {k=6; ir--; p++;}
p--; if(p<=0) break;

}
for(int i=0;i<5;i++)
for(int j=0;j<7;j++)
cout<<arr[i][j]<<"n"[j!=6];
}



---------------------------------------------------------------------------





#include<iostream>
using namespace std;
int leapcheck(int y);
int get(int y,int m,int *);
void print(int date,int day,int year,int month);
void days(int);
int days(int year,int mo)
{
int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
months[1] = 29;
return months[mo-1];

}
int main()
{
int d,m,y,mt,dt,yt,k;
// char day_name[7][5]={"sun","mon","tue","wed","thur","fri","sat"};
int month[12]={6,2,2,5,0,3,5,1,4,6,2,4};
int century[4]={0,5,3,1};
cin>>d>>m>>y;
for(int m=1;m<13;m++){
dt=d%7; 
mt=get(y,m,month);
k=y%100;
yt=k%7+k/4+century[((y/100)%4)];
int sum=(yt+mt+dt)%7;
print(d,sum,y,m);
cout<<endl<<endl;
}
return 0;
}
int leapcheck(int year){
if(year%4==0)
if(year%100==0)
if(year%400==0) return 1;
else return 0;
else return 1;
return 0;
}
int get(int y,int m,int *month)
{
int mt;
if(leapcheck(y)==1)
{ if(m==1) mt=5; else if(m==2) mt=1; else mt=month[m-1];}
else
return month[m-1];
return mt;
}
void print(int date,int day,int year,int month)
{
int row_find=7,ir=0,p; int col=5;
int arr[6][7]={0};
while(row_find<date) { row_find+=7; ir++;}
arr[ir][day]=date;
int test=date-1; int testpos=day-1; int c=0;
int irtemp=ir;
while(irtemp>=0)
{
if(testpos>=0){
testpos--;
c++;
} else {testpos=6; irtemp--;}
}
if(c<test) {ir++; col++;}

p=date+1;
int day_month=days(year,month);
for(int t=day+1;t<7;t++,p++)
arr[ir][t]=p;
for(int i=ir+1;i<col;i++){
for(int j=0;j<7;j++){
arr[i][j]=p;
p++;
if(p>day_month) break;
}
if(p>day_month) break;
}
p=date-1; int k=day-1;
while(ir>=0)
{
if(k>=0){
arr[ir][k]=p;
k--;
}
else {k=6; ir--; p++;}
p--; if(p<=0) break;

}
days(month);
cout<<" ";
for(int i=0;i<col;i++)
for(int j=0;j<7;j++){
cout<<arr[i][j]<<"n"[j!=6];
if(arr[i][j]<10&&j!=6) cout<<" ";
else cout<<" ";
}
}
void days(int m)
{
char *s[12]={"---January-------","---February-------","---March-------","---April-------","---May-------","---June-------","---July-------","---August---------","---September--------","---October---------","---November---------","---December--------"};
cout<<s[m-1]<<endl;
cout<<" sun"<<" "<<"m"<<" "<<"tu"<<" "<<"w"<<" "<<" th"<<" "<<"f"<<" "<<" sat"<<endl;


}