This lab is preparation for midterm exam 2, and project 2 .
By the time you finish (lab06) you'll have demonstrated your ability to:
You'll also reinforce the following skills gained in earlier labs
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
intLinkedList.h, a C++ header file (#include file) that defines a struct for a linked list node, and several function prototypes for functions that modify lists built with that structintLinkedList.cc, a C++ source file that provides the function definitions for the functions that were prototyped in the header file intLinkedList.hsearchList.cc, a C++ source file containing a main program that uses the intLinkedList.h/intLinkedList.cc routines to build a list from an external file (nums.dat) and then allows the user to search the list to see whether a given number is in the list or not.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 >
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
searchList.cc to searchList2.ccsearchList2.cc to change the filename, and add your name
// searchList2.cc by Chris Jones, based on searchList.cc by P. ConradMakefile so that it compiles this program as an additional binary (along with searchList).Note that:
searchList.o should be linked together with intLinkedList.o to make the searchList binary, and searchList2.o will also be linked (in a separate linking step) with intLinkedList.o to create the searchList2 binary.There is no need to create a separate intLinkedList2.cc or intLinkedList2.o and you should not do so.
intLinkedList.h/intLinkedList.cc are reusable in many different main programs,drawings.h/drawings.cpp in many different main programs in Project 1. 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.
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.
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
make clean before you create your tar filelab06 directory) lab06 directory containing all your stuff.make clean; make all| 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. |