Analyzing a program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zakaria2710
    New Member
    • Mar 2007
    • 6

    #1

    Analyzing a program

    Question
    a)Explain what process are being carried out by each method
    b)Test this code on your system and report the outcome of your tests in a systematic manner.You need to provide rationale for every test undertaken
    c)write a critical review of the given code and identify any strengths oe weakness that may be present.

    Code:
    #include <graphics.h>
    #include <stdlib.h>
    #include <time.h>
    #include <math.h>
    #include <conio.h>
    
    const int X0=320;
    const int Y0=240;
    const float PI=3.14159;
    const int NUME=30;
    const DENOM=100;
    const NUMBER=7;
    const float RAD=3.0;
    const float DELTHETA=0.1;
    const int SEGS=60;
    const int REDUX=3;
    const int MIN=1;
    
    class cluster
    {
    Public:
    void display (int size,int x ,int y);
    };
    class tendril
    {
    public:
    void display(int size,float theta,int x,int y);
    };
    void cluster::display(int size,int x,int y)
    {
    if(kbhit())
    exit(0);
    for(int i=0;i<NUMBER;++)
    {
    float theta=i*2*PI/NUMBER;
    moveto(x,y);
    tendril t;
    t.display(size,theta,x,y);
    }
    }
    void tendril::display(int size,float theta, int x,int y)
    {
    for(int j=0; j<size; j++)
    {
    int chng = (random(DENON)<NUME)?-1:1);
    theta=theta+chng*DELTHETA;
    x=x+RAD*sin(theta);
    y=y+RAD*cos(theta);
    if(size<4)setcolor(RED);
    else if(size<13)setcolor(GREEN);
    else if(size<40)setcolor(LIGHTGREEN);
    else setcolor(YELLOW);
    lineto(x,y);
    }
    if(size>MIN)
    {
    cluster c;
    int newsize=size/REDUX;
    c.display(newsize, x,y);
    }
    }
    void main ()
    {
    int driver, mode;
    driver=VGA;
    mode=VGAHI;
    initgraph(&driver,&mode,"\\bc45\\bgi");
    randomize();
    
    int X=0, y=0;
    int size=SEGS;
    cluster c;
    c.display(size, x,y);
    getch();
    closegraph();
    }
    Last edited by horace1; Mar 9 '07, 09:44 AM. Reason: added code tags
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    there are a number of errors in the code, e.g. under C++ DENOM requires a type specified (int, float, double, ?)
    Code:
    const DENOM=100;
    you have a capital P in public
    Code:
    class cluster
    {
    Public:
    are you suposed to fix the errors until the code works giving an explaination in each case ?

    Comment

    • zakaria2710
      New Member
      • Mar 2007
      • 6

      #3
      Originally posted by horace1
      there are a number of errors in the code, e.g. under C++ DENOM requires a type specified (int, float, double, ?)
      Code:
      const DENOM=100;
      you have a capital P in public
      Code:
      class cluster
      {
      Public:
      are you suposed to fix the errors until the code works giving an explaination in each case ?
      Yes! I supose to fix the errors unitil the code works and giving an explanation in each case! Thank u so much if ypu can help me on this I will appreciate!

      Comment

      • zakaria2710
        New Member
        • Mar 2007
        • 6

        #4
        Yes! I supose to fix the errors unitil the code works and giving an explanation in each case! Thank u so much if you can help me on this, I will appreciate!

        Comment

        • DeMan
          Top Contributor
          • Nov 2006
          • 1799

          #5
          Not sure of the problem.....

          1) Explain the process carried out by the code
          2) test this code and explain your results, including why you ran this test
          3) Explain why this code is good or bad

          1) is definitely for you to have a look at what this code is doing
          2) are there any situations where this code should (or better still shouldn't) work....try to simulate these scenarios. In particular, are there specific "boundary values" (this will work near this value but shouldn't AT)
          3) given 1 & 2 above, fo you think this code is good, or could you suggest some improvement.

          Comment

          • horace1
            Recognized Expert Top Contributor
            • Nov 2006
            • 1510

            #6
            Originally posted by zakaria2710
            Yes! I supose to fix the errors unitil the code works and giving an explanation in each case! Thank u so much if ypu can help me on this I will appreciate!
            Compile the code - the compiler will list the errors it finds - attempt to fix them one by one making a note what the errors was and how you fixed it. When it compiles run it and see what it does.

            Comment

            • andersod
              New Member
              • Mar 2007
              • 9

              #7
              hi,
              It seems that there are a number of errors placed in the code to help you to understand what your instructor is trying to teach you. If you are not sure of what you are doing, try doing the following.

              1. place comments arround the class object that is being called.
              2. In main, place a comment arround the instantiation of the object in step 1.
              3. compile the code and fix the errors.
              4. run the code and see what happens.
              5. If you are satisfied that everything looks good. Uncomment the codes in step 1 and 2.
              go to step 3, and 4.

              This process will help you to control the evaluation process.

              Hope this helps.

              Regards,
              Desmond

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Renamed the thread.

                Comment

                • zakaria2710
                  New Member
                  • Mar 2007
                  • 6

                  #9
                  Thank you mate for your help, I will do what u have asked me to do!
                  Regards
                  Zak

                  Originally posted by andersod
                  hi,
                  It seems that there are a number of errors placed in the code to help you to understand what your instructor is trying to teach you. If you are not sure of what you are doing, try doing the following.

                  1. place comments arround the class object that is being called.
                  2. In main, place a comment arround the instantiation of the object in step 1.
                  3. compile the code and fix the errors.
                  4. run the code and see what happens.
                  5. If you are satisfied that everything looks good. Uncomment the codes in step 1 and 2.
                  go to step 3, and 4.

                  This process will help you to control the evaluation process.

                  Hope this helps.

                  Regards,
                  Desmond

                  Comment

                  Working...