CSC 101 Lecture Notes Week 9
CSC 101 Lecture Notes Week 9
Programming Conventions, Volume 2;
Some Additional C++ Features;
Advanced Debugging Techniques
-
Conventions, Volume 2 -- see the handout
-
Details of preconditions and postconditions
-
The new listing for program4 contains detailed examples.
-
Preconditions and postconditions are fundamentally boolean
expressions.
-
Except for the special cases described below, the syntax of preconditions and
postconditions follows the normal rules for boolean expression composition
-
They use the normal C++ logical (&&, ||, !) and
relational operators (==, !=, <, <=,
>, >=).
-
The following are exceptions to the normal rules of boolean expressions:
-
The keyword then is added to make an if-then-else expression
more readable.
-
The keyword return is used as a variable name instead of a control
construct, as in return == a + b.
-
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.
-
Where necessary, pure boolean expressions can be augmented with English phrases
that describe boolean values rather than express them formally using variables.
-
It is important to remember that preconditions and postconditions are strictly
boolean expressions, not normal program code.
-
All that needs to be said in the conditions is what is true before and after
the function runs.
-
The then and else clauses in a condition if-then-
else are always boolean values.
-
The body of a condition for loop is always a boolean expression.
-
Program debugging techniques
-
The basic programming technique we have used so far in 101 is the introduction
of extra cout statements to help track down program errors.
-
A more advanced technique is to use a symbolic debugger.
-
A symbolic debugger allows the programmer to analyze a program while it is
running.
-
The debugger provides commands to control program execution dynamically and
print out the values of program variables.
-
We will discuss details of using a debugger in
this week's lab notes.
index
|
lectures
|
labs
|
handouts
|
assignments
|
solutions
|
grades
|
help