5.4 Solutions

  1.  
    var input : string
    var mark : int
    loop
        loop
            put "Please enter a mark"
            get input : *
            exit when strintok (input)
            put "Please enter a valid integer"
        end loop
        mark := strint (input)
        exit when mark > -1 and mark < 101
        put "Stay in range 0 - 100"
    end loop 
    1.  Since b is used to index the array, if it is not in the range 1 - 5 it will crash the program. If the input for either b or c is not an integer it will crash the program.
    2.  
      var a : array 1 .. 5 of int := init(1, 2, 3, 4, 5)
      var b, c : int
      
      loop
          put "Which element do you want to change?"
          get b
          exit when b >= 1 and b <= 5
          put "The index must be in the range 1 - 5"
      end loop
      put "What value do you want to change it to?"
      get c
      a(b) := c 
    3.  
      var a : array 1 .. 5 of int := init(1, 2, 3, 4, 5)
      var b, c : int
      var input : string
      
      loop
          loop
              put "Which element do you want to change?"
              get input : *
              exit when strintok (input)
              put "Please enter a valid integer"
          end loop
          b := strint (input)
          exit when b >= 1 and b <= 5
          put "Stay in range 1 - 5"
      end loop
      
      loop
          put "What value do you want to change it to?"
          get input : *
          exit when strintok (input)
          put "Please enter a valid integer"
      end loop
      c := strint (input)
      a(b) := c 
  2. There are many examples. As computers are being embedded in more devices, the potential for problems increases. The consequences of software bugs can become life threatening, when they control things like airplanes and medical equipment.