THE C++ PROGRAMS..

1#.THE C++ PROGRAM FOR TWO PLAYER BINGO WITH ONE COMPUTER  PLAYER. .

//source code..
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<dos.h>
#include<graphics.h>
void main()
{randomize();
int gdriver = DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\tc\\BGI");   //for location of your compiler
start:

clrscr();
char ans,ch='y',ansa,ansb;
int d=0,z=0,i,j,k,l,A[5][5],B[5][5],y[25];                    
randomize();
int a[5][5],m[25],n,ia=0,ja=0;
retry1:
for(n=0;n<25;n++)
{
 m[n]=random(26);                                                    //player 1 matrix assign
  check1:                                                       //with code to check no number is repeated in the matrix
  for(l=0;l<n;l++)
  {
if(m[n]==m[l])
{
m[n]+=1;
goto check1;
}
   }
if(m[n]>25)
{
m[n]=0;
goto check1;
}
if(m[n]==0)
{
m[n]+=1;
goto check1;
}

A[ia][ja]=m[n];
a[ia][ja]=m[n];
ja++;
if(ja==5)
{
 ia++;
 ja=0;
}
}
cout<<"\n player 1 your matrix:";

for(i=0;i<5;i++)
{
cout<<"\n";
for(j=0;j<5;j++)
{
if(A[i][j]/10==0&&A[i][j]%10!=0||A[i][j]==0)
{delay(100);
setbkcolor(i*j);
cout<<" 0"<<A[i][j];
}
else
{delay(100);
 setbkcolor(i*j);
 cout<<" "<<A[i][j];
}
}
}
cout<<"\n player want to fill again?";
cin>>ansa;
if(ansa=='y'||ansa=='Y')
{
goto retry1;
}
clrscr();

int b[5][5],o[25],p,ib=0,jb=0;                                   
retry2:
for(p=0;p<25;p++)
{
 o[p]=random(26);
  check2:
  for(l=0;l<p;l++)
  {
if(o[p]==o[l])
{
o[p]+=1;
goto check2;
}
   }
if(o[p]>25)
{
o[p]=0;
goto check2;
}
if(o[p]==0)
{
o[p]+=1;
goto check2;
}
B[ib][jb]=o[p];
b[ib][jb]=o[p];
jb++;
if(jb==5)
{
 ib++;
 jb=0;
}
}
cout<<"\n computer's matrix:";
for(i=0;i<5;i++)                                                //computer matrix assign.
{
cout<<"\n";
for(j=0;j<5;j++)
{
if(B[i][j]/10==0&&B[i][j]%10!=0||B[i][j]==0)
{delay(100);
setbkcolor(i*j);
cout<<" 0"<<B[i][j];
}
else
{delay(100);
 setbkcolor(i*j);
 cout<<" "<<B[i][j];
}
}
}
/*
cout<<"\n want to fill again?";
cin>>ansb;
if(ansb=='y'||ansb=='Y')
{
 goto retry2;
}
cout<<"\n game is about to begin...."<<"\n are you ready?";
cin>>ch;
*/
goto skip;
fill:
{
 for(i=0;i<5;i++)
 {
for(j=0;j<5;j++)
{
A[i][j]=a[i][j];
B[i][j]=b[i][j];
}
}
z=0;
d=0;
}
skip:
for(k=1;k<=25&&ch=='y'||ch=='Y';k++)
{ setbkcolor(k/5);
 if(k%2==1)
 {
  cout<<"\n player 1 enter your number:";
  cin>>y[k-1];
 }
if(k%2==0)
       {
cout<<"\n compuers number is :";
y[k-1]=random(26);
cout<<y[k-1];
delay(1000);
       }
  check:
  for(l=0;l<k-1;l++)
  {
if(y[k-1]==y[l])
{
y[k-1]+=1;
goto check;
}
   }
if(y[k-1]>25)
{
y[k-1]=0;
goto check;
}
if(y[k-1]==0)
{
y[k-1]+=1;
goto check;
}
clrscr();
cout<<"\n the number is :"<<y[k-1];
cout<<"\n \n player 1 your matrix..(number announced is replaced by 0)";
for(i=0;i<5;i++)
{
cout<<"\n";
for(j=0;j<5;j++)
{

if(A[i][j]==y[k-1])
{
A[i][j]=0;
}
if(B[i][j]==y[k-1])
{
B[i][j]=0;
}

 if(A[i][j]/10==0&&A[i][j]%10!=0||A[i][j]==0)
{
cout<<" 0"<<A[i][j];
}
else
{
 cout<<" "<<A[i][j];
}
}
}
cout<<"\n computer's matrix is...(number announced is replaced by 0):";
for(i=0;i<5;i++)
{cout<<"\n";
for(j=0;j<5;j++)
{
if(B[i][j]/10==0&&B[i][j]%10!=0||B[i][j]==0)
{
cout<<" 0"<<B[i][j];
}
else
{
 cout<<" "<<B[i][j];
}
}
}
for(i=0;i<5;i++)
{
if(A[0][i]==A[1][i]&&A[0][i]==A[2][i]&&A[0][i]==A[3][i]&&A[0][i]==A[4][i]&&A[0][i]==0)
{
 z++;
}
if(B[0][i]==B[1][i]&&B[0][i]==B[2][i]&&B[0][i]==B[3][i]&&B[0][i]==B[4][i]&&B[0][i]==0)
{
 d++;
}
if(A[i][0]==A[i][1]&&A[i][0]==A[i][2]&&A[i][0]==A[i][3]&&A[i][0]==A[i][4]&&A[i][0]==0)
{
 z++;
}
if(B[i][0]==B[i][1]&&B[i][0]==B[i][2]&&B[i][0]==B[i][3]&&B[i][0]==B[i][4]&&B[i][0]==0)
{
 d++;
}
}
 if(A[0][0]==A[1][1]&&A[0][0]==A[2][2]&&A[0][0]==A[3][3]&&A[0][0]==A[4][4]&&A[0][0]==0)
 {
  z++;
 }
 if(B[0][0]==B[1][1]&&B[0][0]==B[2][2]&&B[0][0]==B[3][3]&&B[0][0]==B[4][4]&&B[0][0]==0)
 {
  d++;
 }
 if(A[4][0]==A[3][1]&&A[4][0]==A[2][2]&&A[4][0]==A[1][3]&&A[4][0]==A[0][4]&&A[4][0]==0)
 {
  z++;
 }
   if(B[4][0]==B[3][1]&&B[4][0]==B[2][2]&&B[4][0]==B[1][3]&&B[4][0]==B[0][4]&&B[4][0]==0)
 {
  d++;
 }
 cout<<"\n";
cout<<"\n player 1 your current score is:"<<z<<"\n";
cout<<"\n computer's current score is:"<<d<<"\n";
cout<<"\n for autoplay press any alphabet and enter..";
if(z==5&&d==5)
{
 cout<<"\n it's a tie.. ";
 goto end;
}
if(z>5&&d<=5)
{
cout<<"\n player 1 wins:";
goto end;
}
if(d>5&&z<=5)
{
cout<<"\n computer wins:";
goto end;
}
if(z>=5&&d<5)
{
cout<<"\n player 1 wins:";
goto end;
}
if(d>=5&&z<5)
{
cout<<"\n computer wins:";
goto end;
}

if(z>5&&d>5)
{
if(z>d)
{
cout<<"\n player 1 wins:";
goto end;
}
if(d>z)
{
cout<<"\n computer wins:";
goto end;
}
else
{
cout<<"\n it's a tie:";
goto end;
}
}
d=0;
z=0;
}

end:
cout<<"\n game over...";
cout<<"\n want to play again?";
cin>>ans;
if(ans=='y'||ans=='Y')
{
cout<<"\n want to continue with same matrix ?";
cin>>ch;
if(ch=='y')
{
goto fill;
}
 goto start;
}
getch();
}

/* paste the above code  into a notepad file and save the file as .cpp extention. open the file with turbo c or any c++ compiler you have..IF YOU GET ANY ERROR POST IN COMMENT BOX..I WILL REPLY SOON WITH SOLUTION..*/





2#.The Program to convert your age into number of days..

Well  an average Indian lives 23740 days. According to the age expectancy of Indians. want to know how much days of your life you have wasted..Just enter your Date Of Birth and see..
//source code
/* made by saurabh SINGH..do not copy or I will know:*/
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
#include<dos.h>
struct dob{
  int d;
  int m;
  int y;
 }user;


int aty(int d,int m,int y)             //Function to count number of days
{
struct dosdate_t sys;                       //To get current date.
_dos_getdate(&sys);
int dn=sys.day;
int mn=sys.month;
int i,j,k,days=0;
for(i=y;i<=sys.year;i++)
{
if(i==y)
{
for(j=m;j<=12;j++)
{
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
{
if(j==m)
{days+=31-d;
}
else
{
days+=31;
}
}
else if(j==2)
{
if(i%4==0)
{
if(j==m)
{
days+=29-d;
}
else
{
days+=29;
}
}
else
{
if(j==m)
{
days+=28-d;
}
else
{
days+=28;
}
}
}
else
{
if(j==m)
{
days+=30-d;
}
else
{
days+=30;
}
}
}


}
else if(i==sys.year)
{
for(j=1;j<=mn;j++)
{
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
{
if(j==mn)
{days+=dn;
}
else
{
days+=31;
}
}
else if(j==2)
{
if(i%4==0)
{
if(j==mn)
{
days+=dn;
}
else
{
days+=29;
}
}
else
{
if(j==mn)
{
days+=dn;
}
else
{
days+=28;
}
}
}
else
{
if(j==mn)
{
days+=dn;
}
else
{
days+=30;
}
}
}



}
else
{
for(j=1;j<=12;j++)
{
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
{
 days+=31;
}
else if(j==2)
{
if(i%4==0)
{
days+=29;
}
else
{
days+=28 ;
}
}
else
{
 days+=30;

}
}
}
}
return days;
};
int check_input(int d,int m,int y)
{ int flag=0;
struct dosdate_t sys;
_dos_getdate(&sys);

  if(y>=(sys.year+1))
  {
   flag++;
  }
  if(y%4==0)
  {
if(m>=13||m<=0)
{
flag++;
}
else if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
{
if(d>=32||d<=0)
{
flag++;
}
}
else if(m==2)
{
if(d>=30||d<=0)
{
flag++;
}
}
else
{
if(d>=31||d<=0)
{
 flag++;
}
}
  }
  else
  {
if(m>=13||m<=0)
{
flag++;
}
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
{
if(d>=32||d<=0)
{
flag++;
}
}
else if(m==2)
{
if(d>=29||d<=0)
{
flag++;
}
}
else
{
if(d>=31||d<=0)
{
 flag++;
}
}
  }
  if(flag==0)
  {
   return 0;
  }
  else
  {
   return 1;
  }

};
void input(dob &user)
{ renter:
cout<<"\n enter dob year:";
cin>>user.y;
cout<<"\n enter dob month:";
cin>>user.m;
cout<<"\n enter dob day:";
cin>>user.d;
if(check_input(user.d,user.m,user.y)!=0)
{
 cout<<"\n invalid input...";
 delay(500);
 clrscr();
 goto renter;
}
};
void main()
{
char ch='y';
do
{
clrscr();
struct dosdate_t sys;
_dos_getdate(&sys);
int dn=sys.day;
int mn=sys.month;
int day;
input(user);
cout<<"\n your date of birth:"<<user.d<<"/"<<user.m<<"/"<<user.y;
day=aty(user.d,user.m,user.y);
cout<<"\n current date:"<<dn<<"/"<<mn<<"/"<<sys.year;
cout<<"\n you are finely completed your :"<<day<<"days";
cout<<"\n want to enter again??..(y/n):";
cin>>ch;
}while(ch=='y');
clrscr();
cout<<"\n press any key to exit..";
getch();
}
/* the program is easy to understand . The program is complete and if you find any error just report me and post in comment box. And please if you want to modify it ask me first and I will do it for you.  */



No comments:

Post a Comment