Sunteți pe pagina 1din 11

PROGRAM CODE

#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
class handC{
public:
char ch;

char toss;
char choose;
int runs1;
int runs2;
int z;
int c;
handC();
void show();
int p;
int arr[6];

private:
int calculate();
int me();
void disover();
void initia();

};
handC::handC(){
ch=' ';
toss=choose=' ';
runs2=runs1=z=c=p=0;
}

void handC ::show(){


cout<<endl<<"welcome to test cricket match"<<endl;
unsigned int seed;
time_t t;
seed=(unsigned)time(&t);
srand(seed);
while(z==0){
cout<<endl<<"welcome to toss"<<endl;
cout<<endl<<"enter t to take tails or h to take
heads"<<endl;
cin>>toss;
p=rand();
if(p%2==0)
cout<<endl<<"you won the toss"<<endl;
else
cout<<endl<<"you lost the toss"<<endl;
if(p%2==0){
cout<<endl<<"enter O to bowl or A to bat
"<<endl;
cin>>ch;

if(ch=='a'|| ch=='A') {

runs1=calculate();
cout<<endl<<"you are out and your runs
is= "<<runs1<<" now you will bowl"<<endl;
runs2=me();
cout<<endl<<"I am out and my runs is=
"<<runs2<<endl;
if(runs1>runs2)
cout<<endl<<"man you won the
match"<<endl;
else if(runs1<runs2)
cout<<endl<<"man you lost the
match"<<endl;
else
cout<<endl<<"match tied"<<endl;
}
else if(ch=='O'||ch=='o'){
runs2=me();
cout<<endl<<"I am out and my runs is=
"<<runs2<<" now you will bat"<<endl;
runs1=calculate();
cout<<endl<<"you are out and your runs
is= "<<runs1<<endl;
if(runs1>runs2)
cout<<endl<<"man you won the
match"<<endl;
else if(runs1<runs2)
cout<<endl<<"man you lost the
match"<<endl;
else
cout<<endl<<"match tied"<<endl;

}
}
else{
p=p+rand()%100;
if(p%2==0){

cout<<endl<<"i choose to bat and you


will bowl"<<endl;
ch='o';
}
else{
cout<<endl<<"i choose to bowl & you
will bat"<<endl;
ch='a';
}
if(ch=='a'|| ch=='A') {

runs1=calculate();
cout<<endl<<"you are out and your runs
is= "<<runs1<<" now you will bowl"<<endl;
runs2=me();
cout<<endl<<"I am out and my runs is=
"<<runs2<<endl;
if(runs1>runs2)
cout<<endl<<"man you won the
match"<<endl;
else if(runs1<runs2)
cout<<endl<<"man you lost the
match"<<endl;
else
cout<<endl<<"match tied"<<endl;
}
else if(ch=='O'||ch=='o'){
runs2=me();
cout<<endl<<"I am out and my runs is=
"<<runs2<<" now you will bat"<<endl;
runs1=calculate();
cout<<endl<<"you are out and your runs
is= "<<runs1<<endl;
if(runs1>runs2)
cout<<endl<<"man you won the
match"<<endl;
else if(runs1<runs2)
cout<<endl<<"man you lost the
match"<<endl;
else
cout<<endl<<"match tied";

}
cout<<endl<<"to continue press 0 or any other
number to discontinue"<<endl;
cin>>z;
}
}
int handC:: calculate(){
int x=0;
int sum=0;
int s=0;
int c=0;
int cnt=0;
while(c!=1){
cnt++;
cin>>x;
x=x%7;
s=rand()%7;
cout<<endl<<"my shot="<<s<<endl;
if(s!=x)
sum=sum+x;
else
c=1;
arr[cnt-1]=x;
if(cnt==6){
disover();
initia();
cnt=0;
}
}
return sum;
sum=0;

}
int handC :: me(){
int x=0;
int sum=0;
int s=0;
int c=0;
int cnt=0;
while(c!=1){
cnt++;
cin>>x;
x=x%7;
s=rand()%7;
cout<<endl<<"my shot="<<s<<endl;
if(s!=x)
sum=sum+s;
else
c=1;
arr[cnt-1]=s;
if(cnt==6){
disover();
initia();
cnt=0;
}
}
return sum;
sum=0;

}
void handC::disover(){
int i=0;
int add=0;
cout<<endl<<"runs of this over are"<<endl;
for(i=0;i<6;i++){
cout<<arr[i]<<" ";
add=add+arr[i];
}
cout<<endl<<"total run of this over= "<<add<<endl;
}
void handC::initia(){
int i=0;
for(i=0;i<6;i++)
arr[i]=0;
}

int main(){
handC ob;
ob.show();
}

S-ar putea să vă placă și