COMP203 Problems, Chapter 2


These pages are BSU's "questions at the end of the chapter" for Computer Science Logo Style Volume 1. Homework assignments will consist of subsets of these problems. Some of these problems may appear on the midterm.
  1. Read Chapter 2 of the text. According to the definitions in the book, are all "procedures" also "commands"? Explain your answer.

  2. In your own words, describe what a "complete instruction" is and does. (The book provides a definition. The point of this assignment is to understand that definition -- what are complete instructions good for?)

  3. For each of the following instructions, decide whether the input to the print command is appropriate. If the input is appropriate, describe it (word, list, number, procedure output, variable value, etc.). If not, correct the instruction as best you can.
    1. print "noodles
    2. print Hi
    3. print 7
    4. print sum 3 4
    5. print sentence [Hi Joe.] [How are you?]
    6. print sentence "Worst. "road trip. "ever.
    7. print x+y

  4. Withouth using Logo, determine what the following procedure does. (This problem is typical of no-Logo quiz problems you will do.)
    to writeL
    cleartext
    repeat 10 [print [**]]
    repeat 2 [print [***********]]
    end
    

  5. Write a procedure to draw a letter, similar to the example in the previous problem. Use a different character than in the previous question (not *). Make sure you draw a different letter than the previous problem. DO NOT DRAW WITH THE TURTLE FOR THIS PROBLEM. Print characters to the text screen. For full credit, use repeat whenever possible instead of typing the same instruction multiple times.

    It might be helpful to know how to print multiple spaces. If so, you'll need to use verical bars; experiment with:

    print "|                      |***
    
    print "*|                        |*
    
    (Try leaving a large number of spaces between the vertical bars.)

  6. Following the guidelines at the top of page 21 of Chapter 2, explain how the remainder operation works (p. 16, or "help remainder"). Is your explanation detailed enough to predict the result of entering the instruction print remainder -8 5?

  7. Write a single line of Logo code that uses operations such as quotient, difference, sum and product to evaluate and print:
    (8 * 3) / (6 - 2).

    (Do not use *, - and /.)

  8. The following instruction draws a square:

    repeat 4 [forward 100 right 90]

    Figure out which of the following instructions draws a triangle and explain why the other does not draw a triangle. Use the clearscreen command to clear your screen when you need to.

    repeat 3 [forward 100 right 60]

    repeat 3 [forward 100 right 120]

  9. Use what you learned in the previous problem to write an instruction that draws a hexagon.

  10. What does the instruction print 3 + 6 * 2 do and why? What Logo instruction would find the sum of 3 and 6 first and then multiply by 2? What value does the instruction give? Explain your answer in complete sentences. Explain why parentheses work as grouping symbols but square brackets do not.

  11. What does the instruction

    print (random 10) + 10 do and why? Answer in complete sentences, and explain your answer fully.

  12. Give a instruction that uses random to print a random number between 4 and 12. Explain your answer using complete sentences. (Keep in mind that your answer must be in the spirit of Problem 4; we cannot use random with two inputs as incorrectly indicated in the manual entry for random.)

  13. Consider the following instructions:

    What do the instructions do and why? Answer in complete sentences and explain your answers fully. Include comparisons among the different instructions in the list.

  14. Write two different Logo instructions to print the product 5 times 3. Which instruction do you prefer to use? Why might someone else prefer the other instruction?

  15. Write a procedure to draw a triangle using the turtle. For full credit, use repeat whenever possible instead of typing the same instruction multiple times.

  16. A classmate wrote the following procedure, which draws a nice design. If you use the hideturtle (ht) instruction you can see that the design is an open triangle. (If you want to see the turtle again use showturtle (st).) Use the Pythagorean theorem to revise the code to close up the triangle as precisely as possible. Use the sqrt instruction.
    to drawtriangle
    forward 100
    right 90
    forward 100
    right 135
    forward 125
    end
    

  17. Draw a plumbing diagram for the instruction:
    setcursor list random 75 random 20

  18. Use the help command to find out what the command penup does. Describe it completely, following the guidelines presented on page 21.

  19. Use the help command to find out what the operation pos does. Describe it completely, following the guidelines presented on page 21.
Challenge problems

  1. Draw a plumbing diagram for the instruction:
    repeat 3 [forward 80 right 120]

  2. Write a three problem quiz procedure as described on page 7.

  3. What question would use to test students on ideas in this chapter? Give a sample solution. If you would like your name associated with it if it is used as a homework or exam question, please say so.