COMP203 Problems, Chapter 1


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. What instruction would you type in to Logo to save your work in a file named mywork.txt?

  2. Suppose you had saved work in a file named mywork.txt. How would you load your work back into Logo? (There is more than one correct answer to this question.)

  3. Suppose you found a spelling error in the question in your cooking.quiz procedure. What would you do to correct it? (There is more than one correct answer to this question.)

  4. Run the following commands in Logo:
    repeat 3 [forward 25 right 45]
    repeat 6 [type "#]
    repeat 4 [print "Yo]
    repeat 3 [repeat 5 [forward 20 right 72] forward 50 right 120]
    repeat 3 [repeat 5 [type "ow]]
    
    Describe using complete sentences what the repeat command does.

  5. Use repeat to write a single instruction that causes Logo to produce the result shown below:
    Again!
    Again!
    Again!
    Again!
    Again!
    

  6. Review problem 4. Then edit the instruction from page 3:
    repeat 20 [repeat random 30 [type "Hi] print[]]
    to display one rectangular block of text (two examples shown below).
    ...............            """"""""""
    ...............            """"""""""
    ...............            """"""""""
    ...............            """"""""""
    ...............
    

  7. Explore the instruction remainder using the help command. You should find the expected remainders when an even number is divided by 2 and when an odd number is divided by 2. Explain what remainders are expected in these cases, and illustrate your answer with a few examples in Logo.

  8. Referring to the example on page 7, write a one question quiz in Logo. Check your work by running it.

  9. Write a procedure converse based on the hi procedure on page 5 of the text. The conversation can take any form you like; one possibility is shown below.
    ? converse
    Is this your first year at Bridgewater?
    No.
    Neat!  What's your major?
    Mathematics
    That's my favorite subject!
    ?
    
    Hint: To make Logo pause and wait for an answer, use the command ignore readlist.

  10. Write a procedure (a Logo program) named picture that uses the Logo commands forward, back, right and left to draw a simple design on the screen. Use instructions like help "forward to learn what these commands do.

  11. WITHOUT USING LOGO, draw a picture on graph paper showing what the turtle will draw when given the following instructions. Assume each square of graph paper has side length 10.
    forward 10
    left 90
    forward 10
    left 90
    forward 20
    left 90
    forward 40
    left 90
    forward 40
    right 90
    forward 40
    right 90
    forward 20
    right 90
    forward 10
    right 90
    forward 10
    
    You may check your work using Logo. (The point of this exercise is to practice reading a list of instructions given to the computer. You will need this skill later, so be sure to get good practice now!)

  12. (From a worksheet by Mike Koss.) What do you think will happen when Logo executes the following list of instructions:
    FD 100
    BK 50
    RT 90
    FD 50
    LT 90
    FD 50
    BK 100
    PU
    RT 90
    FD 25
    LT 90
    PD
    FD 50
    PU
    FD 10
    PD
    FD 5
    HT
    
    If you're not sure what a command does, use Logo's help feature! For example, typing help "HT causes Logo to tell you:
    HIDETURTLE
    HT
    
            makes the turtle invisible.  It's a good idea to do this while
            you're in the middle of a complicated drawing, because hiding
            the turtle speeds up the drawing substantially.
    

    You can also get help on instructions from files in the DOCS folder that came with your Logo installation or online at http://www.cs.berkeley.edu/~bh/usermanual.

Challenge problems

  1. Study the instruction on page 3 of the text:
    repeat 20 [repeat random 30 [type "Hi] print[]]
    Write an instruction (a line of Logo code) that generates a random number between 0 and 5. Test your instruction to make sure it works! (When reading the help page for random, be aware that the command only works for single inputs even though the help page suggests using two inputs.)

  2. (a) Give an instruction that uses random to print a random number between 2 and 5 (inclusive).

    (b) Give an instruction that uses random to print a random number between 3 and 6 (inclusive). Explain your answer using complete sentences. (Keep in mind that your answer must be in the spirit of Assignment 1, Problem 5; we cannot use random with two inputs as incorrectly indicated in the manual entry for random.)

    (c) Give an instruction that uses random to print a random number between 3 and 7 (inclusive). Explain your answer using complete sentences. (Keep in mind that your answer must be in the spirit of Assignment 1, Problem 5; we cannot use random with two inputs as incorrectly indicated in the manual entry for random.) Have you deduced a general pattern from (a)--(c)? Can you explain the pattern in words? If you don't see a pattern yet, specify similar ranges, and see if you can write instructions that generate random numbers in those ranges. Eventually you will see a general method.

    (d) DESIGN an ALGORITHM (method) that does what (random num1 num2) is supposed to do: outputs a random integer greater than or equal to the first input, and less than or equal to the second input. Assume both inputs are integers, and the first is less than the second. The object here is to DESIGN a procedure, NOT implement it. This work should be descriptive, showing your full understanding of the objective and the approach with minimal (if any) actual Logo instructions. Verify that your METHOD will perform correctly on the inputs (a) 2 and 5 (b) 3 and 6 (c) 3 and 7 as in the first three parts of this problem respectively.

  3. Use Logo's help command to understand why running the instruction

    repeat 50 [setcursor list random 75 random 20 type "Hi]
    has the result it does. Answer fully in complete sentences.

  4. 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.