Think like a programmer

[or better: think like a cook!]

Write pseudocode for each of the problems

  1. You have an egg (in shell), salt, a pan, and butter; produce a scrambled egg.

  2. what is the pseudo code for printing hello world 2 times

  3. Calculate and print the result of Square root of one over x squared for all x smaller than 5.

  4. Imagine a square consisting out of 3x3 tiles, what is the pseudocode to visit all four corner tiles, using pseudo commands moveforward(), turnleft(); you start (S) in the center

    X X
    S
    X X
  5. Same exercise as before but the square has now 301x301 tiles, write pseudocode that uses loops.

  6. Write code that takes the last 3x3 example but think of the corner tiles as lighted up (X), your job is to turn them off using the function toggleLight() once you are on the corner tile, once you turned off all corner lights go back to the middle and turn the light on (take a hint from the function name). The final result looks like this:

    0 0
    X
    0 0
  7. Do a similar pseudocode, but write a function for the subset of the tasks (e.g. change_corner lights()) for this layout (you do not need to go back to the center):

    X X X X
    X X
    S
    X X
    X X X X
  8. Rewrite your pseudocode assuming you have only the functions turnOn() and turnOff() (Hint: test whether the light (X) is on (present) or not (absent) before you turnOff or turnOn.

  9. write pseudocode for a program that takes a simple calculation like 4 + 5 or 3 / 4 or 24 * 3 or 10 - 2 and spits out the result.

Translate pseudo code into real code

If you have time, translate all the pseudocode into real code. Start with the first (easy) ones.










(Peter Beerli, ISC3313, September 2016)