122 lab week 6


What You Will Do In Your Lab

Debugging with scaffolding ( scaffolding )

Goals

By lab's end, you should understand how to insert scaffolding in a program for run-time debugging.

  1. Open debug.cpp from

    Copy and paste the code into an Emacs buffer, save it as debug.cpp, and compile it. Suspend emacs and then run it on the salary inputs 10, 7, 15, and 0.

    The correct salary range should be 8000 (i.e., 15000 - 7000), but it reports 15000 instead.

  2. TRACK DOWN THE BUG WITH "SCAFFOLDING"

    Temporary cout statements ("scaffolding") allow us to display relevant information at runtime. This information can be used to deduce what the logic error is, and where it is.

    Insert this statement

    cout << "debug 1: salary = " << salary << endl;

    after the initial input statement in the loop to echo the data values.

    Insert this statement at the botom of the loop:

    cout << "debug 2: maxSalary = "
    << maxSalary << " minSalary = "
    << minSalary << endl;

  3. Recompile and run the program on the same inputs. The output will show that execution is proceeding correctly until the final iteration. Determine an appropriate fix, and implement it.

  4. FOR FURTHER DEBUGGING PRACTICE

    Perfect-driver-3.cpp has a fairly subtle bug. Debug by inserting scaffolding-- it may be on the final quiz.

NOTES

  • Using temporary couts to display RELEVANT information is key: displaying every value in the program can make it harder to find an error.
  • SCAFFOLDING IN FUNCTIONS. In programs with multiple functions, scaffolding can be placed just inside the function to display passed values, and to help determine whether control made it to that point in the program or not.
  • Becoming skilled at using scaffolding is an invaluable technique.
  • Please insert scaffolding in your programs before coming to office hours for help. Many times you will save yourself the trip.