#include<iostream>
#include<cstring>
#include<cstdlib>
#include<fstream>
//#include<manip.h>
using namespace std;
//char b[9] = {'B', 'O', 'L', 'L', 'Y', 'W', 'O', 'O', 'D'};
class Bollywood
{
protected:
char name[20];
int roll;
char m[15];
char cut[15];
int points;
int count;
char b[9];
int length;
public:
Bollywood()
{
length=0;
roll = 0;
points=0;
count=0;
strcpy(name,"ABC");
strcpy(b,"BOLLYWOOD");
}
void getdata()
{
cout<<"\n\nEnter your name:";
cin>>name;
cout<<endl<<"Enter your Roll number:";
cin>>roll;
}
void displayname()
{
cout<<"\n Hello "<<name<<"!!!!"<<endl;
}
void setb()
{
strcpy(b,"BOLLYWOOD");
}
int llength() //To find the length
{
int length=strlen(m),cnt=0;
for(int i=0;i<strlen(m);i++)
{
if(cut[i]=='_')
{
cnt++;
}
}
return cnt;
}
int random(int num)
{
return (num % 6)+1 ;
}
virtual void getque(){}
virtual void cutdisplay(){}
virtual int vowels(){}
virtual void getletter(){}
};
class Easy:public Bollywood
{
public:
void getque() //to read the question from file
{
ifstream in;
int num;
char a;
int i=0;
in.open("easy.txt");
//cout<<"file is open"<<endl;
num = random(roll);
while(i<((num-1)*2))
{
in.getline(m,30);
i++;
}
in.getline(m,30);
in.getline(cut,30);
}
void cutdisplay() //display to player
{
int i;
cout<<endl<<"\t\t";
for(i=0;i<strlen(m);i++)
{
cout<<cut[i]<<" ";
}
cout<<endl;
}
void getletter() //to get the letter from the user and all the calculations
{
int flag,flag1=1;
char letter;
int correct=0; //counter for correct guess
int k= 0;
char entered[20]; //store the value of letter entered by user
int set=0; //counter for letter enter by user twice
do
{
int i , j;
if(flag1==1) //first time display
{
cout<<"\n\t\t"<<b<<endl;
cutdisplay();
length=llength();
}
flag1=0;
cout<<"\n Enter the letter in uppercase order to guess the movie: ";
cin>>letter;
flag=0;
//cout<<"\t\t\n"<<length;
entered[k++] = letter;
for(j=0;j<strlen(m);j++) //check in the answer array and replace
{
if(m[j] == letter)
{
cut[j] = letter;
flag=1;
for (i=0;i<k-1;i++)
{
if(letter == entered[i]) //if letter is repeated then minus the correct counter
{
correct--;
set=1;
}
}
correct++;
}
}
if(flag==0) //if wrong guess
{
b[count]='$';
count++;
cout<<endl<<"Oops!!!!! Sorry, Wrong guess\n";
}
cout<<"\n\t\t"<<b<<endl;
cutdisplay();
if(set==1)
{
cout<<letter<<" has already been entered"<<endl;
set=0;
}
if(correct == length) //After guessing correct movie
{
int c;
roll++;
for(j=0;j<k;j++)
entered[j]= 0;
k=0;
getque();
correct = 0;
flag1=1;
cout<<endl<<"\n\nCongratulations "<<name<< " You guessed the movie right.\n\n";
points+=10;
cout<<endl<<"You earned "<<points<<" points"<<endl;
cout<<"\n\nEnter 1 for Continue :";
cin>>c;
if(c!=1)
{
cout<<endl<<"You earned "<<points<<" points"<<endl;
exit(1);
}
cout<<endl<<endl<<"Next Movie:"<<endl;
}
}while(count!= 9 );
cout<<endl<<"Game over"<<endl<<endl;
cout<<"Congratulations, "<<name<<" You scored "<<points<<" points"<<endl<<"Bye Bye"<<endl;
//'b[]={'B', 'O', 'L', 'L', 'Y', 'W', 'O', 'O', 'D'};
setb();
//cout<<b;
count=0;
}
};
class Medium:public Bollywood
{
public:
void getque() //to read the question from file
{
ifstream in;
int num;
char a;
int i=0;
in.open("medium.txt");
//cout<<"file is open"<<endl;
num = random(roll);
while(i<((num-1)*2))
{
in.getline(m,30);
i++;
}
in.getline(m,30);
in.getline(cut,30);
}
void cutdisplay() //display to player
{
int i;
cout<<endl<<"\t\t";
for(i=0;i<strlen(m);i++)
{
cout<<cut[i]<<" ";
}
cout<<endl;
}
void getletter() //to get the letter from the user and all the calculations
{
int flag,flag1=1;
char letter;
int correct=0; //counter for correct guess
int k= 0;
char entered[20]; //store the value of letter entered by user
int set=0; //counter for letter enter by user twice
do
{
int i , j;
if(flag1==1) //first time display
{
cout<<"\n\t\t"<<b<<endl;
cutdisplay();
length=llength();
}
flag1=0;
cout<<"\n Enter the letter in uppercase order to guess the movie: ";
cin>>letter;
flag=0;
cout<<"\t\t\n"<<length;
entered[k++] = letter;
for(j=0;j<strlen(m);j++) //check in the answer array and replace
{
if(m[j] == letter)
{
if(cut[j]=='_')
{
cut[j] = letter;
flag=1;
correct++;
}
for (i=0;i<k-1;i++)
{
if(letter == entered[i]) //if letter is repeated then minus the correct counter
{
set=1;
}
}
// cout<<"\t\t\t\n"<<correct;
}
}
if(flag==0) //if wrong guess
{
b[count]='$';
count++;
cout<<endl<<"Oops!!!!! Sorry, Wrong guess\n";
}
cout<<"\n\t\t"<<b<<endl;
cutdisplay();
if(set==1)
{
cout<<letter<<" has already been entered"<<endl;
set=0;
}
if(correct == length) //After guessing correct movie
{
int c;
roll++;
for(j=0;j<k;j++)
entered[j]= 0;
k=0;
getque();
correct = 0;
flag1=1;
//cutdisplay();
cout<<endl<<"\n\nCongratulations "<<name<< " You guessed the movie right.\n\n";
points+=10;
cout<<endl<<"You earned "<<points<<" points"<<endl;
cout<<"\n\nEnter 1 for Continue:";
cin>>c;
if(c!=1)
{
cout<<endl<<"You earned "<<points<<" points"<<endl;
exit(1);
}
cout<<endl<<endl<<"Next Movie:"<<endl;
}
}while(count!= 9 );
cout<<endl<<"Game over"<<endl<<endl;
cout<<"Congratulations, "<<name<<" You scored "<<points<<" points"<<endl<<"Bye Bye"<<endl;
//'b[]={'B', 'O', 'L', 'L', 'Y', 'W', 'O', 'O', 'D'};
setb();
//cout<<b;
count=0;
}
};
class Hard:public Bollywood
{
public:
void getque() //to read the question from file
{
ifstream in;
int num;
char a;
int i=0;
in.open("hard.txt");
//cout<<"file is open"<<endl;
num = random(roll);
while(i<((num-1)*2))
{
in.getline(m,30);
i++;
}
in.getline(m,30);
in.getline(cut,30);
}
void cutdisplay() //display to player
{
int i;
cout<<endl<<"\t\t";
for(i=0;i<strlen(m);i++)
{
cout<<cut[i]<<" ";
}
cout<<endl;
}
void getletter() //to get the letter from the user and all the calculations
{
int flag,flag1=1;
char letter;
int correct=0; //counter for correct guess
int k= 0;
char entered[20]; //store the value of letter entered by user
int set=0; //counter for letter enter by user twice
do
{
int i , j;
if(flag1==1) //first time display
{
cout<<"\n\t\t"<<b<<endl;
cutdisplay();
length=llength();
}
flag1=0;
cout<<"\n Enter the letter in uppercase order to guess the movie: ";
cin>>letter;
flag=0;
cout<<"\t\t\n"<<length;
entered[k++] = letter;
for(j=0;j<strlen(m);j++) //check in the answer array and replace
{
if(m[j] == letter)
{
if(cut[j]=='_')
{
cut[j] = letter;
flag=1;
correct++;
}
for (i=0;i<k-1;i++)
{
if(letter == entered[i]) //if letter is repeated then minus the correct counter
{
set=1;
}
}
// cout<<"\t\t\t\n"<<correct;
}
}
if(flag==0) //if wrong guess
{
b[count]='$';
count++;
cout<<endl<<"Oops!!!!! Sorry, Wrong guess\n";
}
cout<<"\n\t\t"<<b<<endl;
cutdisplay();
if(set==1)
{
cout<<letter<<" has already been entered"<<endl;
set=0;
}
if(correct == length) //After guessing correct movie
{
int c;
roll++;
for(j=0;j<k;j++)
entered[j]= 0;
k=0;
getque();
correct = 0;
flag1=1;
//cutdisplay();
cout<<endl<<"\n\nCongratulations "<<name<< " You guessed the movie right.\n\n";
points+=10;
cout<<endl<<"You earned "<<points<<" points"<<endl;
cout<<"\n\nEnter 1 for Continue:";
cin>>c;
if(c!=1)
{
cout<<endl<<"You earned "<<points<<" points"<<endl;
exit(1);
}
cout<<endl<<endl<<"Next Movie:"<<endl;
}
}while(count!= 9 );
cout<<endl<<"Game over"<<endl<<endl;
cout<<"Congratulations, "<<name<<" You scored "<<points<<" points"<<endl<<"Bye Bye"<<endl;
//'b[]={'B', 'O', 'L', 'L', 'Y', 'W', 'O', 'O', 'D'};
setb();
//cout<<b;
count=0;
}
};
int main()
{
int ch ,flag=0;
Easy e1;
Medium m1;
Hard h1;
Bollywood *b1=&e1,*b2=&m1,*b3=&h1,b;
//b1->getdata();
//b1=b2=b3;
cout<<"\n ------------------------------------------------------------------------";
cout<<"\n\t\t >> Welcome to the Bollywood quiz\n";
cout<<"\n >> NOTE : 10 MARKS per question if whole ans will be right";
cout<<"\n\n >> Use only UPPERCASE LETTER ....!!";
cout<<"\n\n >> Dont use the letter again if once it will be right";
cout<<"\n ------------------------------------------------------------------------";
//b1->displayname();
cout<<endl<<"\nChoose your level:\n";
do
{
cout<<endl<<"1.Easy"<<endl;
cout<<endl<<"2.Medium"<<endl;
cout<<endl<<"3.Hard"<<endl;
cout<<endl<<"0.Quit"<<endl<<endl;
cout<<"Input:";
cin>>ch;
switch(ch)
{
case 1: if(flag==0)
{
b1->getdata();
b1->getque();
b1->getletter();
flag=1;
}
else
{
b1->getque();
b1->getletter();
}
break;
case 2: if(flag==0)
{
b2->getdata();
b2->getque();
b2->getletter();
flag=1;
}
else
{
b2->getque();
b2->getletter();
}
break;
case 3: if(flag==0)
{
b3->getdata();
b3->getque();
b3->getletter();
flag=1;
}
else
{
b3->getque();
b3->getletter();
}
break;
case 4: break;
default: cout<<"Invalid entry";
}
cout<<endl<<"Want to play again:";
cin>>ch;
}while(ch!=0);
return 0;
}
//easy,medium,hard files should be included in the folder with data like given bellow
HEROPANTI
_E_O_A__I
FUKREY
_U__E_
DHOOM
__OO_
WAQT
_A__
PIKU
_I_U
GABBAR IS BACK
_A__A_ I_ _A__
DHAMAAL
__A_AA_
GOLMAAL
_O__AA_
RAONE
_AO_E
VICKY DONOR
_I___ _O_O_