Wednesday, July 30, 2014

Procedures: Revisiting squares

The following programs are intended to provide practice with writing procedures in Pro-Bot, storing them in Pro-Bot's memory and calling them.


(1)  Write a program for Pro-Bot to draw a square of sides 6 cm. Store this program as a procedure on Pro-Bot (say proc1). Now call this procedure (proc1) from Main to test and see if Pro-Bot draws a 6 cm square.



(2)  Now that you have your program for drawing a 6 cm square stored in Pro-Bot's memory, any time you want to use it, you can call it either from your Main program or from another procedure.
You may recall the figure below from the Nested Loops assignment.




















Can you use the procedure that you have in Pro-Bot's memory to draw the above figure now? Rewrite your previous program for Pro-Bot to trace this figure, using the procedure for the square.




(3)   Let's revisit the Trains project from Nested Loops. Can you rewrite your previous program for Pro-Bot to draw the coaches of the train using the above procedure?




















In all of the projects above, you can see that you did not have to write the code for the square anew each time. All you had to do was write the program for the square once, store it as a procedure and then call the procedure any time you needed its functionality. You were able to use the same procedure for different programs.


Here is a set of solutions.

No comments:

Post a Comment