1.7 Review Exercises


Exercise 1.7

  1. What will this program print?
    put "Here we are " ..
    put "finally,"
    put ""
    put "at the end " ..
    put "of" ..
    put ""
    put ""
    put "Chapter 1"
  2. What will this program print?
    put "To give the variable \"doubleQuote\"" ..
    put " the value of a double quote,"
    put "use the following assignment:"
    put "doubleQuote := \"\\\"\"" 
  3. Classify each constant as being int, real, char, string, or illegal. If the constant is illegal, explain.
    1. "5.2e-3"
    2. -0
    3. '''
    4. "A string"
    1. '7'
    2. 37.
    3. .26E1
    4. 63.9E0.5
  4. Write without using E notation.
    1. 1E-3
    2. 6.35E0
    1. 0.007E-2
    2. 73.08E5
  5. State, with reasons, which of the following are illegal Turing identifiers.
    1. velocity
    2. firstValue
    3. 15March
    4. Get
    5. x27
    1. last-value
    2. case
    3. ending
    4. time.at.start
    5. time at end
  6. For each legal constant definition, state the type of the constant. If the definition is illegal, give a reason.
    1. STAR = "*"
    2. const PI = 0.314159e1
    3. const DATE := "October 31"
    1. const leastValue := -10000
    2. const SUM := 2 + 3
    3. const SCALE_FACTOR := -2.0E2.0
  7. Give two different statements that could be used to give a value to the int variable number.
  8. The program shown is full of errors. Copy the program and correct the mistakes.
    Here's a comment
    var a:= integer b:= real c:= char
    const MAX : 50; MIN : 1
    a = 75.6
    put "Here is the integer, a
    put "MAX = " MAX "MIN = " MIN
    b := 7.2
    put "Here is the "real"" b
    c := *
    put "And here's the char", c
    1. Rewrite the following program using the formatting style shown in this text.
      const PI := 3.14159 var first,last:string get first get last put "Hi, mom, it's me ",first,last
      put "Are we having ", PI, " for dessert tonight?" 
    2. What would this program print given input of DAVID SKY?
  9. Write a program that draws a picture of a car.
  10. Draw a red square that is 100 x 100 at the bottom right corner. Draw a green circle that has a radius of 50 and just touches the top left corner of the screen. Draw a blue triangle with a black outline that goes through the following points: (150,150), (150, 250), (300, 200).