Recall

ZIMSEC O-Level Computer Science (4021)

Programming: notes

AI-written, not yet teacher-reviewed

Not affiliated with or endorsed by ZIMSEC

Key ideas

  • A program is a set of instructions written in a programming language.
  • High-level languages (Python, Visual Basic, Java) are close to English and easy to read. Low-level languages (machine code, assembly) are close to what the CPU understands.
  • A compiler translates the whole program into machine code before it runs. An interpreter translates and runs one line at a time.

Building blocks

  • Variable: a named store whose value can change. Constant: a named value that does not change while the program runs.
  • Data types: integer (whole number), real (decimal number), string (text), Boolean (true or false), character.
  • Operators: arithmetic (+ - * /), comparison (= < > <= >=), logical (AND, OR, NOT).
  • Arrays: one name holding many values of the same type, reached by an index.

Functions and procedures

  • A procedure is a named block of code that does a task.
  • A function is like a procedure but returns a value.
  • Both make code shorter, easier to test, and reusable. Values passed in are parameters.

Interface design and visual programming

  • A good interface is clear, consistent, and gives helpful messages.
  • Visual programming builds programs by placing objects (buttons, text boxes) on a form and writing code for their events, such as a button click.

Errors

  • Syntax error: breaks the language rules, such as a missing bracket. The translator finds it.
  • Logic error: the program runs but gives the wrong answer, such as using < instead of >.
  • Runtime error: the program crashes while running, such as dividing by zero.

Testing and debugging

Test with normal, extreme and erroneous data. Debugging is finding and fixing errors, using breakpoints, stepping through code and watching variables.

Gotcha: a logic error does not stop the program from running, which makes it the hardest kind to spot.

Built by Allan Simoyi · X · GitHub · How it's built