COMP203: Assignment 3
Please include your full name and the assignment number
in your document and submit your document in plain text (.txt) file format through Blackboard's
assignment manager.
- In your own words, explain what a global variable is.
- The procedure bottom on page 50 of the text uses a variable outer
that is not declared as local to the procedure, nor is it an argument (input) of the procedure.
Does the variable outer in procedure bottom violate the prohibition
on page 56 against using global variables? Why or why not?
- Write a procedure perimeter that accepts the length and width of a rectangle as input
and outputs the permiter of the rectangle.
- Read the section on Defining Your Own Predicates on page 64 of the text, then
create a predicate smallp which takes a single number as
input and outputs true if the number is less than 1 and
false if the number is greater than or equal to 1. Test your
procedure with the instruction print smallp 0.
- a) What happens when you print smallp zero? Why? What happens when you
print smallp "zero? Why? (Note: this a question about error
messages, not about predicates. It also serves as an introduction to and motivation
for part b.)
b) Use the primitive procedures numberp and ifelse
to create a new procedure smallnumberp that takes one input and
outputs true if the input is a number less than 1, false if
the output is a number greater than or equal to 1, and which prints a warning
and outputs false if the input is not a number. (If you get stuck
on this problem, take a break and work on the next one.)
- As described in the last two sections of Chapter 4, write a
quiz program that asks three or more questions. When the quiz is completed,
print the score on the quiz. Suggestion: use the local and make
commands to create and modify a variable to save the score.
Bonus: (5 pts) Revise your quiz program to give the user three tries
to answer each question. (Note that the example in the book does not work because stop
ends the entire program, not just the procedure it occurs in.)