Documente Academic
Documente Profesional
Documente Cultură
#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;
}
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){
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();
}