Vous êtes sur la page 1sur 9

1 #include <iostream>

2 #include <conio.h>
3 #include <fstream>
4 #include <string.h>
5 #include <windows.h>
6 #include <iomanip>
7 #include <ctime>
8 using namespace std;
9 string fav_team,name;
10 void gotoxy(int,int);
11 void loadalldata();
12 struct team_data;
13 team_data getTeamData(string);
14 struct players{
15 char name[20];
16 int runs=-1;
17 int wickets=-1;
18 char team[3];
19 };
20 string teams[8][2]={{"India","IN"},{"Australia","AU"},{"West Indies","WI"},{"Srilanka","SL"},{"Pakistan",
"PK"},{"South Africa","SA"},{"Bangladesh","BA"},{"England","EN"}};
21 void clrscr();
22 string autocomplete_team(string );
23 int getx(){
24 int x;
25 CONSOLE_SCREEN_BUFFER_INFO consoleinfo;
26 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleinfo);
27 x = consoleinfo.dwCursorPosition.X;
28 return x;
29
}
30 int gety(){
31 int y;
32 CONSOLE_SCREEN_BUFFER_INFO consoleinfo;
33 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleinfo);
34 y= consoleinfo.dwCursorPosition.Y;
35 return y;
36 }
37 void textcolor(int k){
38 HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
39 SetConsoleTextAttribute(console, k);
40 }
41 string autocomplete_team(string team_namee){
42 team_namee +='\0';
43 string ret;
44 for(int i=0;i<8;i++){
45
int k=0;
46
for(int xx=0;xx<team_namee.length()-1;xx++){
47
if(!(tolower(teams[i][0][xx])==tolower(team_namee[xx]))){k=-1;}
48
}
49
if(k==0){
50
textcolor(0x08);
51
ret=teams[i][0].substr(team_namee.length()-1,(teams[i][0].length()-team_namee.length()+1));
52
cout<<ret;
53
textcolor(0x0F);
54
break;
55
56
}
57 }
58 return ret;
59 }
60 int menu(string options[],int no_of_options,int xc=2,int yc=0){
61 int i=0;int k=1;
62 gotoxy(xc,yc);textcolor(0x0F);
63 char a;
64 while(a!=13){
65
textcolor(0x0F);

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

//if(scr)clrscr();
if(a==72 && k>1){k--;}
if(a==80 && k<no_of_options){k++;}
for(i=0;i<no_of_options;i++){
textcolor(0x0F);
if(i==(k-1)){textcolor(0xFC);}
gotoxy(xc,yc+i+2);cout<<(i+1)<<options[i]<<"\n";
}
a=_getch();
if(a==32 || a==224)a=_getch();
if(a==27){k=a;break;}
}
textcolor(0x0F);
return k;
}
struct match{
int home_of=0;
int match_id=0;
string team1;
string team2;
int score=0;
int who_won=0;
long date=0;
players top11[2][11];
};
struct factor{
int factor_weightage;
int factor_value;
char fact[5];
};
struct team_data{
string tcode;
match allmatch[20];
factor allfactor[3];
int rnk=-1;
factor getFactor(string g){
for(int i=0;i<3;i++){
string te=allfactor[i].fact;
if(te==g)return allfactor[i];
}
}
match getMatchById(int g){
for(int i=0;i<20;i++){
int te=allmatch[i].match_id;
if(te==g)return allmatch[i];
}
}
match* getMatchesByOppTeam(string oppTeam){
match arr_of_match[10];
int m=0;
for(int i=0;i<9;i++){
string tm=allmatch[i].team2;
if(tm==oppTeam){arr_of_match[m]=allmatch[i];m++;}
}
return arr_of_match;
}
};
team_data allteamdata[8];
int main();
void user();
void selfcorrect(match);
void selfcorrect(match);

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

void reguser(bool first=true){


string a[3];
ofstream my("c:\\p\\user.dat",ios::out|ios::app);
if(first){
cout<<"Enter Your Name";
cin>>a[0];
cout<<"\nEnter Favourite team code";
cin>>a[2];
}else{
a[0]=name;
a[1]=fav_team;
}
cout<<"\nEnter Password";
cin>>a[1];
for(int i=0;i<=2;i++){
my<<"\n"<<a[i];
}
my.close();
main();
}
void clrscr(){
system("cls");
}
void pause(){
system("pause");
}
class score{
public:
char *name;
int homeground_factor=0,luck_factor=0,icci_factor=0,last_matches_factor=0;
int getscore(){
int kk=homeground_factor+luck_factor+icci_factor+last_matches_factor;
return kk;
}
};
class data{
string team_code;
public:
factor t[3];
data(string t){
team_code=t;
string tmp="c:\\p\\Factors\\"+team_code+".dat";
int i=0;
ifstream fctr;
fctr.open(tmp.c_str(),ios::in|ios::binary);
while(!fctr.eof()){
fctr.read((char*)&t[i],sizeof(t[i]));
i++;
}
fctr.close();
}
int get_factor(string x,bool a){
for(int i=0;i<3;i++){
string tmp=t[i].fact;
int result=t[i].factor_value*t[i].factor_weightage;
if(tmp==x){return result;}
}
return 1;
}
int get_factor(char x[]){
string h=x;
int fc=getTeamData(team_code).getFactor(h).factor_value;
return 1;
}

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263

};
class predicting_engine{
int winning_team=0;
public:
int predict(match f);
};
int predicting_engine::predict(match f){
score t1,t2;
data dat1=f.team1;
data dat2=f.team2;
if(f.home_of==1){
t1.homeground_factor=dat1.get_factor("Home",true);
t2.homeground_factor=dat2.get_factor("Home",false);
}else{
t2.homeground_factor=dat2.get_factor("Home",true);
t1.homeground_factor=dat1.get_factor("Home",false);
}
t1.icci_factor=dat1.get_factor("icc");
//Bogus result->> t1.icci_factor=1;
t1.luck_factor=dat1.get_factor("luck");
t1.icci_factor=dat1.get_factor("last");
t2.icci_factor=dat2.get_factor("icci");
t2.luck_factor=dat2.get_factor("luck");
t2.icci_factor=dat2.get_factor("last");
cout<<"Score of t1"<<t1.getscore();
cout<<"\nScore of team t2"<<t2.getscore();
if(t1.getscore()==t2.getscore())return -1;
if(t1.getscore()>t2.getscore()){
return 1;
}
else{
return 2;
}
}
void matchadd(bool upcoming){
match j;
cout<<"Enter Team 1 Code";
cin>>j.team1;
cout<<"Enter Team 2 Code";
cin>>j.team2;
cout<<"Home ground of which team (1 or 2)";
cin>>j.home_of;
fstream mtch;
time_t now=time(0);
tm *tmptime=localtime(&now);
if(upcoming){
cout<<"Enter Date of the match??";
cout<<"\nYear:";cin>>tmptime->tm_year;
cout<<"\nMonth:";cin>>tmptime->tm_mon;
cout<<"\nDate:";cin>>tmptime->tm_mday;
time_t nn=mktime(tmptime);
j.date=nn;
}else{
cout<<"Who won?";
cin>>j.who_won;
j.date=now;
predicting_engine palash;
if(palash.predict(j)!=j.who_won){
selfcorrect(j);
}
}
if(!upcoming){
cout<<"Press F for full entering full detail or Enter to Submit";
char a=_getch();
if(a=='f'|| a=='F'){

264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329

cout<<"Enter Score";
cin>>j.score;
cout<<"Indvidual Players Runs and Wickets Entry(Y/N)";
a=_getch();
if(a=='Y' or 'y'){
for(int m=0;m<2;m++){
cout<<"For:";
if(m=0)cout<<j.team1;
else cout<<j.team2;
for(int i=0;i<11;i++){
cout<<j.top11[m][i].name<<"\nEnter Runs:";
cin>>j.top11[m][i].runs;cout<<"\nEnter Wickets:";
cin>>j.top11[m][i].wickets;
}
}
}
}
}
fstream mid;
mid.open("C:\\p\\count.dat",ios::in|ios::out|ios::binary);
mid.read((char*)&j.match_id,sizeof(j.match_id));
mid.seekg(0);
int k=j.match_id+1;
mid.write((char*)&k,sizeof(k));
mid.close();
string tmp="c:\\p\\Matches\\"+j.team1+".dat";
mtch.open(tmp.c_str(),ios::out|ios::app|ios::binary);
mtch.write((char*)&j,sizeof(j));
mtch.close();
clrscr();
cout<<"Enter more?? Y/N";
char l=_getch();
if(l=='y'|l=='Y'){matchadd(upcoming);}
user();
}
void selfcorrect(match err){
}
struct news{
char heading[20];
char main_news[50];
int views=0;
};
void changeranking(){
clrscr();string tc;int rnk;
cout<<"Enter Team Code";
cin>>tc;
cout<<"Enter New Rank";
cin>>rnk;
char d[25];
string tmp="c:\\p\\rankings\\"+tc+".dat";
ofstream my(tmp.c_str(),ios::out);
my<<rnk;
my.close();
user();
}
void user(){
clrscr();
time_t now=time(0);
char *tme=ctime(&now);
string options[5];
HERE:

330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
-Or367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

int c;
options[0]="Predicitions";
options[1]="Matches and Stats";
options[2]="Change Password";
options[3]="News";
textcolor(0xCF);cout<<"Welcome:
"<<tme<<"\n";textcolor(0X0F);
if(name=="admin"){
options[4]="Add Records";
c=menu(options,5);
}else{
c=menu(options,4);
}
int i=0;
if(c==1){
clrscr();
match x;
cout<<"TEAM-1";
cin>>x.team1;
cout<<"\nTEAM-2";
cin>>x.team2;
cout<<"\nHOMEGROUND OF WHICH TEAM (1 OR 2)??";
cin>>x.home_of;
predicting_engine custom;
//clrscr();
cout<<"\nPrediciting....\n";
cout<<"Team "<<custom.predict(x)<<"Wins\n\n\n\n";
_getch();
user();

}
else if(c==2){
clrscr();
textcolor(78);
cout<<"1"<<gety()<<"-"<<getx();
cout<<"2"<<gety()<<"-"<<getx();
cout<<"Find stats about matches and players here.Enter Team Name\Player\nEg. India vs Australia
Virat Kohli -Or- 4567 (Match Id)\n\n";
char d=_getch();
string temp="";
int temp2=0;
textcolor(0x0F);
int ay=0;
int ax=3;
while(d!=13){
cout<<d;
temp+=d;
ay++;
if(d==32){
temp=autocomplete_team(temp);
}
else{
autocomplete_team(temp);
gotoxy(ay,ax);
}
d=_getch();
}
char a=0;
while(a!=27){
a=_getch();
}
clrscr();
}
else if(c==3){
reguser(false);
}

395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460

else if(c==4){
int i=0;news read_news[10];
fstream nw;
nw.open("C:\\p\\news.dat",ios::in|ios::binary|ios::app);
while(!nw.eof()){
if(i==10)break;
nw.read(reinterpret_cast<char*>(&read_news[i]),sizeof(read_news[i]));
i++;
}
nw.close();
string sort[]={"Latest","Popular"};
clrscr();
cout<<"Sort By";
int s=menu(sort,2,3,2);
if(s==1){
string displ[10];
int cou=0;
i-=2;
while(i!=-1){
displ[cou]=read_news[i].heading;
cou++;
i--;
}
clrscr();
int j=menu(displ,cou,3,3);
if(j==27)user();
else{
clrscr();
textcolor(0xfc);gotoxy(5,3);
cout<<read_news[(cou-j)].heading<<"\n";textcolor(0x0f);
gotoxy(5,5);
cout<<read_news[(cou-j)].main_news<<"\n";
_getch();
user();
}
}
}
else if(name=="admin"){
if(c==5){
clrscr();int xx;
string j[4]={"Change Team Ranking","Add match data","Add upcoming match data","Add News"};
xx=menu(j,4);
if(xx==1){changeranking();}
if(xx==2){matchadd(false);}
if(xx==3){matchadd(true);}
if(xx==4){
fstream nw;
nw.open("C:\\p\\news.dat",ios::out|ios::app|ios::binary);
char c='y';
while(c=='y'){
news temp;
cout<<"Enter Title";
cin>>temp.heading;
cout<<"Enter News";
cin>>temp.main_news;
nw.write(reinterpret_cast<char*>(&temp),sizeof(temp));
cout<<"ENTER MORE (y/n)";
c=_getch();
}
nw.close();
user();
};
if(xx==27)user();
}
if(c==27){exit(0);}

461 }
462 }
463
464 void gotoxy(int x, int y)
465 {
466
//Copied from the internet.
467
COORD coord;
468
coord.X = x;
469
coord.Y = y;
470
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
471
472 }
473
474
475 bool checkuser(string x,string y){
476
string line;
477
fstream myfile("c:\\p\\user.dat",ios::in);
478 if (myfile.is_open())
479
{
480
int c=-1;
481
while (!myfile.eof())
482
{
myfile>>line;
483
if(c==-1){
484
if(line==x){name=line;c=0;}
485
}
486
if(c==0){
487
if(line==y){c=1;}
488
}
489
if(c==1){
490
fav_team=line;return true;
491
}
492
}
493
return false;
494
myfile.close();
495
}
496
else cout << "Unable to open User database";
497 }
498 using namespace std;
499 int main () {
500
loadalldata();
501
clrscr();
502
string username,password="0000";
503
textcolor(0x0C);
504
clrscr();
505
cout<<"\n"<<setw(50)<<" CRICKET FAN CLUB\n\n";
506
//cout<<"\t\t\t";textcolor(0xcf);cout<<"APPLICATION HELP:\n";textcolor(0x0F);
507
cout<<"\t";textcolor(0xb2);cout<<"1.MENU TO BE NAVIGATED VIA ARROW AND ENTER KEY";textcolor(0x0F);
508
cout<<"\n\n\t";textcolor(0xb2);cout<<"2.ON CERTAIN PAGES AUTO-COMPLETE IS THERE.";textcolor(0x0F);
509
cout<<"\n\t";textcolor(0xb2);cout<<"
PRESS SPACEBAR TO USE THAT AUTO-COMPLETED VERSION";textcolor(
0x0F);
510 _getch();
511
textcolor(0x0E);
512
string x[2];
513
x[0]="Login";
514
x[1]="Registeration";
515
int j=menu(x,2,1,6);
516
clrscr();
517
if(j==1){
518
textcolor(0xCF);cout<<"Enter username: ";textcolor(0x0F);
519
cin>>username;
520
textcolor(0xCF);cout<<"Enter password: ";textcolor(0x0F);
521
cin>>password;
522
if(checkuser(username,password)){
523
clrscr();
524
cout<<"Login successfull \n";
525
_getch();

526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577

user();
}else {
clrscr();
cout<<"Login Error \n Press 1 to retry.Any other key to exit";
cin>>username;
if(username=="1")main();
}
}else if(j==2){reguser();}

return 0;
}
team_data getTeamData(string t){
for(int i=0;i<=8;i++)
if(allteamdata[i].tcode==t)return allteamdata[i];
}
void loadalldata(){
for(int i=0;i<8;i++){
allteamdata[i].tcode=teams[i][1];
//Factors
string tmp="c:\\p\\Factors\\"+teams[i][1]+".dat";
int g=0;
ifstream fctr;
fctr.open(tmp.c_str(),ios::in|ios::binary);
while(!fctr.eof()){
fctr.read((char*)&allteamdata[i].allfactor[g],sizeof(allteamdata[i].allfactor[g]));
g++;
}
fctr.close();
//Matches
ifstream mtch;
tmp="c:\\p\\Matches\\"+teams[i][1]+".dat";
mtch.open(tmp.c_str(),ios::out|ios::app|ios::binary);
g=0;
while(!mtch.eof()){
mtch.read((char*)&allteamdata[i].allmatch[g],sizeof(allteamdata[i].allmatch[g]));
g++;
}
mtch.close();
//ranking
ifstream rnking;
tmp="c:\\p\\Matches\\"+teams[i][1]+".dat";
rnking.open(tmp.c_str(),ios::in|ios::app|ios::binary);
g=0;
rnking>>allteamdata[i].rnk;
rnking.close();
}
}

Vous aimerez peut-être aussi