CISC181 lab06, Spring 2007

Introduction

This lab introduces basic linked lists of ints, using structs

This lab is preparation for midterm exam 2, and project 2 .

Learning objectives

By the time you finish (lab06) you'll have demonstrated your ability to:

  1. Understand code involving linked lists
  2. Write code to add items to the beginning of a linked list

You'll also reinforce the following skills gained in earlier labs

  1. Modifying an existing Makefile to add new files
  2. Create a tar file to submit multiple files as a single file

Step-by-Step Instructions

Step 1: Read and understand the code in the lab06 directory

In the lab06 directory, there is a Makefile that compiles a program called searchList.

This program consists of three C++ source files, and one Makefile

Here is a sample run of this program. I do a cat on the nums.dat first, so that you can see what numbers are in the file. I've also enabled DEBUG output in the Makefile so that you can see that the linked list matches the numbers in the file.

 

> cd lab06
> ls
Makefile  intLinkedList.cc  intLinkedList.h  nums.dat  searchList.cc
> make
CC -DDEBUG -c searchList.cc
CC -DDEBUG -c intLinkedList.cc
CC -DDEBUG searchList.o intLinkedList.o -o searchList
> cat nums.dat 
4
76
2
867
3
> ./searchList
DEBUG: Here's the list: 4 76 2 867 3 
At each prompt, enter a number to search for, or q to quit,
 and the program will tell you whether
 that number is in the list 

number (or q to quit): 1
1 is not in the list
number (or q to quit): 2
2 is in the list
number (or q to quit): 3
3 is in the list
number (or q to quit): 4
4 is in the list
number (or q to quit): 5
5 is not in the list
number (or q to quit): 867
867 is in the list
number (or q to quit): 768
768 is not in the list
number (or q to quit): g
0 is not in the list
number (or q to quit): foo
0 is not in the list
number (or q to quit): q
> 

 

Step 2: Add a new file, searchList2.cc, and modify the Makefile accordingly.

Add a new file to the directory, called searchList2.cc.

At first, this will be a simple copy of the program searchList.cc.In this step all you need to do is

Note that:

There is no need to create a separate intLinkedList2.cc or intLinkedList2.o and you should not do so.

Once you have a Makefile that creates two executables, searchList, and searchList2, and they both are identical (except for the file header comment,) you are finished with Step 2—go on to Step 3.

Step 3: Modify searchList2.cc

In searchList2.cc, change the line that says:

addIntsFromFileToEndOfLinkedList(head, tail, infile);

to this:

addEachIntFromFileToStartOfLinkedList(head, tail, infile);

Then try to compile the program. At first, you'll get an error like this:

> make
CC -DDEBUG -c searchList2.cc
"searchList2.cc", line 39: Error: The function "addEachIntFromFileToStartOfLinkedList" must have a prototype.
1 Error(s) detected.
*** Error code 1
make: Fatal error: Command failed for target `searchList2.o'
> 

Modify intLinkedList.h to add the necessary function prototype. As you make the modification, change the header comment to now indicate that the file is a collaboration—it contains some code by P. Conrad's code, and some code by you.

That will fix the compiling error, but then you'll get a linking error:

> make
CC -DDEBUG -c searchList.cc
CC -DDEBUG -c intLinkedList.cc
CC -DDEBUG searchList.o intLinkedList.o -o searchList
CC -DDEBUG -c searchList2.cc
CC -DDEBUG searchList2.o intLinkedList.o -o searchList2
Undefined                       first referenced
 symbol                             in file
void addEachIntFromFileToStartOfLinkedList(Node_S*&,Node_S*&,std::ifstream &) searchList2.o
ld: fatal: Symbol referencing errors. No output written to searchList2
*** Error code 1
make: Fatal error: Command failed for target `searchList2'
> 

So, add the function definition into intLinkedList.cc.

This will require you to think about the proper way to add to the beginning of a linked list. Your lecture notes may help!

As with intLinkedList.h, as you modify intLinkedList.cc, change the header comment to now indicate that the file is a collaboration—it contains some code by P. Conrad's code, and some code by you.

Step 4: Creating a tar file of your finished product.

Don't start this step until you have finished all your programming, and are ready to submit your work.

Follow the directions from lab05, step 7 to create a file called lab06.tar.

Follow the guidelines from lab05, step 7, including

Finishing up and Submitting

  1. Make a script called lab06.txt. In your script, you should
  2. Then, submit your lab06.txt and your lab06.tar file to WebCT.
  3. If your TA typically requests paper output, print your lab06.txt file and give it to your TA.

Grading: 100 points total

Points What/Where Issues
20 Correctly modifying the Makefile Both programs link against the same intLinkedList.o file
10 Correct header comments on files you modified Both P. Conrad's name and your name should be listed, and the filenames should be correct
10 Correctness of modifications to searchList2.cc New function call
10 Correctness of modifications to intLinkedList.h New function prototype
30 Correctness of modifications to intLinkedList.cc New function definition.
10 style style issues throughout all code (.cc, .h files and in the Makefile) in the code
that is the part YOU modified.
10 following instructions completing all steps per instructions on this web page and general course policies.

End of lab06