You must use a linked list to store the input strings.
~/$ ./part1 Input file is: in00.txt Count is 8 the a cat dog sounds is smelly incomprehensible ~/$ ./part1 Input file is: in01.txt Count is 23 a let my ring of the fire truth way is that a better scary golden ring the left sight ring out highway alone ~/$ ./part1 Input file is: asdf Error! File 'asdf' not found!
submit:
~/bin/submit -c=IC210 -p=lab10 part1.cpp
(word
value). Check the contents of in02.txt on the
right.
Make a new struct for representing pairs and make that the type of
data rather than mucking up Node with multiple data
members representing "the data".
~/$ ./part2 Input file is: in02.txt Count is 8 (the 1) (a 1) (cat 2) (dog 2) (sounds 2) (is 1) (smelly 3) (incomprehensible 5)
~/$ ./part2 Input file is: in03.txt Count is 23 (a 1) (let 3) (my 2) (ring 3) (of 1) (the 1) (fire 3) (truth 3) (way 2) (is 1) (that 1) (a 1) (better 3) (scary 4) (golden 4) (ring 3) (the 1) (left 2) (sight 3) (ring 3) (out 2) (highway 4) (alone 3)
submit:
~/bin/submit -c=IC210 -p=lab10 part*.cpp
It's a bit cheesy to force you to have only one .h/.cpp pair and
to force you to name it "lab10.h" and "lab10.cpp", but it'll
help with the submit system for the following parts.
Note: No submit for this part!
|
In the Part 3 program, after reading in the pairs as with Part 2, we let the
user move through the list. At each step we print out:
The user is asked to either "accept" or "reject" the current word/value pair, though we don't actually act on that until Part 5 (yes, that means you do the same thing regardless of what the user enters: do nothing). After the user has gone through the whole list, we print the entire list all at once. Tip: Do you remember how to compute the length of a list? submit:~/bin/submit -c=IC210 -p=lab10 part*.cpp lab10.* |
Sample run:
~/$ ./part3 Input file is: in04.txt The current node: (the 1) Nodes before the current: #nodes after the current: 3 [a]ccept or [r]eject: a The current node: (dog 2) Nodes before the current: (the 1) #nodes after the current: 2 [a]ccept or [r]eject: a The current node: (is 1) Nodes before the current: (the 1) (dog 2) #nodes after the current: 1 [a]ccept or [r]eject: a The current node: (smelly 3) Nodes before the current: (the 1) (dog 2) (is 1) #nodes after the current: 0 [a]ccept or [r]eject: a List is: (the 1) (dog 2) (is 1) (smelly 3) |
in04.txt:
(smelly 3) (is 1) (dog 2) (the 1) |
Your Part 4 program should do:
Warning: Your lab10.h and lab10.cpp should work both for Part 3 and
Part 4.
For example, suppose you wrote some function in lab10.h and lab10.cpp for Part 3. You realize you need to slightly modify how that function works for Part 4, so you changed it. Part 4 may work fine, but you have a problem: Part 3 won't work anymore!! So, for this case, you should write a new (slightly different) function for Part 4 instead of modifing the already-existing function for Part 3. submit: ~/bin/submit -c=IC210 -p=lab10 part*.cpp lab10.* |
Sample run:
~/$ ./part4 Input file is: in04.txt The current node: (the 1) Nodes before the current: #nodes after the current: 3 [a]ccept or [r]eject: a The current node: (dog 2) Nodes before the current: (the 1) #nodes after the current: 2 [a]ccept or [r]eject: a The current node: (is 1) Nodes before the current: (the 1) (dog 2) #nodes after the current: 1 [a]ccept or [r]eject: a The current node: (smelly 3) Nodes before the current: (the 1) (dog 2) (is 1) #nodes after the current: 0 [a]ccept or [r]eject: a List is: the dog is smelly Score is: 7 |
in04.txt:
(smelly 3) (is 1) (dog 2) (the 1) |
In Part 5 we finally acheive what the other stuff was really working toward: a
really simple word game!
Tips: you have two choices for making this work. The first is to actually remove the node for the [r]ejected word from the list. The second is to keep a separate list consisting of the [a]ccepted words. Both have their challenges!
Warning: Your lab10.h and lab10.cpp should work for Part 3,
Part 4, and Part 5.
submit: ~/bin/submit -c=IC210 -p=lab10 part*.cpp lab10.* |
Sample run:
~/$ ./part5 Input file is: in02.txt The current node: (the 1) Sentence you made so far: #words left: 7 [a]ccept or [r]eject: a The current node: (a 1) Sentence you made so far: the #words left: 6 [a]ccept or [r]eject: r The current node: (cat 2) Sentence you made so far: the #words left: 5 [a]ccept or [r]eject: r The current node: (dog 2) Sentence you made so far: the #words left: 4 [a]ccept or [r]eject: a The current node: (sounds 2) Sentence you made so far: the dog #words left: 3 [a]ccept or [r]eject: a The current node: (is 1) Sentence you made so far: the dog sounds #words left: 2 [a]ccept or [r]eject: r The current node: (smelly 3) Sentence you made so far: the dog sounds #words left: 1 [a]ccept or [r]eject: r The current node: (incomprehensible 5) Sentence you made so far: the dog sounds #words left: 0 [a]ccept or [r]eject: a Sentence is: the dog sounds incomprehensible Score is: 10 |
in02.txt:
(incomprehensible 5) (smelly 3) (is 1) (sounds 2) (dog 2) (cat 2) (a 1) (the 1) |