Name: ______________ CSCI 201 -- Introduction to Algorithm Design This is a closed book exam. This exam MUST be turned in at 8:30 pm. Each of the ten questions on this page counts three points. What is a reserved word? Give examples of two reserved words from Pascal. What are Pascal's four primitive types? Which of the following are valid Pascal integers? (Circle your choices.) 1 3.00 -5 5,280 Which of the following are valid Pascal reals? (Circle your choices.) 1. 3.0 22.0E5 22E5.0 Convert the following into Pascal decimal notation: 1E6 15E-2 List Pascal's boolean values. What is written to the terminal by the following statement: WRITELN(OUTPUT, 3.1416 : 4:2); What Pascal statement would you use to write: It's a fine day for an exam to the terminal? Which of the following are legal Pascal variable names? (Circle your choices.) R2D2 MAX REAL 1X200 What is Pascal's null statement? Name: ______________ The precedence of Pascal's operators are listed in the following table: NOT - (unary minus) AND * / DIV MOD OR + - (binary subtraction) < > <= >= = <> [ 9 Points] When several operators are at the same precedence level they are evaluated left-to-right. What is the result of evaluating the following expressions? 5*6 DIV (2+1) - 3 (7+ 3=8) AND (7.5 < 8.5 * 2) (6+3 * 5 < 16) OR TRUE <= FALSE [3 points] Write a Pascal expression that uses both forms (minus and subtraction) of the - operator. [6 points] What is the type and value of the following expressions: 17 MOD 3 17.0 DIV 3 10 / 2 [12 points] Given the following constant definitions and variable declarations: CONST TaxRate := 0.5; Year := 1990; VAR Tax, Money : REAL; I, J: INTEGER ; Letter : CHAR; Rich : BOOLEAN; which of the following are valid Pascal assignment statements: Rich := Letter < 'X' ; Tax := TaxRate * (Year - Money) ; Tax := TaxRate * I ; I := Rich ; Name: ______________ [12 points] Suppose C is a character variable and I is an integer variable. What is the result of executing the following statements: READLN(INPUT, C); READ(INPUT, I); with the following four input sequences: (a) x 15 (b) y17 85 (c) 112 8 (d) y 17x [8 points] Describe a method that could be used to replace any Pascal CASE statement with an equivalent statement using IF-THEN-ELSE's. Name: ______________ [20 points] Using Pascal's three different iteration constructs, the DO-WHILE, the REPEAT-UNTIL, and FOR loop, write three different program segments to compute the result of multiplying the number 3 by itself N times, where N is an integer variable.