This assignment is due at 9 PM on Wednesday, October 4th, 2000. The assignment is a written one, and must be submitted as a single file, a README. Refer to the homework policies page for general homework guidelines.
This assignment has only one purpose, which is to familiarize you with interactive debuggers.
The program assign_05 is a simple file shuffler.  It
reads lines from a file (provided on the standard input device,
cin), shuffles them into a random order, and writes them
to its standard output, cout.  Although it is quite
simple, the program can be used to perform relatively complex tasks.
For example, the class summary
schedule was produced by running the CS70 class roster through a
C version of the same program.  A random line can be chosen from a file such
as /etc/passwd with the command:
    ./assign_05 < /etc/passwd | head -1
To the best of my knowledge, the program is free of bugs. However, for instructional reasons it is much less efficient than it could be.
For this assignment, you will run the program under an interactive debugger and follow a list of steps. Most steps will require you to record the answer to a question. The final result will be submitted as a README file. Other than a file header (name, date, etc.), the README should not have "documentation" components such as the program purpose or input format. Please number your answers corresponding to the step in which the question is asked, leaving gaps if a step asks no question.
The assignment is written for use with the interactive debugger
ddd on Turing.
It is not possible to do the assignment with a different debugger,
primarily because minor debugger variations make grading impossible.
Also, it is probably not possible to do the assignment by using a
Windows machine to connect to Turing, because ddd expects that you
will be connecting from an X-compatible display, and to the best of my
knowledge Windows machines can't do that securely.
The program for the assignment is implemented using 4 files: a Makefile, a main program (assign_05.cc), and a header file (line.hh) and implementation (line.cc) for a pair of classes that support some simple operations on text lines. There is also a sample input file (hw5-input.txt). As usual, you can download all of the files as a gzipped tar file or a zip archive.
make.
    echo $EDITOR".  If the response is the name of
	some other editor, fix it by typing "setenv EDITOR
	vi", "setenv EDITOR pico", or whatever is
	appropriate to your taste.
    ddd debugger
	from the command line by typing ddd assign_05.
    Run... from the Program
	menu.  Specify
	hw5-input.txt in response to the prompt for
	arguments.  You will see 16 words scroll by in
	the window at the bottom of the screen.  Question:
	In order, what are
	they?  (You may use cut-and-paste, and you don't have to list
	them one per line).
    File/Open Source... to bring up a list of
	the source files involved in the program.  Most of them are
	system files that aren't of interest to us, so find
	line.cc and open it.
    LineGetter::getLine.  Select the full name
	(including the scope qualifier) and click on the stop sign
	labeled "Break" to set a breakpoint.  Run the program again,
	this time giving the arguments "-s 0 hw5-input.txt".
	Question: What happens?
    Next button in the pop-up toolbar to step through
	the program until you reach the first "else if" statement.
	Rest the mouse on the string "nextCharacter".
	Question: What happens?
    nextCharacter.  Then click
	Display on the main toolbar.  Click
	Next repeatedly until nextCharacter changes.
	Question: What is it?
    line =
	expand...".  Click at the start of the line, and set a
	breakpoint.  Hit the Cont (continue) button.
	Question: Where does the program stop?
    assign_05.cc".  Press Cont
	repeatedly until you reach the breakpoint at the
	expand call.  Question: How many
	times did you hit
	Cont?
    Run button to run again.  This
	time, type "continue 2" on your keyboard (the
	characters will appear in the small gdb window at
	the bottom).  Question: Where does the program stop?
    Source/Breakpoints... to disable breakpoint
	#1 and run the program yet again.  Question:
	What is the value of nextCharacter?
    length?
    Step button.  Question:
	Where are we?
    line.  Question: What is its
	hexadecimal value?
    Next button.  Question:
	Where are we?
    line represents the address at
	which that array of characters is stored.
	Question: Where is
	line stored?
    Source/Breakpoints to delete breakpoint 2
	and enable breakpoint 1.  Hit the Finish button.
	Question: Where are we?
    Up button.
	Question: Where are we?
    whereToPutIt.  Select the
	... inside the curly braces, and choose
	Show/Show All.  Question: What is
	the value of _M_start?
    Undispl to un-display what you just saw.
	Select _M_start with a single click, then click
	and hold on Display to pick the get a pop-down
	menu.  Choose Other....  Put an asterisk at the
	front of the expression, and "@5" at the end,
	and then display.  Scroll to the right.
	Question: What do you see?
    Show.  Question: Where
	are the 5 contents variables stored?
    getLine.
	Type next 4 to get to the while loop
	quickly; this makes length a valid variable.
	Click to select length, and then click
	Watch to set a watchpoint that will stop
	the program whenever length changes.
	(Warning: this can make your program run very slowly.)
	Finally,
	hit Cont.  Question: Where does
	the program stop?
    length?
    length, and then click
	Watch to delete the watchpoint.  (This also works
	with breakpoints.)  Also delete the breakpoint at the
	beginning of getLine.  Scroll down to find any
	constructor for Line, and select the
	text Line::Line (without any parentheses).  Click
	the Break button.  Choose the all
	option in the dialog box.  Continue the program.
	Question: Where does it stop?
    Status/Backtrace... to see who called
	whom.  Question: Who called the function that
	called us?
    Kill button to kill the current
	program.  Make sure you are displaying
	assign_05.cc, and hit the Edit
	button to bring up your favorite editor.  Find the call to
	drand48 at the very end of the file (inside the
	randomize function), and change it to read:
        unsigned int j = (unsigned int) lrand48();
	Exit your editor and hit the Make button in
	ddd to recompile the program.  Use
	Source/Breakpoints to delete the remaining
	breakpoint, and run the program again with the arguments
	"-s 0 hw5-input.txt".  Question:
	What happens, and where?
    source> in the line that
	refers to source.lineNumber.
	Question: What does the status line say?
    lineNumber on the left of
	the assignment statement.  Question: What
	does the popup say?
    j?
    j and choose Display/Convert to
	Hex.  Question: What is the value in hex?
    
        unsigned int j = (unsigned int) (drand48() * array.size());
	Recompile the program, and run it one last time with the
	arguments "-d -n -s 1 hw5-input.txt".
	Question: What are the
	17 lines that are printed?
The only file you need to submit for this assignment is the README.
Please use cs70submit to submit it, rather than
cs70submitall, so that only the README will get picked
up.  If you use cs70submitall, you will merely clutter up
the grader directories.
Don't forget to spell-check your file.
In a couple of places, assign_05.cc deliberately uses a
very inefficient implementation for illustrative purposes.  If you
ever expect to use it in the future, you should change randomize
accepts the array argument by reference, and returns
void.  Don't worry if you don't know how to do that right
now; we'll cover references in class soon.
This page maintained by Geoff Kuenning.