//A PROJECT BY ARPIT CHAWLA ON KBC(KAUN BANEGA CROREPATI).
/* questions and answers are being written in a separate file named QNA.dat
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<fstream.h>
#include<ctype.h>
//DECLARATION OF GLOBAL ARRAYS, STRINGS AND VARIABLES.
char name[20],address[80],dob[10],fname[20];
int age;
int count1,count2;
int a[5]={20,20,20,20,20};
long double telno;
long money[6]={0,10000,100000,1000000,10000000,50000000};
//DECLARATION OF GLOBAL FUNCTIONS.
void eligibility();
void menu();
void rulnreg();
//CLASS DECLARATION AND DEFINATION TO OPERATE ON PRE-EXISTING FILE.
class question
{public:
char ques[100];
char op1[20];
char op2[20];
char op3[20];
char op4[20];
char correct[1];
question()
{strcpy(ques," ") ;
strcpy(op1," ");
strcpy(op2," ");
strcpy(op3," ");
strcpy(op4," ");
strcpy(correct," ");
}
void getdata() //TO ENTER THE QUESTION AND OPTIONS IN THE FILE.
{cout<<"\nEnter the question :";
gets(ques);
cout<<"\nEnter the first option :";
gets(op1);
cout<<"\nEnter the second option :";
gets(op2);
cout<<"\nEnter the third option :";
gets(op3);
cout<<"\nEnter the fourth option :";
gets(op4);
cout<<"\nEnter correct option :";
gets(correct);
};
void display() //TO RETRIEVE THE QUESTIONS AND CORRESPONDING OPTIONS
{puts(ques); //FROM THE FILE.
puts(op1);
puts(op2);
puts(op3);
puts(op4);
puts(correct);
}
};
void enterdata() //TO ENTER THE DATA OF THE CONTESTANT.
{cout<<"\n ";
cout<<"Please Fill The Following Form:-\n\n\n";
cout<<"NAME :";
gets(name);
cout<<"\nADDRESS :";
gets(address);
cout<<"\nDATE OF BIRTH (dd/mm/yyyy) :";
gets(dob);
cout<<"\nFATHER'S NAME :";
gets(fname);
cout<<"\nAGE :";
cin>>age;
cout<<"\nTELEPHONE NUMBER :";
cin>>telno;
eligibility();
menu();
};
void eligibility() //FUNCTION DEFINATION TO CHECK ELIGIBILITY OF CONTESTANT BASED ON AGE.
{if (age<18)
{cout<<"\n\nYou are not eligible to play the game\n\n";
cout<<"\nEnter any character to exit..";
getch();
exit(0);}
else
{
cout<<"\nYou are eligible to play the game\n\n";
cout<<"\nPress any key to continue to menu....\n\n";
getch();
}
};
void menu() //TO DISPLAY A MENU.
{clrscr();
int a;
cout<<"\n\n "
<<"Select the appropriate option\n\n"
<<"1. Play The Game\n\n"
<<"2. Read Rules And Regulations\n\n\n"
<<"Enter Your Choice (1 / 2) :";
cin>>a;
switch(a)
{case 1 :break;
case 2 :{rulnreg();break;}
default:{cout<<"\nInvalid Choice Entered.....";
cout<<"\n\nPress any key to return to menu";
getch();
menu();}
}
}
void rulnreg() //TO DISPLAY RULES AND REGULATIONS.
{cout<<"\n\n\n "
<<"!!!!!!!!RULES AND REGULATIONS!!!!!!!!\n\n\n\n"
<<"1.There are 5 questions ranging from Rs.10,000"
<<" to Rs.5,00,00,000.\n\n"
<<"2.Each question will have four options with only"
<<" one correct option.\n\n"
<<"3.Contestant can Quit the game by entering 'e'"
<<" or 'E' when answer is asked.\n\n"
<<"4.Four lifelines are available during the game play.\n\n"
<<"5.Contestant can't Quit the game while using lifelines.\n\n";
cout<<"Press any key to return to menu...";
getch();
menu();
}
void randomfn() //TO GENERATE AN ARRAY WITH RANDOM BUT NON REPEATED 5 NUMBERS FROM 0 TO 14.
{int t;
randomize();
for(int i=0;i<=4;i++)
{label:
t=random(15);
for(int j=0;j<=4;j++)
{if (a[j]==t)
{goto label;}
}
a[i]=t;
}
}
void lifeline(char corr[1],int l) //FUNCTION FOR USE OF LIFELINES.
{int ch;char answ[1];
abc:
cout<<"\nWhich lifeline u want to use:-\n\n1.Expert advice.\n\n2.Double Dip.\n";
cout<<"\nEnter your choice(1/2):-";
cin>>ch;
if (ch==1) //for expert advice.
{if (count1==0)
{count1++; //to stop the multiple use of expert advice.
cout<<"\nExpert Says That Correct Option Is "<< corr[0]<<"\n\n";
cout<<"So , Enter Your final option(a/b/c/d):-";
gets(answ);
if((answ[0]==corr[0])||(answ[0]==tolower(corr[0])))
{ cout<<"\n\nThat's the right answer.Well played.\n\n" ;
cout<<"Press Any Key To Proceed.....\n\n";
getch();}
else
{cout<<"\nSorry,that was a wrong answer.You lost the game.\n\n";
cout<<"Congratulations You Are Leaving With "<<money[l+1]<<"\n\n";
cout<<"Press any key To Exit";
getch();
exit(0);}}
else
{cout<<"\nThis Lifeline have been used once. Can't use this lifeline\n";
goto abc;}}
else
{if(ch==2) //for double dip.
{if (count2==0)
{count2++; //to stop the multiple use of double dip.
for(int i=1;i<=2;i++)
{cout<<"\nEnter your answer:-";
cin>>answ;
if((answ[0]==corr[0])||(answ[0]==tolower(corr[0])))
{cout<<'\n'<<"\nThat's the right answer.Well played.Press Any Key To Proceed\n\n" ;
getch();
break;}
else
{cout<<"\n\nSorry,that was a wrong answer.\n\n";}}}
else
{cout<<"\nThis Lifeline have been used once. Can't use this life line\n\n";
goto abc;}}}}
main()
{clrscr();
cout<<"\n\n\n ----------!!!!!!! WELCOME TO KAUN BANEGA CROREPATI !!!!!!!----------\n\n";
enterdata();
fstream f;
question m;
char d;
char ans[1];
randomfn(); //to generate an array with random numbers.
f.open("qna.dat",ios::in|ios::binary); //read data from file "qna.dat".
for (int i=0;i<=4;i++)
{clrscr();
cout<<"\n\n\n\n";
cout.write(name,strlen(name));
cout<<", here is your Question no "<<i+1<<" for Rs."<<money[i+1]<<" (Press Enter)\n\n";
getch();
f.seekg(0,ios::beg);
f.seekg(a[i]*sizeof(m),ios::cur);
f.read((char*)&m,sizeof(m));
cout.write(m.ques,sizeof(m.ques));
cout<<"\n\nPress any key for options.....\n\n";
getch();
cout.write(m.op1,sizeof(m.op1));
cout.write(m.op2,sizeof(m.op2));
cout<<"\n\n";
cout.write(m.op3,sizeof(m.op3));
cout.write(m.op4,sizeof(m.op4));
cout<<"\n\n";
cout<<"L or l->LIFELINE ";
cout<<"E or e->EXIT ";
label:
cout<<"\n\nEnter the correct option (a/b/c/d) : ";
gets(ans);
if ((ans[0]=='e')||(ans[0]=='E')) //to exit the game.
{cout<<"\nAre you sure you want to Exit.....? (y/n) : ";
cin>>d;
if((d=='y')||(d=='Y'))
{cout<<"\n\nYou are leaving with Rs."<<money[i]<<".";
cout<<"\n\nPress any key to Exit......";
getch();
exit(0);
}}
if ((ans[0]=='l')||(ans[0]=='L')) //to use a lifeline.
{if ((count1==0)||(count2==0))
lifeline(m.correct,i);
else
{cout<<"\nNo Lifeline Available\n\n";
goto label; } }
else
{if ((ans[0]==m.correct[0]) || (toupper(ans[0])==m.correct[0]))
{cout<<"\nThats the right Answer....";
cout<<"\n\nCongratulations you have won Rs."<<money[i+1]<<".";
cout<<"\n\nPress any key to proceed....\n\n";
getch();
}
else
{cout<<"\n\nThats the Wrong Answer...";
cout<<"\n\nYou have lost the game...";
cout<<"\n\nYou are leaving with Rs."<<money[i]<<".";
cout<<"\n\nPress any key to Exit.....";
getch();
exit(0);
}
}
}
}
/* questions and answers are being written in a separate file named QNA.dat
this source code is just an example and you can set your own questions and answers */
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<fstream.h>
#include<ctype.h>
//DECLARATION OF GLOBAL ARRAYS, STRINGS AND VARIABLES.
char name[20],address[80],dob[10],fname[20];
int age;
int count1,count2;
int a[5]={20,20,20,20,20};
long double telno;
long money[6]={0,10000,100000,1000000,10000000,50000000};
//DECLARATION OF GLOBAL FUNCTIONS.
void eligibility();
void menu();
void rulnreg();
//CLASS DECLARATION AND DEFINATION TO OPERATE ON PRE-EXISTING FILE.
class question
{public:
char ques[100];
char op1[20];
char op2[20];
char op3[20];
char op4[20];
char correct[1];
question()
{strcpy(ques," ") ;
strcpy(op1," ");
strcpy(op2," ");
strcpy(op3," ");
strcpy(op4," ");
strcpy(correct," ");
}
void getdata() //TO ENTER THE QUESTION AND OPTIONS IN THE FILE.
{cout<<"\nEnter the question :";
gets(ques);
cout<<"\nEnter the first option :";
gets(op1);
cout<<"\nEnter the second option :";
gets(op2);
cout<<"\nEnter the third option :";
gets(op3);
cout<<"\nEnter the fourth option :";
gets(op4);
cout<<"\nEnter correct option :";
gets(correct);
};
void display() //TO RETRIEVE THE QUESTIONS AND CORRESPONDING OPTIONS
{puts(ques); //FROM THE FILE.
puts(op1);
puts(op2);
puts(op3);
puts(op4);
puts(correct);
}
};
void enterdata() //TO ENTER THE DATA OF THE CONTESTANT.
{cout<<"\n ";
cout<<"Please Fill The Following Form:-\n\n\n";
cout<<"NAME :";
gets(name);
cout<<"\nADDRESS :";
gets(address);
cout<<"\nDATE OF BIRTH (dd/mm/yyyy) :";
gets(dob);
cout<<"\nFATHER'S NAME :";
gets(fname);
cout<<"\nAGE :";
cin>>age;
cout<<"\nTELEPHONE NUMBER :";
cin>>telno;
eligibility();
menu();
};
void eligibility() //FUNCTION DEFINATION TO CHECK ELIGIBILITY OF CONTESTANT BASED ON AGE.
{if (age<18)
{cout<<"\n\nYou are not eligible to play the game\n\n";
cout<<"\nEnter any character to exit..";
getch();
exit(0);}
else
{
cout<<"\nYou are eligible to play the game\n\n";
cout<<"\nPress any key to continue to menu....\n\n";
getch();
}
};
void menu() //TO DISPLAY A MENU.
{clrscr();
int a;
cout<<"\n\n "
<<"Select the appropriate option\n\n"
<<"1. Play The Game\n\n"
<<"2. Read Rules And Regulations\n\n\n"
<<"Enter Your Choice (1 / 2) :";
cin>>a;
switch(a)
{case 1 :break;
case 2 :{rulnreg();break;}
default:{cout<<"\nInvalid Choice Entered.....";
cout<<"\n\nPress any key to return to menu";
getch();
menu();}
}
}
void rulnreg() //TO DISPLAY RULES AND REGULATIONS.
{cout<<"\n\n\n "
<<"!!!!!!!!RULES AND REGULATIONS!!!!!!!!\n\n\n\n"
<<"1.There are 5 questions ranging from Rs.10,000"
<<" to Rs.5,00,00,000.\n\n"
<<"2.Each question will have four options with only"
<<" one correct option.\n\n"
<<"3.Contestant can Quit the game by entering 'e'"
<<" or 'E' when answer is asked.\n\n"
<<"4.Four lifelines are available during the game play.\n\n"
<<"5.Contestant can't Quit the game while using lifelines.\n\n";
cout<<"Press any key to return to menu...";
getch();
menu();
}
void randomfn() //TO GENERATE AN ARRAY WITH RANDOM BUT NON REPEATED 5 NUMBERS FROM 0 TO 14.
{int t;
randomize();
for(int i=0;i<=4;i++)
{label:
t=random(15);
for(int j=0;j<=4;j++)
{if (a[j]==t)
{goto label;}
}
a[i]=t;
}
}
void lifeline(char corr[1],int l) //FUNCTION FOR USE OF LIFELINES.
{int ch;char answ[1];
abc:
cout<<"\nWhich lifeline u want to use:-\n\n1.Expert advice.\n\n2.Double Dip.\n";
cout<<"\nEnter your choice(1/2):-";
cin>>ch;
if (ch==1) //for expert advice.
{if (count1==0)
{count1++; //to stop the multiple use of expert advice.
cout<<"\nExpert Says That Correct Option Is "<< corr[0]<<"\n\n";
cout<<"So , Enter Your final option(a/b/c/d):-";
gets(answ);
if((answ[0]==corr[0])||(answ[0]==tolower(corr[0])))
{ cout<<"\n\nThat's the right answer.Well played.\n\n" ;
cout<<"Press Any Key To Proceed.....\n\n";
getch();}
else
{cout<<"\nSorry,that was a wrong answer.You lost the game.\n\n";
cout<<"Congratulations You Are Leaving With "<<money[l+1]<<"\n\n";
cout<<"Press any key To Exit";
getch();
exit(0);}}
else
{cout<<"\nThis Lifeline have been used once. Can't use this lifeline\n";
goto abc;}}
else
{if(ch==2) //for double dip.
{if (count2==0)
{count2++; //to stop the multiple use of double dip.
for(int i=1;i<=2;i++)
{cout<<"\nEnter your answer:-";
cin>>answ;
if((answ[0]==corr[0])||(answ[0]==tolower(corr[0])))
{cout<<'\n'<<"\nThat's the right answer.Well played.Press Any Key To Proceed\n\n" ;
getch();
break;}
else
{cout<<"\n\nSorry,that was a wrong answer.\n\n";}}}
else
{cout<<"\nThis Lifeline have been used once. Can't use this life line\n\n";
goto abc;}}}}
main()
{clrscr();
cout<<"\n\n\n ----------!!!!!!! WELCOME TO KAUN BANEGA CROREPATI !!!!!!!----------\n\n";
enterdata();
fstream f;
question m;
char d;
char ans[1];
randomfn(); //to generate an array with random numbers.
f.open("qna.dat",ios::in|ios::binary); //read data from file "qna.dat".
for (int i=0;i<=4;i++)
{clrscr();
cout<<"\n\n\n\n";
cout.write(name,strlen(name));
cout<<", here is your Question no "<<i+1<<" for Rs."<<money[i+1]<<" (Press Enter)\n\n";
getch();
f.seekg(0,ios::beg);
f.seekg(a[i]*sizeof(m),ios::cur);
f.read((char*)&m,sizeof(m));
cout.write(m.ques,sizeof(m.ques));
cout<<"\n\nPress any key for options.....\n\n";
getch();
cout.write(m.op1,sizeof(m.op1));
cout.write(m.op2,sizeof(m.op2));
cout<<"\n\n";
cout.write(m.op3,sizeof(m.op3));
cout.write(m.op4,sizeof(m.op4));
cout<<"\n\n";
cout<<"L or l->LIFELINE ";
cout<<"E or e->EXIT ";
label:
cout<<"\n\nEnter the correct option (a/b/c/d) : ";
gets(ans);
if ((ans[0]=='e')||(ans[0]=='E')) //to exit the game.
{cout<<"\nAre you sure you want to Exit.....? (y/n) : ";
cin>>d;
if((d=='y')||(d=='Y'))
{cout<<"\n\nYou are leaving with Rs."<<money[i]<<".";
cout<<"\n\nPress any key to Exit......";
getch();
exit(0);
}}
if ((ans[0]=='l')||(ans[0]=='L')) //to use a lifeline.
{if ((count1==0)||(count2==0))
lifeline(m.correct,i);
else
{cout<<"\nNo Lifeline Available\n\n";
goto label; } }
else
{if ((ans[0]==m.correct[0]) || (toupper(ans[0])==m.correct[0]))
{cout<<"\nThats the right Answer....";
cout<<"\n\nCongratulations you have won Rs."<<money[i+1]<<".";
cout<<"\n\nPress any key to proceed....\n\n";
getch();
}
else
{cout<<"\n\nThats the Wrong Answer...";
cout<<"\n\nYou have lost the game...";
cout<<"\n\nYou are leaving with Rs."<<money[i]<<".";
cout<<"\n\nPress any key to Exit.....";
getch();
exit(0);
}
}
}
}
Please give me qna.dat file its urgent..
ReplyDeletesend qna.dat file fast bro
ReplyDeleteKBC Winner 2021
ReplyDeletekbc winner list 2021
kbc 25 lack winner list 2021
This comment has been removed by the author.
ReplyDeleteYour post really helped me but there's one problem if u could Pleaseee forward qna.dat file asap it would be great.
ReplyDeleteurgent. please help.