Programming Right From the Start with Visual Basic.NET CHAPTER 5 Graphics and Procedures True-False Questions 1. The Logo Programming Language is the basis for the graphics of Visual Logic. Answer: True Level: Easy Section: 5-1 Page: 80 2. The graphic command Turn Right D will make the pen turn right and move the distance D. Answer: False Level: Easy Section: 5-1 Page: 82 3. The graphic command Turn Left D will make the pen turn left D degrees. Answer: True Level: Easy Section: 5-1 Page: 82 4. Forward, Turn Left, and Fill Circle are examples of Multimedia commands. Answer: False Level: Easy Section: 5-1 Page: 82 5. The home position of the pen is in the center of the screen facing south. Answer: False Level: Easy Section: 5-1 Page: 80 6. Using only a loop, Turn Right, and Forward graphic command any shape can be drawn. Answer: True Level: Easy Section: 5-1 Page: 84 7. The Go Home command causes the pen to move to the center of the screen and face 0º. Answer: True Level: Easy Section: 5-1 Page: 81 8. In the Visual Logic graphic system 90º is considered East unless the Rotate Axis command is executed. Answer: False Level: Moderate Section: 5-1 Page: 80 9. The pen is set at a color of blue and a width of 1 by default. Answer: False Level: Easy Section: 5-2 Page: 85 10. The Set Color command is used to change the color of the pen. Answer: True Level: Easy Section: 5-2 Page: 85 4-1 Chapter 5 – Graphics and Procedures 11. The Pen Size command is used to make the pen line wider. Answer: False Level: Moderate Section: 5-2 Page: 85 12. Both the Color Forward and Set Color commands are used to change to color of the pen. Answer: True Level: Easy Section: 5-2 Page: 86 13. The Set Color command will open the color dialog box. Answer: True Level: Moderate Section: 5-2 Page: 85 14. After using the Set Color command the pen will change back to the default color of black when ten other commands are executed. Answer: False Level: Hard Section: 5-2 Page: 85 15. A procedure is a set of programming instructions grouped together into a single unit. Answer: True Level: Easy Section: 5-3 Page: 85 16. Structured design is the process of breaking a problem into smaller parts. Answer: True Level: Easy Section: 5-3 Page: 87 17. A procedure is the solution to a small part of a problem identified through the process of structured design. Answer: True Level: Moderate Section: 5-3 Page: 87 18. The Call Procedure menu option will only allow you to add a new procedure. Answer: False Level: Moderate Section: 5-3 Page: 89 19. A special process must be followed to add commands to a procedure. Answer: False Level: Easy Section: 5-3 Page: 88 20. Procedures with arguments are used to create general solutions to problems. Answer: True Level: Moderate Section: 5-4 Page: 91 21. A formal argument is the parameter as it is referred to inside the procedure. Answer: True Level: Easy Section: 5-4 Page: 91 5-2 Chapter 5 – Graphics and Procedures 22. The name of the actual argument must match the name of the formal argument. Answer: False Level: Easy Section: 5-4 Page: 92 23. The name of the formal argument is found in the parentheses after the procedure name in the definition of the procedure. Answer: True Level: Hard Section: 5-4 Page: 93 24. The order of the actual arguments when the procedure is called does not have to match the order of the formal arguments inside the procedure. Answer: False Level: Moderate Section: 5-4 Page: 93 25. Arguments are used to send information from the calling program to the procedure. Answer: True Level: Easy Section: 5-4 Page: 93 26. An argument in a procedure is different from a parameter in a procedure. Answer: False Level: Easy Section: 5-4 Page: 90 27. Loops cannot be placed inside a procedure. Answer: False Section: 5-4 Level: Easy Page: 91 28. The actual argument can be edited in the Arguments dialog box. Answer: True Level: Easy Section: 5-4 Page: 92 29. The procedure name can be edited in the Arguments dialog box. Answer: False Level: Moderate Section: 5-4 Page: 92 30. Multiple arguments can be added to a procedure in the Procedure Edit dialog box. Answer: True Level: Easy Section: 5-5 Page: 93 31. After the Procedure Edit dialog box is closed, the developer must type in the procedure stub. Answer: False Level: Easy Section: 5-3 Page: 88 32. A recursive procedure calls two or more different procedures. Answer: False Level: Easy Section: 5-5 Page: 94 33. Good programmers create as many infinite recursions as possible. Answer: False Level: Easy Section: 5-5 Page: 94 5-3 Chapter 5 – Graphics and Procedures 34. When a base cast test on a parameter is false, the procedure will not call itself. Answer: True Level: Moderate Section: 5-5 Page: 94 35. A loop is like a recursive procedure because the same actions are repeated many times. Answer: True Level: Moderate Section: 5-5 Page: 94 Multiple Choice Questions 36. Which is not a Visual Logic graphic command? a.) Rotate Left D b.) Forward N c.) Set Color C d.) Circle N e.) Pen Up Answer: a Section: 5-1 37. Level: Moderate Page: 81 Which is true about the graphic positions? a.) The home position faces south. b.) The north, south, east and west positions can be changed with a command. c.) The pen starts in the upper right hand corner of the screen. d.) The home position is at the coordinates (0, 0). e.) None of the above. Answer: d Section: 5-1 38. Level: Moderate Page: 80 Which three statements can be used to create any graphic shape? a.) Loop, Forward, and Backward b.) Input, Forward, and Backward c.) Loop, Forward, and Turn Right d.) Input, Forward, and Turn Right e.) Loop, Forward, and Go Home Answer: c Section: 5-1 Level: Moderate Page: 83 5-4 Chapter 5 – Graphics and Procedures 39. Which graphic command rotates the pen’s drawing direction without moving the pen? a.) Forward N b.) Turn Left D c.) Set Direction D d.) Both b and c. e.) All of the above. Answer: d Section: 5-1 40. Level: Moderate Page: 81 Which shape can be created with just one graphic command? a.) Circle b.) Triangle c.) Square d.) Rectangle e.) Hexagon Answer: a Section: 5-1 41. Level: Easy Page: 81 The default color for the graphic pen is: a.) blue. b.) black. c.) green. d.) red. e.) There is no default color. Answer: b Section: 5-2 42. Level: Easy Page: 85 Which sets of colors will the Color Forward command not cycle through? a.) yellow-red b.) red-blue c.) blue-green d.) green-red e.) All are sets of colors for the Color Forward command. Answer: a Section: 5-2 43. Level: Moderate Page: 86 Which command causes the standard color dialog box to open? a.) Go Home b.) Set Direction c.) Set Color d.) Color Forward e.) Pen Width Answer: c Section: 5-2 Level: Moderate Page: 85 5-5 Chapter 5 – Graphics and Procedures 44. When programming instructions are grouped together into a single unit this is called a: a.) graphic command. b.) do loop. c.) For loop. d.) recursion. e.) procedure. Answer: e Section: 5-3 45. Level: Moderate Page: 87 Breaking a problem into smaller parts is called: a.) recursion. b.) structured design. c.) implementation. d.) logical design. e.) syntax. Answer: b Section: 5-3 46. Level: Moderate Page: 87 What happens when a procedure is called? a.) The control of the program exits the procedure. b.) The control of the program goes to the inside of the procedure. c.) The control of the program returns to the calling statement. d.) First a then b. e.) First b then a then c. Answer: e Section: 5-3 47. Level: Moderate Page: 87 Which is true about a procedure? a.) It has at least one argument. b.) It has at least one parameter. c.) It has more than one argument. d.) It has more than one parameter. e.) Arguments and parameters are optional in procedures. Answer: e Section: 5-4 48. Level: Easy Page: 90 An actual argument is: a.) a special argument that is never used in a procedure. b.) the argument inside the procedure. c.) the argument at the time the procedure is called. d.) optional in a procedure with arguments. e.) Both b and c. Answer: c Section: 5-4 Level: Hard Page: 91 5-6 Chapter 5 – Graphics and Procedures 49. The formal argument is: a.) used inside the procedure. b.) is defined in the Procedure Edit dialog box. c.) is added with the New button located below the Arguments box. d.) Both a and b. e.) All of the above. Answer: e Section: 5-4 50. Level: Moderate Page: 91 The procedure name and arguments are displayed: a.) in the procedure header element. b.) in the procedure footer element. c.) inside the body of the procedure. d.) Both a and b. e.) All of the above. Answer: d Section: 5-4 51. Level: Easy Page: 92 Double clicking on a procedure element will activate the: a.) Procedure Edit dialog box. b.) Argument dialog box. c.) Graphic dialog box. d.) Color dialog box. e.) None of the above. Answer: b Section: 5-4 52. Level: Moderate Page: 92 A recursive procedure: a.) will call itself. b.) should be avoided at all costs. c.) is the same as an infinite recursion. d.) Both a and b. e.) All of the above. Answer: a Section: 5-5 53. Level: Moderate Page: 92 The number of times a procedure is called recursively: a.) is always zero. b.) is always one. c.) is at least one or more. d.) depends on the values of the formal arguments passed to the procedure. e.) None of the above. Answer: d Section: 5-5 Level: Hard Page: 92 5-7 Chapter 5 – Graphics and Procedures 54. Infinite recursions: a.) are useful for breaking a problem into simple components. b.) make the program easier to understand. c.) are prevented by checking a parameter against a base case. d.) will prevent the program from malfunctioning. e.) None of the above. Answer: c Section: 5-5 Level: Hard Page: 92 Fill in the Blank Questions 55. The ___Logo___ programming language is the basis for the Visual Logic Graphic system. Level: Moderate Section: 5-1 Page: 80 56. The direction ___north___ is the default drawing direction when the graphic system starts. Level: Easy Section: 5-1 Page: 82 57. The orientation of 180º corresponds to the direction ___south___. Level: Easy Section: 5-1 Page: 80 58. A simple program to draw any equally sided shape can be written with just a ___Loop___, ___Turn Right___, and ___Forward___ statement. Level: Moderate Section: 5-1 Page: 84 59. The ___Set Direction___ graphic command will rotate the drawing direction to a new orientation. Level: Moderate Section: 5-1 Page: 81 60. The ___Set Color___ graphic command lets the programmer change the color the pen draws. Level: Easy Section: 5-2 Page: 85 61. The ___ Color Forward___ graphic command sets the color by rotating through 256 shades each of Blue-Green, Green-Red, and Red-Blue. Level: Easy Section: 5-2 Page: 86 62. The Set Color graphic command allows the programmer to select a color for the pen from the ___color dialog box___. Level: Moderate Section: 5-2 Page: 85 5-8 Chapter 5 – Graphics and Procedures 63. The default for the graphic pen is to draw a ___black___ line with a width of ___1___. Level: Moderate Section: 5-2 Page: 85 64. A set of programming instructions grouped together into a single unit is called a(n) ___procedure___. Level: Easy Section: 5-3 Page: 87 65. The process of breaking a problem into smaller parts is called ___structured design___. Level: Easy Section: 5-3 Page: 87 66. All procedures are found on the command menu under the ___Call Procedures___ menu option. Level: Moderate Section: 5-3 Page: 89 67. Another name for an argument in a procedure is a(n) ___parameter___. Level: Easy Section: 5-4 Page: 90 68. A formal argument is declared when the ___Procedure Edit___ dialog box is open. Level: Moderate Section: 5-4 Page: 91 69. An actual argument is declared when the ___Arguments___ dialog box is open. Level: Moderate Section: 5-4 Page: 92 70. In a procedure with multiple arguments the first actual argument corresponds to the ___first___ formal argument. Level: Easy Section: 5-4 Page: 93 71. The argument inside of the procedure is a(n) ___formal___ argument. Level: Easy Section: 5-4 Page: 93 72. The argument placed in the parenthesis when calling a procedure is a(n) ___actual___ argument. Level: Easy Section: 5-4 Page: 91 73. A procedure that calls itself is called a(n) ___recursive___ procedure. Level: Easy Section: 5-5 Page: 94 74. A recursive procedure that never stops calling itself is a(n) ___infinite recursion___. Level: Moderate Section: 5-5 Page: 94 5-9 Chapter 5 – Graphics and Procedures 75. The ___base case___ test on an argument can prevent infinite recursions. Level: Hard Section: 5-5 Page: 94 Essay Questions 76. Write a Visual Logic algorithm or program to draw a triangle. Begin Forward: 100 Turn Right: 120 Forward: 100 Turn Right: 120 Forward: 100 Turn Right: 120 End 77. Which design process leads to the use of procedures? What are the advantages of using procedures? The goal of the structured design process is to break problems into smaller and smaller parts until a simple, general algorithm can be created to solve each part of the problem. Once this basic building block of an algorithm is created it can be placed in a procedure. The procedure can then be called multiple times as needed with the main program or from other procedures. Using procedures results in code that is easier to read, understand, and maintain. There is only one location for the code that solves a particular problem. If it turns out that the logic in that procedure needs to be fixed or updated, the developer will only have to change the code in that one location instead of multiple locations. Not having duplicate code saves time and decreases the chance that errors are introduced into the code, both during the creation and maintenance phases of software development. 5 - 10