By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

Analyzing a program

P: 6
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.

Expand|Select|Wrap|Line Numbers
  1. #include <graphics.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <math.h>
  5. #include <conio.h>
  6.  
  7. const int X0=320;
  8. const int Y0=240;
  9. const float PI=3.14159;
  10. const int NUME=30;
  11. const DENOM=100;
  12. const NUMBER=7;
  13. const float RAD=3.0;
  14. const float DELTHETA=0.1;
  15. const int SEGS=60;
  16. const int REDUX=3;
  17. const int MIN=1;
  18.  
  19. class cluster
  20. {
  21. Public:
  22. void display (int size,int x ,int y);
  23. };
  24. class tendril
  25. {
  26. public:
  27. void display(int size,float theta,int x,int y);
  28. };
  29. void cluster::display(int size,int x,int y)
  30. {
  31. if(kbhit())
  32. exit(0);
  33. for(int i=0;i<NUMBER;++)
  34. {
  35. float theta=i*2*PI/NUMBER;
  36. moveto(x,y);
  37. tendril t;
  38. t.display(size,theta,x,y);
  39. }
  40. }
  41. void tendril::display(int size,float theta, int x,int y)
  42. {
  43. for(int j=0; j<size; j++)
  44. {
  45. int chng = (random(DENON)<NUME)?-1:1);
  46. theta=theta+chng*DELTHETA;
  47. x=x+RAD*sin(theta);
  48. y=y+RAD*cos(theta);
  49. if(size<4)setcolor(RED);
  50. else if(size<13)setcolor(GREEN);
  51. else if(size<40)setcolor(LIGHTGREEN);
  52. else setcolor(YELLOW);
  53. lineto(x,y);
  54. }
  55. if(size>MIN)
  56. {
  57. cluster c;
  58. int newsize=size/REDUX;
  59. c.display(newsize, x,y);
  60. }
  61. }
  62. void main ()
  63. {
  64. int driver, mode;
  65. driver=VGA;
  66. mode=VGAHI;
  67. initgraph(&driver,&mode,"\\bc45\\bgi");
  68. randomize();
  69.  
  70. int X=0, y=0;
  71. int size=SEGS;
  72. cluster c;
  73. c.display(size, x,y);
  74. getch();
  75. closegraph();
  76. }
  77.  
Mar 9 '07 #1
Share this Question
Share on Google+
8 Replies


Expert 100+
P: 1,510
there are a number of errors in the code, e.g. under C++ DENOM requires a type specified (int, float, double, ?)
Expand|Select|Wrap|Line Numbers
  1. const DENOM=100;
  2.  
you have a capital P in public
Expand|Select|Wrap|Line Numbers
  1. class cluster
  2. {
  3. Public:
  4.  
are you suposed to fix the errors until the code works giving an explaination in each case ?
Mar 9 '07 #2

P: 6
there are a number of errors in the code, e.g. under C++ DENOM requires a type specified (int, float, double, ?)
Expand|Select|Wrap|Line Numbers
  1. const DENOM=100;
  2.  
you have a capital P in public
Expand|Select|Wrap|Line Numbers
  1. class cluster
  2. {
  3. Public:
  4.  
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!
Mar 9 '07 #3

P: 6
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!
Mar 9 '07 #4

DeMan
100+
P: 1,806
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.
Mar 9 '07 #5

Expert 100+
P: 1,510
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.
Mar 9 '07 #6

P: 9
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
Mar 9 '07 #7

10K+
P: 13,264
Renamed the thread.
Mar 10 '07 #8

P: 6
Thank you mate for your help, I will do what u have asked me to do!
Regards
Zak

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
Mar 10 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.