CSC 101 Lecture Notes Week 8

CSC 101 Lecture Notes Week 8
More on the Art and Science of Program Design


  1. Quiz Alert
    1. There's a 20-minute quiz at the end of lecture this Wednesday.
    2. It will cover the basics of arrays.
    3. It is open-book, open-note.

  2. Reading
    1. Chapter 4, pp. 445 - 448.
    2. Chapter 7, pp. 352 - 358.

  3. Solutions to program4.
    1. Attached are three solutions to programming assignment 4:
      1. program4-basic -- the basic solution, as expected to be turned in.
      2. program4-arrays -- the basic solution, modified to used arrays.
      3. program4.h, program4.cpp, program4-main.cpp, program4-test-open.cpp -- the array solution, updated per the design topics discussed in these notes

  4. The nature of program comments.
    1. The top-level comment for a program describes what the program does from the end user's perspective.
      1. In a multi-file program, the top-level comment goes at the top of the file containing the main function for the program.
      2. 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.
      3. 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.
    2. The program comment for each function declaration describes what the function does from the programmer's perspective.
      1. These comments go above each function declaration.
      2. The prose description explains in English what the function does, including mention of all inputs and outputs.
      3. The Precondition and Postcondition define more precisely what the function does, in pseudo Boolean logic.
      4. More on preconditions and postconditions below.
    3. The inline variable and code comments.
      1. These comments go within the body of each function definition.
      2. They describe how the program works.

  5. Separating a program into .h and .cpp files.
    1. A well-engineered C++ program is comprised of multiple-files.
    2. The .h file(s) contain(s) function declarations.
    3. For each .h file there is a companion .cpp file that contains the function definitions.
    4. There is one .cpp file containing the main function for the complete program.
    5. There are one or more testing files, containing a main function that tests one or more functions, but does not implement the entire program.

  6. Modular program testing with drivers and stubs.
    1. A driver is a function that calls one or more other functions for testing purposes.
      1. For example, the functions in program4-test-open.cpp are drivers that test the OpenGradeFile function.
      2. A driver supplies inputs and validates outputs for the functions it tests.
    2. A stub is a function that is simply a shell for a function that is yet to be implemented.
      1. Typically, a stub function has a body that just does a cout message indicating that it has been called.
      2. Stub functions are useful for incremental development.

  7. Function preconditions and postconditions.
    1. A function precondition is a logical (i.e., Boolean) expression that defines what conditions must be true before a function begins execution.
    2. A postcondition is a logical expression that defines what conditions are true after a function has completed execution.
    3. The file program4.h illustrates the use of preconditions and postconditions.


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