Describe the five program structure/flow
abstractions mentioned in the text.
- Fill in the blank:
- "Computers are t________s, and computing scientists are t___________s."
- A procedure that returns a value is called a ____________ procedure.
- Before using the value of a variable for the first time in a program,
we need to ________________ and ___________________ it.
- True or False (circle one): The word FUNCTION is a legal identifier.
- The three loop structures in Modula-2 are
_______________, _______________, and ______________.
- A new type made from a sequence of consecutive values of an
existing type is called a ________________ of the host type.
- What English part of speech should a variable generally be? ___________
- The ______ function is used to determine how far a
real/integer is from zero.
- The function that evaluates natural logarithms on real numbers is found
in the _______________ standard library.
- Redirection of the standard input/output channels is handled by the
- A procedure that invokes itself is called a _________________ procedure.
Explain all the differences between the following, and give examples of each:
- reserved words:
- standard identifiers:
- standard library items:
Write a complete declaration for each of the following data types:
- A string type:
- An enumeration type representing the months of the year:
- A type holding one string for each month of the year:
- A type for only the uppercase letters:
- A type for an m by n matrix of booleans:
Evaluate each of the following expressions,
or if it produces an error, describe the error.
Assume all necessary IMPORTs have been done.
Assume the following declaration and initialization:
myApple : ARRAY [0..5] OF CHAR;
myApple := "granny smith";
- 11 REM 0
- 12.2 MOD 5
- WriteFixed (23.468, 4, 8); (show output, including any spaces)
- (LENGTH(myApple) > 0) AND (CAP(myApple) = 'G')
- Strings.Compare (myApple, "Granny Smith")
- 'C' > 'A'
- 'C' - 'A'
- ORD ('C') - ORD ('A')
- 'C' + 'A'
- ORD (March) (using the enumeration type you defined above)
Show the results (output and/or errors) both with and without the VAR in the
formal parameter list and explain.
FROM SWholeIO IMPORT
PROCEDURE Swap (VAR a, b: CARDINAL);
tmp : CARDINAL;
tmp := a;
a := b;
b := tmp;
a, b: CARDINAL;
a := 2;
b := 5;
Swap (a, b);
WriteCard (a, 0);
WriteCard (b, 0);
Consider the following procedure:
PROCEDURE SumPlus1 (VAR a, b: CARDINAL): CARDINAL;
(* returns a+b+1 *)
RETURN a + b;
Assume there is a global variable x := 5. If we invoke
SumPlus1 (x, x), we might expect the result to be 11,
but it is not. What is returned instead, and why? How would you fix this?