Overview

This lab returns to the books we used way back after learning loops. You now know about lists, so we can "read" books and actually count the words used in them! We don't need to know in advance how many unique words exist due to the power of lists.
You will need to download the tarball of books.

Part 1: Super-simple linked list [part1.cpp all in one file!]

Your Part 1 program will read in strings from a file (e.g., a book) and print them in reverse order (which happens naturally if you use our good friend add2front) along with the count of the total number of words in the list. The filename is input by the user, and you must print an error message and exit if the file isn't found. You must use a linked list for this. If you just declare a giant array and hope it's big enough, your poor instructor will be really discouraged.
~/$ ./part1
Input file is: shortExample.txt
Count is 12
Holla. sentences. couple a has just It example. short a is Here
~/$ ./part1
Input file is: mobyDick.txt
Count is 215829
eBooks. new about hear to newsletter email our to subscribe to how and eBooks, new ...
~/$ ./part1
Input file is: asdf
Error! File 'asdf' not found!

submit: ~/bin/submit -c=SI204 -p=lab11 part1.cpp

Part 2: Search! [part2.cpp all in one file!]

Copy your part1.cpp into part2.cpp and implement basic word search. This should allow the user to ask if words exist in the book or not, with as many searches as the user desires. 'quit' will exit the program. You must write a function which implements this search. The trick here is that we also want you to print the next word in the list after the one you found. HINT: have your search function return a pointer to the node where you found the word!

~/$ ./part2
Input file is: mobyDick.txt
Count is 215829
word search: happy
Word found and next word is: glad,
word search: angry
Word found and next word is: his
word search: asdf
Word not found.
word search: fish
Word found and next word is: murderous
word search: harpoo
Word not found.
word search: harpoon
Word found and next word is: The
word search: quit!

Part 3: Linked lists are the same no matter what the data [part3.cpp all in one file!]

Your Part 3 program will be just like Part 2, except your data no longer consists of a single word, but rather of a word and an integer value (the frequency count of that word). Keep your code reading the entire file, but instead of just inserting each word at the front of the list, you must first search your list to see if it already exists. If it does, increment the count associated with that word by one. If the word does not yet exist, then add2front as usual. The result will be a linked list of unique words and their frequency counts.

If you do this elegantly, you'll make a new struct for representing pairs (word,count) and make that the type of data rather than mucking up Node with multiple data members representing "the data". This reinforces the fundamental idea that linked lists are the same no matter what kind of data you put in them.

Important! This is a super inefficient way to store word counts. You have to search the entire list for each word, so your program will take 2-3 minutes to load a full novel. Test first on shortExample.txt and shortMoby.txt to make sure it works. Then run on an entire book and enjoy searching!

~/$ ./part3
Input file is: blah
Error! File 'blah' not found!

~/$ ./part3
Input file is: shortMoby.txt
count is 2193
word search: whale
Word found with count 1 and the next word is idea
word search: the
Word found with count 121 and the next word is see
word search: water
Word found with count 4 and the next word is nigh
word search: sails
Word not found.
word search: sail
Word found with count 2 and the next word is would
word search: me  
Word found with count 17 and the next word is Call
word search: quit!

~/$ ./part3
Input file is: mobyDick.txt
count is 215829
word search: whale
Word found with count 393 and the next word is higgledy-piggledy
word search: higgledy-piggledy
Word found with count 1 and the next word is least,
word search: knife
Word found with count 8 and the next word is weather.
word search: knot
Word found with count 3 and the next word is pendulous,
word search: quit!

submit: ~/bin/submit -c=SI204 -p=lab11 part1.cpp part2.cpp part3.cpp

Part 4.0: (optional) Split into multiple files!

Hopefully you have written a nice program with multiple structs and nicely chosen functions so that main() is simple and beautiful. Now copy your part3.cpp to part4.cpp. Then break this into multiple files: part4.cpp for main, lab11.h for your structs and protptypes, and lab11.cpp for your function definitions. It's a bit cheesy to force you to have only one .h/.cpp pair and to force you to name it "lab11.h" and "lab11.cpp", but it'll help with the submit system for the following parts.

Note: No submit for this part!

Part 4.1: (optional) The user iterates through the list [part4.cpp, lab11.h, lab11.cpp]

Keep your part4.cpp from the previous 4.0 instructions. In this Part 4.1 program, we let the user move through the list and print where we currently are in it. We start at the beginning, and the user can type the following:
~/$ ./part4
Input file is: shortExample.txt
count is 12
query: printall
(Holla. 1) (sentences. 1) (couple 1) (has 1) (just 1) (It 1) (example. 1) (short 1) (a 2) (is 1) (Here 1) 
query: n
query: n
query: printall
(couple 1) (has 1) (just 1) (It 1) (example. 1) (short 1) (a 2) (is 1) (Here 1) 
query: countall
count is 10
query: n
query: countall
count is 9
query: sentences.
Word found with count 1 and the next word is couple
query: quit!

submit: ~/bin/submit -c=SI204 -p=lab11 part1.cpp part2.cpp part3.cpp part4.cpp lab11.h lab11.cpp

Part 5: (optional) — Delete [part5.cpp, lab11.h, lab11.cpp]

In Part 5 we add a delete function. Keep all you have from Part 4, but now allow the user to delete any word they want from the list permanently. Write a delete function and add this user command:
~/$ ./part5
Input file is: shortExample.txt
count is 12
query: printall
(Holla. 1) (sentences. 1) (couple 1) (has 1) (just 1) (It 1) (example. 1) (short 1) (a 2) (is 1) (Here 1) 
query: n
query: printall
(sentences. 1) (couple 1) (has 1) (just 1) (It 1) (example. 1) (short 1) (a 2) (is 1) (Here 1) 
query: delete It
query: printall
(sentences. 1) (couple 1) (has 1) (just 1) (example. 1) (short 1) (a 2) (is 1) (Here 1) 
query: delete Here
query: printall
(sentences. 1) (couple 1) (has 1) (just 1) (example. 1) (short 1) (a 2) (is 1) 
query: countall
count is 9
query: quit!
      

submit: ~/bin/submit -c=SI204 -p=lab11 part1.cpp part2.cpp part3.cpp lab11.h lab11.cpp part4.cpp part5.cpp