Professor Simonson  -  How Computers Work   -  CS 195

Assignment 2 -  20 points

Due midnight, Thursday February 7

Email a file called asg2.lgo with all the solutions in it.  Use comments (with ;) to write your group members on the assignment and/or to explain your ideas.

Procedures without Output Values

  1. Write a procedure, octagon :size :pos, which will draw a STOP-sign of a particular :size at a particular position :pos on the screen.  Test your procedure with some examples like “octagon 50 [30 -80]”.

  2.  
  3. Write a procedure, polygon :sides :size, which will draw a polygon with a particular number of :sides and of a particular :size on the screen.  Test your procedure with some examples like “polygon 5  50 “  (Hint: To make an n-sided polygon, you need to turn 360/n each time).

  4.  
  5. Write a procedure, prettyring, which draws a ring of pentagons (5 sided polygons), with sides of length 20, in the center of the screen.  You should use the procedure polygon to help.

Procedures with Output Values

  1. Write a procedure, mini  :item1 :item2 :item3, which outputs the minimum of the 3 items.  (Hint: it can be done with three if statements).  Test your procedure by writing and running the short program below:
  2. To testmini
     print [please type in 3 numbers or names, separated by spaces]
     make "x1 read make "x2 read make "x3 read
     print se [The smallest is] mini :x1 :x2 :x3
    End

     
  3. Write a procedure, sort :item1 :item2 :item3, which outputs a list of the three items in sorted order from smallest to largest. (Hint: it can be done with 6 if statements).  To output more than one value, you will need to group the values together in a list.  This is done with the "se" or "sentence" procedure.  For example op (se 7 8 5) will output [7 8 5].  Test your procedure by writing and running a test program (similar to testmini in problem 3), which read in 3 items and prints them out in sorted order.

  4.  
  5. Write a procedure, average :num1 :num2 :num3, which outputs the average of three different numbers.

  6.  
  7. Write a procedure, process3, which reads in 3 different numbers and prints out the average of the 3 numbers and the minimum of the 3 numbers.  If the numbers are NOT all different, then your program should print a warning message, and stop.  You should use the procedures mini and average.  You also need to write a procedure are_different?  that outputs “true when the three numbers are different and “false otherwise.

 
 
 

back
 


shai@stonehill.edu

http://www.stonehill.edu/compsci/shai.htm