Cricket Database project using C++
Cricket Database project Source Code
#include
#include
#include
#include
#include
#include #include
#include
#include
/*------------------base class------------------------------*/
class player
{
float strate,btavg,blavg;
int runs,wic,hiscr,bbol,overs,balls,innings,r1,w1,o1,b1,hcen,cen,i1;
public:
int mat;
char name[10];
char country[10];
player();
void getdata();
void update();
void showdata();
void calculation();
void search();
void modify();
void updatetest();
void menu();
};
/*----------------------constructor------------------------------*/
player::player()
{
strcpy(name," ");
strcpy(country," ");
strate=0;
btavg=0;
innings=0;
balls=0;
overs=0;
blavg=0;
runs=0;
wic=0;
mat=0;
hiscr=0;
bbol=0;
cen=0;
hcen=0;
}
/* -----------------------------fun for calculation -----------*/
void player::calculation()
{
strate=(float)(runs/balls)*100;
btavg=(float)runs/innings;
blavg=(float)overs/wic;
}
/*---------------------- scan data from user -----------------*/
void player::getdata()
{
cleardevice();
settextstyle(1,0,1);
outtextxy(100,50," ENTER DATA ");
settextstyle(0,0,1);
//cout<<"\n\t\t ENTER INFORMATION: \n\n";
cout<<"\n\n\n\t\t Name: ";
gets(name);
cout<<"\n\t\t Country: ";
gets(country);
cout<<"\n\t\t Matches: ";
cin>>mat;
cout<<"\n\t\t Innings: ";
cin>>innings;
cout<<"\n\t\t Runs: ";
cin>>runs;
cout<<"\n\t\t Balls Played: ";
cin>>balls;
cout<<"\n\t\t Fifties: ";
cin>>hcen;
cout<<"\n\t\t Hundreds: ";
cin>>cen;
cout<<"\n\t\t Overs Bowled: ";
cin>>overs;
cout<<"\n\t\t Wickets: ";
cin>>wic;
cout<<"\n\t\t Best Batting Performance: ";
cin>>hiscr;
cout<<"\n\t\t Best Bowling Performance: ";
cin>>bbol;}
/*-------------- fun used for modification -----------------*/
void player::update()
{
//cout<<"\n\n\t\t ENTER DATA OF LAST MATCH\n";
cleardevice();
settextstyle(1,0,1);
outtextxy(100,50," ENTER DATA OF LAST MATCH");
settextstyle(0,0,1);
cout<<"\n\n\n\t\t Runs: ";
cin>>r1;
if(r1>100)
cen++;
if(r1>50&&r1<100)
hcen++;
runs+=r1;
cout<<"\n\t\t Wickets: ";
cin>>w1;
wic+=w1;
mat++;
cout<<"\n\t\t OUT/NOTOUT(y/n): ";
char ch=getche();
if(ch=='y')
innings++;
cout<<"\n\t\t Overs Bowled :";
cin>>o1;
overs+=o1;
cout<<"\n\t\t Balls Played";
cin>>b1;
balls+=b1;
if(hiscr<r1)
hiscr=r1;
if(bbol<w1)
bbol=w1;
}
/*--------------------- fun for displaying the data --------------*/
void player::showdata()
{
int x=50;
char str[20];
cleardevice();
rectangle(50,150,610,250);
line(50,200,610,200);
for(int i=0;i<6;i++)
{
x+=80;
line(x,150,x,250);
}
outtextxy( 60,170,"MATCHS");
outtextxy(140,170,"RUNS");
outtextxy(220,170,"WICKETS");
outtextxy(300,170,"AVG(BAT)");
outtextxy(380,170,"AVG(BOL)");
outtextxy(460,170,"100`s");
outtextxy(540,170,"50`s");
outtextxy( 50,280,"BEST PERFORMANCE IN A MATCH ::");
outtextxy( 50,300,"RUNS : ");
outtextxy( 50,320,"WICKETS :");
sprintf(str,"%d",mat);
outtextxy(60,220,str);
sprintf(str,"%d",runs);
outtextxy(140,220,str);
sprintf(str,"%d",wic);
outtextxy(220,220,str);
sprintf(str,"%f",btavg);
outtextxy(300,220,str);
sprintf(str,"%f",blavg);
outtextxy(380,220,str);
sprintf(str,"%d",cen);
outtextxy(460,220,str);
sprintf(str,"%d",hcen);
outtextxy(540,220,str);
settextstyle(1,0,1);
sprintf(str,"%s",country);
outtextxy(50,110,str);
sprintf(str,"%s",name);
outtextxy(50,90,str);
settextstyle(0,0,1);
sprintf(str,"%d",hiscr);
outtextxy(130,300,str);
sprintf(str,"%d",bbol);
outtextxy(130,320,str);
getch();
}
fstream file,file1,tfile,tfile1;
int ch1;
/*----------------------------- main -------------*/
void main()
{
player p;
clrscr();
int ch,i=0,gm,gd=DETECT;
char st[10];
int x,y;
x=100;
y=100;initgraph(&gd,&gm,"g:\\tc\\bgi");
char pname[10],cname[10],password[10]="",c;
setbkcolor(BLUE);
while(!kbhit())
{settextstyle(1,0,6);
outtextxy(150,200,"CRICKETER`S");
outtextxy(170,270,"DATABASE");
}
settextstyle(0,0,1);
cleardevice();
setcolor(11);
settextstyle(1,0,1);
outtextxy(100,380,"LOADING...");for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
if(i<400&&i>370)
delay(40);
delay(10);
}
settextstyle(0,0,1);
cleardevice();
getch();
//cleardevice();
/*------------------ starting menu -------*/
int tag;
tag:
cleardevice();
settextstyle(1,0,2);
outtextxy(200,100," 1 :: ONE DAY") ;
outtextxy(200,130," 2 :: TEST") ;
//cin>>ch1;ch1=getche();
ch1=ch1-'0';
settextstyle(0,0,1);
if(ch1==1)
{
do
{
cleardevice();
//p.menu();
settextstyle(1,0,2);
outtextxy(200,100," 1 :: ADD RECORDS ") ;
outtextxy(200,130," 2 :: MODIFY RECORDS ") ;
outtextxy(200,160," 3 :: SEARCH RECORD (NAME)") ;
outtextxy(200,190," 4 :: SEARCH RECORD (COUNTRY)") ;
outtextxy(200,220," 5 :: LIST OF PLAYER OF ONE COUNTRY") ;
outtextxy(200,250," 6 :: BACK") ;
outtextxy(200,280," 7 :: EXIT") ;
//cin>>ch;
ch=getche();
ch=ch-'0';settextstyle(0,0,1);
switch(ch)
{
/*----- ODI insert --------------*/
case 1:cleardevice();
file.open("ODI.txt",ios::in|ios::out|ios::ate);
file.seekp(0,ios::end);
p.getdata();
p.calculation();
file.write((char*)&p,sizeof(p));
file.clear();
file.close();
c=getch();
break;
/*------- ODI name wise search -----------*/case 3:
cleardevice();
cout<<"\n\t\t Name For Search: ";
gets(pname);
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
//if(i>250&&i<300)
// delay(40);delay(10);
}
cleardevice();
int flag=0;
file.open("ODI.txt",ios::in|ios::out|ios::ate);
file.seekp(0,ios::beg);
while(file.read((char*)&p,sizeof(p)))
{
if(!strcmp(p.name,pname))
{
flag=1;
cout<<"\n\n";
p.showdata();
break;
}
}
file.clear();
file.close();
if(flag==0)
cout<<"\n\t\t Record Not Found";
//cout<<"\n\n\t\t Enter Any Key To Cont.";
//cin>>c;
c=getch();
break;/*-------------- ODI modification --------------*/
case 2:cleardevice();
cout<<"\n\t\tENTER PASSWORD ";
int i=0;
while(i<6)
{
password[i]=getche();
cout<<"*";
i++;
}
getch();
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
if(i>350&&i<400)
delay(40);
}
cleardevice();if(!strcmp("vineet",password))
{
cout<<"\n\t\t Name For Modification ";
gets(pname);
flag=0;
file.open("ODI.txt",ios::in|ios::out|ios::ate);
file1.open("temp1.txt",ios::in|ios::out|ios::ate);
if(!tfile1)
cout<<"\nerror";
file1.seekp(0,ios::beg);
file.seekp(0,ios::beg);
while(file.read((char*)&p,sizeof(p)))
{if(!strcmp(p.name,pname))
{
flag=1;
p.update();
p.calculation();
file1.write((char*)&p,sizeof(p));
}
else
{
tfile1.write((char*)&p,sizeof(p));
}
}
file.clear();
file.close();
file1.clear();
file1.close();
if(flag==1)
{
remove("ODI.txt");
rename("temp1.txt","ODI.txt");}
if(flag==0)
cout<<"\n\t\t Record Not Found";
}
else
cout<<"\n\t\t Wrong Password";
c=getch();
break;/*------------ ODI country wise search ------*/
case 4:
cleardevice();
cout<<"\n\t\t Country`s Name For Search: ";
gets(cname);
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
//if(i>333&&i<400)
// delay(40);
}
cleardevice();
flag=0;
file.open("ODI.txt",ios::in|ios::out|ios::ate);
file.seekp(0,ios::beg);
while(file.read((char*)&p,sizeof(p)))
{
if(!strcmp(p.country,cname))
{
flag=1;
cout<<"\n\n";
p.showdata();
}
}
file.clear();
file.close();
if(flag==0)
cout<<"\n\t\t Record Not Found";
//cout<<"\n\n\t\t Enter Any Key To Cont.";
//cin>>c;
c=getch();
break;
/*------ ODI list of players -----------*/
case 5:
cleardevice();
cout<<"\n\t\t Country`s Name For Search: ";
gets(cname);
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
}
cleardevice();
flag=0;
file.open("ODI.txt",ios::in|ios::out|ios::ate);
file.seekp(0,ios::beg);
while(file.read((char*)&p,sizeof(p)))
{
if(!strcmp(p.country,cname))
{
flag=1;
settextstyle(1,0,1);
//cout<<"\n\n\t\t"< <p.name;sprintf(st,"%s",p.name);
outtextxy(x,y,st);
y=y+30;
settextstyle(0,0,1);
}
}
file.clear();
file.close();
if(flag==0)
cout<<"\n\t\t Record Not Found";//cout<<"\n\n\t\t Enter Any Key To Cont.";
//cin>>c;
c=getch();
break;
case 6:
goto tag;
//break;case 7:
exit(0);
break;
}
}while(1);
}
if(ch1==2)
{
do
{
cleardevice();
//p.menu();
settextstyle(1,0,2);
outtextxy(200,100," 1 :: ADD RECORDS ") ;
outtextxy(200,130," 2 :: MODIFY RECORDS ") ;
outtextxy(200,160," 3 :: SEARCH RECORD (NAME)") ;
outtextxy(200,190," 4 :: SEARCH RECORD (COUNTRY)") ;
outtextxy(200,220," 5 :: LIST OF PLAYER OF ONE COUNTRY") ;
outtextxy(200,250," 6 :: BACK") ;
outtextxy(200,280," 7 :: EXIT") ;
//cin>>ch;
ch=getche();
ch=ch-'0';settextstyle(0,0,1);
switch(ch)
{
/*------------------ TEST insert ------------------*/
case 1:
cleardevice();
tfile.open("TEST.txt",ios::in|ios::out|ios::ate);
tfile.seekp(0,ios::end);
p.getdata();
p.calculation();
tfile.write((char*)&p,sizeof(p));
tfile.clear();
tfile.close();
break;
/*------------------ TEST name wise search ------------------*/
case 3:
cleardevice();
cout<<"\n\t\t Name For Search: ";
gets(pname);
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
if(i>350&&i<400)
delay(40);
}
cleardevice();
int flag=0;
tfile.open("TEST.txt",ios::in|ios::out|ios::ate);
tfile.seekp(0,ios::beg);
while(tfile.read((char*)&p,sizeof(p)))
{
if(!strcmp(p.name,pname))
{
flag=1;
cout<<"\n\n";
p.showdata();
break;
}
}
tfile.clear();
tfile.close();
if(flag==0)
cout<<"\n\t\t Record Not Found";
c=getch();
break;
/*------------------ TEST modification ------------------*/
case 2:
cleardevice();
cout<<"\n\t\tENTER PASSWORD";
int i=0;
while(i<6)
{
password[i]=getche();
cout<<"*";
i++;
}
getch();
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
if(i>350&&i<400)
delay(40);
}
cleardevice();if(!strcmp("vineet",password))
{
cout<<"\n\t\t Name For Modification ";
gets(pname);
flag=0;
tfile.open("TEST.txt",ios::in|ios::out|ios::ate);
tfile1.open("temp1.txt",ios::in|ios::out|ios::ate);
if(!tfile1)
cout<<"\nerror";
tfile1.seekp(0,ios::beg);
tfile.seekp(0,ios::beg);
while(tfile.read((char*)&p,sizeof(p)))
{if(!strcmp(p.name,pname))
{
flag=1;
cout<<"\n\t\t Enter Data For First Inning: ";
p.update();
cout<<"\n\t\t Enter Data For Second Inning: ";
p.update();
p.mat--;
p.calculation();
tfile1.write((char*)&p,sizeof(p));
}
else
{
tfile1.write((char*)&p,sizeof(p));
}
}
tfile.clear();
tfile.close();
tfile1.clear();
tfile1.close();
if(flag==1)
{
remove("TEST.txt");
rename("temp1.txt","TEST.txt");}
if(flag==0)
cout<<"\n\t\t Record Not Found";
}
else
cout<<"\n\t\t Wrong Password";
c=getch();
break;
/*------------------ TEST country wise search ------------------*/
case 4:
cleardevice();
cout<<"\n\t\t Country`s Name For Search: ";
gets(cname);
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
if(i>350&&i<400)
delay(40);
}
cleardevice();
flag=0;
tfile.open("TEST.txt",ios::in|ios::out|ios::ate);
tfile.seekp(0,ios::beg);
while(tfile.read((char*)&p,sizeof(p)))
{
if(!strcmp(p.country,cname))
{
flag=1;
cout<<"\n\n";
p.showdata();
}
}
tfile.clear();
tfile.close();
if(flag==0)
cout<<"\n\t\t Record Not Found";
break;
/*------------------ TEST list ------------------*/
case 5:
cleardevice();
cout<<"\n\t\t Country`s Name For Search: ";
gets(cname);
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
if(i>350&&i<400)
delay(40);
}
cleardevice();
flag=0;
tfile.open("TEST.txt",ios::in|ios::out|ios::ate);
tfile.seekp(0,ios::beg);
while(tfile.read((char*)&p,sizeof(p)))
{
if(!strcmp(p.country,cname))
{
flag=1;
settextstyle(1,0,1);
//cout<<"\n\n\t\t"< <p.name;sprintf(st,"%s",p.name);
outtextxy(x,y,st);
y=y+30;
settextstyle(0,0,1);
//cout<<"\n\n\t\t"< <p.name;
}
}
file.clear();
file.close();
if(flag==0)
cout<<"\n\t\t Record Not Found";
//char c;
//cout<<"\n\n\t\t Enter Any Key To Cont.";
//cin>>c;
c=getch();
break;
case 6:
goto tag;
case 7:
exit(0);
break;
}
}while(1);
}
}
/* ------------------------------end of main -----------------*/#include
#include
#include
#include
#include
#include #include
#include
#include
/*------------------base class--------------------------------*/
class player
{
float strate,btavg,blavg;
int runs,wic,hiscr,bbol,overs,balls,innings,r1,w1,o1,b1,hcen,cen,i1;
public:
int mat;
char name[10];
char country[10];
player();
void getdata();
void update();
void showdata();
void calculation();
void search();
void modify();
void updatetest();
void menu();
};
/*----------------------constructor-------------------------------------*/
player::player()
{
strcpy(name," ");
strcpy(country," ");
strate=0;
btavg=0;
innings=0;
balls=0;
overs=0;
blavg=0;
runs=0;
wic=0;
mat=0;
hiscr=0;
bbol=0;
cen=0;
hcen=0;
}
/* -----------------------------fun for calculation ----------------------*/
void player::calculation()
{
strate=(float)(runs/balls)*100;
btavg=(float)runs/innings;
blavg=(float)overs/wic;
}
/*---------------------- scan data from user -------------------------*/
void player::getdata()
{
cleardevice();
settextstyle(1,0,1);
outtextxy(100,50," ENTER DATA ");
settextstyle(0,0,1);//cout<<"\n\t\t ENTER INFORMATION: \n\n";
cout<<"\n\n\n\t\t Name: ";
gets(name);
cout<<"\n\t\t Country: ";
gets(country);
cout<<"\n\t\t Matches: ";
cin>>mat;
cout<<"\n\t\t Innings: ";
cin>>innings;
cout<<"\n\t\t Runs: ";
cin>>runs;
cout<<"\n\t\t Balls Played: ";
cin>>balls;
cout<<"\n\t\t Fifties: ";
cin>>hcen;
cout<<"\n\t\t Hundreds: ";
cin>>cen;
cout<<"\n\t\t Overs Bowled: ";
cin>>overs;
cout<<"\n\t\t Wickets: ";
cin>>wic;
cout<<"\n\t\t Best Batting Performance: ";
cin>>hiscr;
cout<<"\n\t\t Best Bowling Performance: ";
cin>>bbol;}
/*------------------------------ fun used for modification -----------------*/
void player::update()
{
//cout<<"\n\n\t\t ENTER DATA OF LAST MATCH\n";
cleardevice();
settextstyle(1,0,1);
outtextxy(100,50," ENTER DATA OF LAST MATCH");
settextstyle(0,0,1);
cout<<"\n\n\n\t\t Runs: ";
cin>>r1;
if(r1>100)
cen++;
if(r1>50&&r1<100)
hcen++;
runs+=r1;
cout<<"\n\t\t Wickets: ";
cin>>w1;
wic+=w1;
mat++;
cout<<"\n\t\t OUT/NOTOUT(y/n): ";
char ch=getche();
if(ch=='y')
innings++;
cout<<"\n\t\t Overs Bowled :";
cin>>o1;
overs+=o1;
cout<<"\n\t\t Balls Played";
cin>>b1;
balls+=b1;
if(hiscr<r1)
hiscr=r1;
if(bbol<w1)
bbol=w1;
}
/*------------------------------------- fun for displaying the data -------------*/
void player::showdata()
{
int x=50;
char str[20];
cleardevice();
rectangle(50,150,610,250);
line(50,200,610,200);
for(int i=0;i<6;i++)
{
x+=80;
line(x,150,x,250);
}
outtextxy( 60,170,"MATCHS");
outtextxy(140,170,"RUNS");
outtextxy(220,170,"WICKETS");
outtextxy(300,170,"AVG(BAT)");
outtextxy(380,170,"AVG(BOL)");
outtextxy(460,170,"100`s");
outtextxy(540,170,"50`s");
outtextxy( 50,280,"BEST PERFORMANCE IN A MATCH ::");
outtextxy( 50,300,"RUNS : ");
outtextxy( 50,320,"WICKETS :");
sprintf(str,"%d",mat);
outtextxy(60,220,str);
sprintf(str,"%d",runs);
outtextxy(140,220,str);
sprintf(str,"%d",wic);
outtextxy(220,220,str);
sprintf(str,"%f",btavg);
outtextxy(300,220,str);
sprintf(str,"%f",blavg);
outtextxy(380,220,str);
sprintf(str,"%d",cen);
outtextxy(460,220,str);
sprintf(str,"%d",hcen);
outtextxy(540,220,str);
settextstyle(1,0,1);
sprintf(str,"%s",country);
outtextxy(50,110,str);
sprintf(str,"%s",name);
outtextxy(50,90,str);
settextstyle(0,0,1);
sprintf(str,"%d",hiscr);
outtextxy(130,300,str);
sprintf(str,"%d",bbol);
outtextxy(130,320,str);
getch();
}
fstream file,file1,tfile,tfile1;
int ch1;
/*----------------------------- main ---------------------*/
void main()
{
player p;
clrscr();
int ch,i=0,gm,gd=DETECT;
char st[10];
int x,y;
x=100;
y=100;initgraph(&gd,&gm,"g:\\tc\\bgi");
char pname[10],cname[10],password[10]="",c;
setbkcolor(BLUE);
while(!kbhit())
{settextstyle(1,0,6);
outtextxy(150,200,"CRICKETER`S");
outtextxy(170,270,"DATABASE");
}
settextstyle(0,0,1);
cleardevice();
setcolor(11);
settextstyle(1,0,1);
outtextxy(100,380,"LOADING...");for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
if(i<400&&i>370)
delay(40);
delay(10);
}
settextstyle(0,0,1);
cleardevice();
getch();
//cleardevice();
/*------------------ starting menu -------*/
int tag;
tag:
cleardevice();
settextstyle(1,0,2);
outtextxy(200,100," 1 :: ONE DAY") ;
outtextxy(200,130," 2 :: TEST") ;
//cin>>ch1;ch1=getche();
ch1=ch1-'0';
settextstyle(0,0,1);
if(ch1==1)
{
do
{
cleardevice();
//p.menu();
settextstyle(1,0,2);
outtextxy(200,100," 1 :: ADD RECORDS ") ;
outtextxy(200,130," 2 :: MODIFY RECORDS ") ;
outtextxy(200,160," 3 :: SEARCH RECORD (NAME)") ;
outtextxy(200,190," 4 :: SEARCH RECORD (COUNTRY)") ;
outtextxy(200,220," 5 :: LIST OF PLAYER OF ONE COUNTRY") ;
outtextxy(200,250," 6 :: BACK") ;
outtextxy(200,280," 7 :: EXIT") ;
//cin>>ch;
ch=getche();
ch=ch-'0';settextstyle(0,0,1);
switch(ch)
{
/*----- ODI insert ----------*/
case 1:cleardevice();
file.open("ODI.txt",ios::in|ios::out|ios::ate);
file.seekp(0,ios::end);
p.getdata();
p.calculation();
file.write((char*)&p,sizeof(p));
file.clear();
file.close();
c=getch();
break;
/*------- ODI name wise search -------------*/case 3:
cleardevice();
cout<<"\n\t\t Name For Search: ";
gets(pname);
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
//if(i>250&&i<300)
// delay(40);delay(10);
}
cleardevice();
int flag=0;
file.open("ODI.txt",ios::in|ios::out|ios::ate);
file.seekp(0,ios::beg);
while(file.read((char*)&p,sizeof(p)))
{
if(!strcmp(p.name,pname))
{
flag=1;
cout<<"\n\n";
p.showdata();
break;
}
}
file.clear();
file.close();
if(flag==0)
cout<<"\n\t\t Record Not Found";
//cout<<"\n\n\t\t Enter Any Key To Cont.";
//cin>>c;
c=getch();
break;/*-------------- ODI modification --------------*/
case 2:cleardevice();
cout<<"\n\t\tENTER PASSWORD ";
int i=0;
while(i<6)
{
password[i]=getche();
cout<<"*";
i++;
}
getch();
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
if(i>350&&i<400)
delay(40);
}
cleardevice();if(!strcmp("vineet",password))
{
cout<<"\n\t\t Name For Modification ";
gets(pname);
flag=0;
file.open("ODI.txt",ios::in|ios::out|ios::ate);
file1.open("temp1.txt",ios::in|ios::out|ios::ate);
if(!tfile1)
cout<<"\nerror";
file1.seekp(0,ios::beg);
file.seekp(0,ios::beg);
while(file.read((char*)&p,sizeof(p)))
{if(!strcmp(p.name,pname))
{
flag=1;
p.update();
p.calculation();
file1.write((char*)&p,sizeof(p));
}
else
{
tfile1.write((char*)&p,sizeof(p));
}
}
file.clear();
file.close();
file1.clear();
file1.close();
if(flag==1)
{
remove("ODI.txt");
rename("temp1.txt","ODI.txt");}
if(flag==0)
cout<<"\n\t\t Record Not Found";
}
else
cout<<"\n\t\t Wrong Password";
c=getch();
break;/*------------ ODI country wise search --------------*/
case 4:
cleardevice();
cout<<"\n\t\t Country`s Name For Search: ";
gets(cname);
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
//if(i>333&&i<400)
// delay(40);
}
cleardevice();
flag=0;
file.open("ODI.txt",ios::in|ios::out|ios::ate);
file.seekp(0,ios::beg);
while(file.read((char*)&p,sizeof(p)))
{
if(!strcmp(p.country,cname))
{
flag=1;
cout<<"\n\n";
p.showdata();
}
}
file.clear();
file.close();
if(flag==0)
cout<<"\n\t\t Record Not Found";
//cout<<"\n\n\t\t Enter Any Key To Cont.";
//cin>>c;
c=getch();
break;
/*------ ODI list of players ------------*/
case 5:
cleardevice();
cout<<"\n\t\t Country`s Name For Search: ";
gets(cname);
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
}
cleardevice();
flag=0;
file.open("ODI.txt",ios::in|ios::out|ios::ate);
file.seekp(0,ios::beg);
while(file.read((char*)&p,sizeof(p)))
{
if(!strcmp(p.country,cname))
{
flag=1;
settextstyle(1,0,1);
//cout<<"\n\n\t\t"< <p.name;sprintf(st,"%s",p.name);
outtextxy(x,y,st);
y=y+30;
settextstyle(0,0,1);
}
}
file.clear();
file.close();
if(flag==0)
cout<<"\n\t\t Record Not Found";//cout<<"\n\n\t\t Enter Any Key To Cont.";
//cin>>c;
c=getch();
break;
case 6:
goto tag;
//break;case 7:
exit(0);
break;
}
}while(1);
}
if(ch1==2)
{
do
{
cleardevice();
//p.menu();
settextstyle(1,0,2);
outtextxy(200,100," 1 :: ADD RECORDS ") ;
outtextxy(200,130," 2 :: MODIFY RECORDS ") ;
outtextxy(200,160," 3 :: SEARCH RECORD (NAME)") ;
outtextxy(200,190," 4 :: SEARCH RECORD (COUNTRY)") ;
outtextxy(200,220," 5 :: LIST OF PLAYER OF ONE COUNTRY") ;
outtextxy(200,250," 6 :: BACK") ;
outtextxy(200,280," 7 :: EXIT") ;
//cin>>ch;
ch=getche();
ch=ch-'0';settextstyle(0,0,1);
switch(ch)
{
/*------------------ TEST insert ------------------*/
case 1:
cleardevice();
tfile.open("TEST.txt",ios::in|ios::out|ios::ate);
tfile.seekp(0,ios::end);
p.getdata();
p.calculation();
tfile.write((char*)&p,sizeof(p));
tfile.clear();
tfile.close();
break;
/*------------------ TEST name wise search ------------------*/
case 3:
cleardevice();
cout<<"\n\t\t Name For Search: ";
gets(pname);
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
if(i>350&&i<400)
delay(40);
}
cleardevice();
int flag=0;
tfile.open("TEST.txt",ios::in|ios::out|ios::ate);
tfile.seekp(0,ios::beg);
while(tfile.read((char*)&p,sizeof(p)))
{
if(!strcmp(p.name,pname))
{
flag=1;
cout<<"\n\n";
p.showdata();
break;
}
}
tfile.clear();
tfile.close();
if(flag==0)
cout<<"\n\t\t Record Not Found";
c=getch();
break;
/*------------------ TEST modification ------------*/
case 2:
cleardevice();
cout<<"\n\t\tENTER PASSWORD";
int i=0;
while(i<6)
{
password[i]=getche();
cout<<"*";
i++;
}
getch();
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
if(i>350&&i<400)
delay(40);
}
cleardevice();if(!strcmp("vineet",password))
{
cout<<"\n\t\t Name For Modification ";
gets(pname);
flag=0;
tfile.open("TEST.txt",ios::in|ios::out|ios::ate);
tfile1.open("temp1.txt",ios::in|ios::out|ios::ate);
if(!tfile1)
cout<<"\nerror";
tfile1.seekp(0,ios::beg);
tfile.seekp(0,ios::beg);
while(tfile.read((char*)&p,sizeof(p)))
{if(!strcmp(p.name,pname))
{
flag=1;
cout<<"\n\t\t Enter Data For First Inning: ";
p.update();
cout<<"\n\t\t Enter Data For Second Inning: ";
p.update();
p.mat--;
p.calculation();
tfile1.write((char*)&p,sizeof(p));
}
else
{
tfile1.write((char*)&p,sizeof(p));
}
}
tfile.clear();
tfile.close();
tfile1.clear();
tfile1.close();
if(flag==1)
{
remove("TEST.txt");
rename("temp1.txt","TEST.txt");}
if(flag==0)
cout<<"\n\t\t Record Not Found";
}
else
cout<<"\n\t\t Wrong Password";
c=getch();
break;
/*------------------ TEST country wise search -------*/
case 4:
cleardevice();
cout<<"\n\t\t Country`s Name For Search: ";
gets(cname);
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
if(i>350&&i<400)
delay(40);
}
cleardevice();
flag=0;
tfile.open("TEST.txt",ios::in|ios::out|ios::ate);
tfile.seekp(0,ios::beg);
while(tfile.read((char*)&p,sizeof(p)))
{
if(!strcmp(p.country,cname))
{
flag=1;
cout<<"\n\n";
p.showdata();
}
}
tfile.clear();
tfile.close();
if(flag==0)
cout<<"\n\t\t Record Not Found";
break;
/*------------------ TEST list --------*/
case 5:
cleardevice();
cout<<"\n\t\t Country`s Name For Search: ";
gets(cname);
cleardevice();
setcolor(10);
outtextxy(100,380,"LOADING...");
for(i=0;i<401;i++)
{
outtextxy(100+i,400,"#");
delay(10);
if(i>350&&i<400)
delay(40);
}
cleardevice();
flag=0;
tfile.open("TEST.txt",ios::in|ios::out|ios::ate);
tfile.seekp(0,ios::beg);
while(tfile.read((char*)&p,sizeof(p)))
{
if(!strcmp(p.country,cname))
{
flag=1;
settextstyle(1,0,1);
//cout<<"\n\n\t\t"< <p.name;sprintf(st,"%s",p.name);
outtextxy(x,y,st);
y=y+30;
settextstyle(0,0,1);
//cout<<"\n\n\t\t"< <p.name;
}
}
file.clear();
file.close();
if(flag==0)
cout<<"\n\t\t Record Not Found";
//char c;
//cout<<"\n\n\t\t Enter Any Key To Cont.";
//cin>>c;
c=getch();
break;
case 6:
goto tag;
case 7:
exit(0);
break;
}
}while(1);
}
}
/* ------------------------------end of main ----------*/
Leave a Reply