@laserlight i don't know how to use that but i am curious to know!
@laserlight i don't know how to use that but i am curious to know!
Ah. What book are you using to learn C++?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
done
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")==0) { return(overs); } else if(strcmp(choose,"maidovers")==0) { return(maidovers); } else if(strcmp(choose,"runsgiv")==0) { return(runsgiv); } else if(strcmp(choose,"wictaken")==0) { 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")==0) { return(iout); } else if(strcmp(choose,"runs")==0) { return(runs); } else if(strcmp(choose,"run")==0) { 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()
Computer Science with C++ by sumita Arora(class XII)
Your program is going to crash and burn and kill your computer with it unless you switch over to C++ to get rid of those buffer overruns and other bugs.
And... remind me to not use your software in the future with all those buffer overruns.
Oh, and in case you don't know something, study it! Don't avoid it.
I have never heard of the book. The title hints that its focus is on computer science, and given what you have written, my guess is that the author treats C++ as a mere handmaiden for teaching computer science concepts. Consequently, if you want to learn how to program in C++, you may need additional material, e.g., Accelerated C++.Originally Posted by Mukul Kumar
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
!done
What about the problem I mentioned about srand()?
Where have you allocated the memory for the pointer that is contained in your class?
What about the problem with using the wrong header files?
What about the following warnings?
Jimmain.cpp||In member function ‘void Batsman::disp()’:|
main.cpp|119|warning: switch missing default case [-Wswitch-default]|
main.cpp||In function ‘int main()’:|
main.cpp|167|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|176|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|178|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|178|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|207|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|162|warning: unused variable ‘z’ [-Wunused-variable]|
main.cpp||In member function ‘int Bowler::giv(char*)’:|
main.cpp|36|warning: control reaches end of non-void function [-Wreturn-type]|
main.cpp||In member function ‘int Batsman::giv(char*)’:|
main.cpp|100|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build finished: 0 errors, 9 warnings ===|
i think i am getting only 5 warnings!of those conversions
@elysia whoose avoiding it? read post#16
Well, you still need to use more descriptive names. It is also likely that your main function could do with being split up into smaller functions. Oh, and you have not yet address my point about the class design.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
You're avoiding using std::string, which means pretty soon everyone is going to start ignoring you.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
aah mann i am paralyzed from one side ......in my school my teacher teaches us 1980's programming and we use turbo C++ 3.0
and at home i use DEV C++ 5.4
i don't think that i know the core meaning and implementation of classes
Last edited by Mukul Kumar; 05-14-2013 at 12:04 PM.
how am i supposed to change my school teacher?
i clearly can't
also i don't know abcd... of namespaces
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?