Code:
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
using namespace std;
class Bowler{//******************************class bowler***********************
int overs,povers,maidovers,runsgiv,wictaken;
public:
void disp()
{
cout<<"\n\t BOWLER\n";
cout<<"\novers played : "<<povers;
cout<<"\nmaiden overs : "<<maidovers;
cout<<"\nruns given : "<<runsgiv;
cout<<"\nwickets taken : "<<wictaken;
}
int giv(char *choose)
{
if(!strcmp(choose,"overs"))
{
return(overs);
}
else if(!strcmp(choose,"maidovers"))
{
return(maidovers);
}
else if(!strcmp(choose,"runsgiv"))
{
return(runsgiv);
}
else if(!strcmp(choose,"wictaken"))
{
return(wictaken);
}
}
void over()
{
cout<<"enter number of overs : ";
cin>>overs;
}
void update(int run,int iout,int j,int balls[])
{
int l=0,m;
if(j==5)
{
povers++;
for(m=0;m<6;m++)
{
if(balls[m]==0)
l++;
}
}
if(l==6)
{
maidovers++;
for(m=0;m<6;m++)
{
balls[m]=1;
}
}
if(run!=5)
runsgiv=run;
else
runsgiv=0;
if(!iout)
{
wictaken++;
}
}
};
class Batsman{//********************class Batsman*******************************
int runs,iout,run,mod;
char name[10],*mout;
static int count;
public:
Batsman()
{
iout=1;
}
void updatecount()
{
count++;
}
int giv(char *choose)
{
if(!strcmp(choose,"iout"))
{
return(iout);
}
else if(!strcmp(choose,"runs"))
{
return(runs);
}
else if(!strcmp(choose,"run"))
{
return(run);
}
}
void init(int &a)
{
system("cls");
if(a!=0)
{
cout<<"the batsman #"<<count-1<<" is out now out\n";
}
cout<<"enter name of batsman #"<<count<<" : ";
cin>>name;
iout++;
runs=0;
}
void disp()
{
cout<<"\n\t BATSMAN #"<<count<<"\n";
cout<<"\nName : "<<name;
cout<<"\nruns made : "<<runs;
cout<<"\nstatus : ";
switch(mod)
{
case 0:strcpy(mout,"Catch-out");;break;
case 1:strcpy(mout,"Run-Out");break;
case 2:strcpy(mout,"Wicket");break;
case 3:strcpy(mout,"Bold");break;
case 4:strcpy(mout,"Hit-Wicket");break;
}
if(!iout)
{
cout<<"Out\n";
cout<<"mode by which out : "<<mout;
}
else if(iout)
{
cout<<"Not out";
}
}
void update()
{
srand(time(NULL));
run=rand()%7;
if(run==5)
{
iout--;
mod=rand()%5;
}
else
{
runs+=run;
}
}
};
int Batsman :: count=1;
int main()
{
Bowler ball;
Batsman bats[10];
ball.over();
system("cls");
char place[3];
int ov,i=0,balls[6],j,l=0,z=1,k;
bats[i].init(i);
cout<<"the score board is ready to be used\n";
getch();
system("cls");
ov=(ball.giv("overs"));
for(k=0;k<ov;k++)
{
if(l)
{
break;
}
for(j=0;j<6;j++)
{
balls[j]=bats[i].giv("run");
bats[i].update();
ball.update(bats[i].giv("run"),bats[i].giv("iout"),j,balls);
if(k+1==1)
{
strcpy(place,"st");
}
else if(k+1==2)
{
strcpy(place,"nd");
}
else if(k+1==3)
{
strcpy(place,"rd");
}
else
{
strcpy(place,"th");;
}
if(j==6)
{
system("cls");
cout<<"the "<<k+1<<place<<" over is finished";
cout<<"\n";
}
bats[i].disp();
ball.disp();
cout<<"\n\nnow the bowler throws the ball...\n";
cout<<"press enter to update the score board...";
getch();
system("cls");
if(!bats[i].giv("iout"))
{
if(i<10)
{
i++;
}
else if (i>10)
{
l++;
j=7;
break;
}
bats[i].updatecount();
bats[i].init(i);
}
}//end of loop of balls
}//end of loop of overs
system("cls");
if(k==ov)
{
cout<<"overs finished";
}
else if(l)
{
cout<<"all batsmen out !";
}
cout<<"\nend result :-";
bats[i].disp();
ball.disp();
getch();
return 0;
}//end of main()