CSC 101 Lecture Notes Week 8
CSC 101 Lecture Notes Week 8
More on the Art and Science of Program Design
-
Quiz Alert
-
There's a 20-minute quiz at the end of lecture this Wednesday.
-
It will cover the basics of arrays.
-
It is open-book, open-note.
-
Reading
-
Chapter 4, pp. 445 - 448.
-
Chapter 7, pp. 352 - 358.
-
Solutions to program4.
-
Attached are three solutions to programming assignment 4:
-
program4-basic -- the basic solution, as expected to be turned in.
-
program4-arrays -- the basic solution, modified to used arrays.
-
program4.h, program4.cpp, program4-main.cpp, program4-test-open.cpp -- the array solution, updated per the design topics discussed in these notes
-
The nature of program comments.
-
The top-level comment for a program describes what the program does
from the end user's perspective.
-
In a multi-file program, the top-level comment goes at the top of the file
containing the main function for the program.
-
Note how the top-level comment for the basic solution does not differ from the
comment for the array-based solution, except for the NOTE at the end of the
array solution description.
-
That is, if the implementation of a program changes, but the specification does
not, then the top-level description of the program does not change.
-
The program comment for each function declaration describes what the
function does from the programmer's perspective.
-
These comments go above each function declaration.
-
The prose description explains in English what the function does, including
mention of all inputs and outputs.
-
The Precondition and Postcondition define more precisely what the function
does, in pseudo Boolean logic.
-
More on preconditions and postconditions below.
-
The inline variable and code comments.
-
These comments go within the body of each function definition.
-
They describe how the program works.
-
Separating a program into .h and .cpp files.
-
A well-engineered C++ program is comprised of multiple-files.
-
The .h file(s) contain(s) function declarations.
-
For each .h file there is a companion .cpp file that contains
the function definitions.
-
There is one .cpp file containing the main function for the
complete program.
-
There are one or more testing files, containing a main function that
tests one or more functions, but does not implement the entire program.
-
Modular program testing with drivers and stubs.
-
A driver is a function that calls one or more other functions for
testing purposes.
-
For example, the functions in program4-test-open.cpp are drivers that
test the OpenGradeFile function.
-
A driver supplies inputs and validates outputs for the functions it tests.
-
A stub is a function that is simply a shell for a function that is yet
to be implemented.
-
Typically, a stub function has a body that just does a cout message
indicating that it has been called.
-
Stub functions are useful for incremental development.
-
Function preconditions and postconditions.
-
A function precondition is a logical (i.e., Boolean) expression that defines
what conditions must be true before a function begins execution.
-
A postcondition is a logical expression that defines what conditions are true
after a function has completed execution.
-
The file program4.h illustrates the use of preconditions and
postconditions.
index
|
lectures
|
labs
|
handouts
|
assignments
|
solutions
|
grades
|
help