CSC 101 Lecture Notes Week 9

CSC 101 Lecture Notes Week 9
Programming Conventions, Volume 2;
Some Additional C++ Features;
Advanced Debugging Techniques


  1. Conventions, Volume 2 -- see the handout

  2. Details of preconditions and postconditions
    1. The new listing for program4 contains detailed examples.
    2. Preconditions and postconditions are fundamentally boolean expressions.
      1. Except for the special cases described below, the syntax of preconditions and postconditions follows the normal rules for boolean expression composition
      2. They use the normal C++ logical (&&, ||, !) and relational operators (==, !=, <, <=, >, >=).
    3. The following are exceptions to the normal rules of boolean expressions:
      1. The keyword then is added to make an if-then-else expression more readable.
      2. The keyword return is used as a variable name instead of a control construct, as in return == a + b.
      3. The special keyword @entry is used (when necessary) as a reference parameter suffix, to distinguish the value of the reference parameter at entry to the function from its value at exit.
      4. Where necessary, pure boolean expressions can be augmented with English phrases that describe boolean values rather than express them formally using variables.
    4. It is important to remember that preconditions and postconditions are strictly boolean expressions, not normal program code.
      1. All that needs to be said in the conditions is what is true before and after the function runs.
      2. The then and else clauses in a condition if-then- else are always boolean values.
      3. The body of a condition for loop is always a boolean expression.

  3. Program debugging techniques
    1. The basic programming technique we have used so far in 101 is the introduction of extra cout statements to help track down program errors.
    2. A more advanced technique is to use a symbolic debugger.
      1. A symbolic debugger allows the programmer to analyze a program while it is running.
      2. The debugger provides commands to control program execution dynamically and print out the values of program variables.
    3. We will discuss details of using a debugger in this week's lab notes.


index | lectures | labs | handouts | assignments | solutions | grades | help