(Not for handing in)
In software development, we
need to debug our programs. This can be a challenging process: we may find
our program's logic is most mysterious to us, even though we designed and
wrote it. To dig into the mystery, we invoke the debugger, gdb.
For this lab,
you are to make a directory for practicing stuff. If in your
top directory ('cd' gets you there) you could enter 'mkdir practice'
and hit return. Then
cd practice
cp ~gpruesse/Public/160/setWithBug.cpp .
g++ -g setWithBug -o set -Wall -Wextra
The program is supposed to operate like a (initially empty) set of integers,
which
the user can insert an integer into, query whether a given integer is there,
remove an integer; and the user can ask that the contents of the set be listed.
Even though it is compiled with the debugger, you can just run set
the normal way -- go ahead and try it.
There is a problem, though -- integers don't seem to `stick'. Try
init, then insert two integers and then list the contents. Does it work
as planned? If not, try to figure out be code inspection or by using debug
what is going wrong.
To invoke the debugger (if you have compiled it with the -g flag), type this:
gdb ./set
Recall the commands of gdb:
quit
run
backtrace (if program crashes)
break theLineNumber
step or s
next or n
continue or c
print or p
See Dave's slides on gdb for more information on gdb.
Part 2: If you have finished Part 1, try implementing a "maxInArray" function. Have your "main" pass an array as a parameter, and "maxInArray" finds the maximum integer in the array passed in. You can implement it using iteration, or recursion.