6.3 Solutions

  1. (a) There are only 2 arguments. There should be 3
    (c) The second argument should be an int, not a real
    (d) The third argument should be a boolean, not a string
    (e) All the arguments are the wrong types
  2.  
    5 7
    5 6 8
    5 6
    6 7 9
    5 7
  3. % 4a) Why might length be a bad name for the parameter?
    procedure putArea(length, width : real)
       put "The area of the rectangle is ", round(length * width)
    end putArea
    
    % 4b)
    var l, w : real
    
    put "Enter the length"
    get l
    put "Enter the width"
    get w
    putArea(l, w)
    
    
    
  4. procedure putRow(c : char, n : int)
       for i : 1 .. n
          put c..
       end for
    end putRow
    
    
    
  5. const WIDTH := 80
    
    procedure putRow(c : char, n : int)
       for i : 1 .. n
          put c..
       end for
    end putRow
       
    procedure putTriangle(rows : int, symbol : char)
       for i : 1 .. rows
          put " ":WIDTH div 2 - i..
          putRow(symbol, 1 + 2*(i - 1))
          put ""
       end for
    end putTriangle
    
    put "A small triangle of stars"
    putTriangle(3, '*')
    put ""
    put "A large triangle of plus signs"
    putTriangle(10, '+')
    put ""
    put "A very small triangle of dots"
    putTriangle(1, '.')
    put "" 
  6. procedure range (list: array 1 .. * of int)
       var least, greatest : int
       
       least := list(1)
       greatest := list(1)
       for i : 1 .. upper(list)
          if list(i) < least then
             least := list(i)
          end if
          if list(i) > greatest then
             greatest := list(i)
          end if
       end for
       put "The least value is ", least, " and the greatest is ", greatest
    end range