Thread: is my programming flawless? i need to reach that level of skill

  1. #16
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    @laserlight i don't know how to use that but i am curious to know!

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Ah. What book are you using to learn C++?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    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()

  4. #19
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    Computer Science with C++ by sumita Arora(class XII)

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Mukul Kumar
    Computer Science with C++ by sumita Arora(class XII)
    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++.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #22
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    !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?

    main.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 ===|
    Jim

  8. #23
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    i think i am getting only 5 warnings!of those conversions

  9. #24
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    @elysia whoose avoiding it? read post#16

  10. #25
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #26
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    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.

  12. #27
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    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.

  13. #28
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Mukul Kumar View Post
    in my school my teacher teaches us 1980's programming and we use turbo C++ 3.0
    find a new teacher. turbo C++ 3.0 is about as relevant to modern C++ as the grammy awards are to music.
    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?

  14. #29
    Registered User
    Join Date
    Apr 2013
    Posts
    103
    how am i supposed to change my school teacher?
    i clearly can't
    also i don't know abcd... of namespaces

  15. #30
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Mukul Kumar View Post
    also i don't know abcd... of namespaces
    I'm pretty sure you mentioned that before in another thread, and I told you then that it's my signature. it appears on all of my posts. have you ever used a forum before? have you noticed all the other users with signatures on their posts?
    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?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. game development & programming skill required
    By newprog82 in forum Game Programming
    Replies: 2
    Last Post: 11-02-2010, 11:29 AM
  2. API Programming in network level
    By rchiu5hk in forum C++ Programming
    Replies: 0
    Last Post: 09-07-2009, 10:42 PM
  3. low level programming book
    By CChakra in forum C Programming
    Replies: 5
    Last Post: 09-08-2008, 01:23 PM
  4. Ways to better programming skill
    By Unferth in forum C++ Programming
    Replies: 9
    Last Post: 09-23-2003, 05:35 PM
  5. Low level programming question
    By phooey in forum C++ Programming
    Replies: 2
    Last Post: 02-16-2003, 08:59 AM