CS2050 SS2017 Lab 6 Assignment Use the following structure definition: typedef s
ID: 3856371 • Letter: C
Question
CS2050 SS2017 Lab 6
Assignment
Use the following structure definition:
typedef struct word_
{
char word[10];
struct word_* nextWord;
struct word_* prevWord;
} Word;
You will be implementing the undo and redo functionality, although it will be clunky. You will input a word at a time to forma a sentence then have the option to undo/redo the last word put in. For this lab you will only have to redo the last word that is undone. See the sample output for details.
Be sure to pay close attention to where the pointers are referencing and make sure the pointers in the list are pointing to the correct nodes. You must also error check thoroughly so user doesn’t have accidentally break anything.
Use the following function prototypes:
Word* addWord(Word* lastWord, Word* nextWord);
This function adds the newest word to the stack of words. The last word passed into this function is the top of the stack. Return the newest top of the stack after the new word is added. NOTE: this function will also be used to implement the redo functionality.
void printSentence(Word* lastWord);
Prints ot the sentence as one would read it. Be careful!!! The last word(top of the stack) is the parameter to this function, not the first.
void freeSentence(Word* lastWord);
Frees every word in the sentence, starting with the last word entered.
Word* undoWord(Word** lastWordPtr);
Takes out the last word entered from the stack, and returns it. The stack must be updated to have a new top!
Int main(void);
Presents a menu to the user for adding, undoing, or redoing a word, executes that command and prints out the sentence. Main must also keep track of the top of the stack, as well as the word that was undone, in case the user wants to redo. The user will continue to choose an option until they want to quit and the stack is freed up. See sample output for details
Sample Output
Select an option:
1: add a word
2: undo
3: redo
4: quit
Option:
>2
Nothing to undo.
Nothing to print.
Select an option:
1: add a word
2: undo
3: redo
4: quit
Option:
>1
Insert your word: This
This
Select an option:
1: add a word
2: undo
3: redo
4: quit
Option:
>1
Insert your word: is
This is
Select an option:
1: add a word
2: undo
3: redo
4: quit
Option:
>2
This
Select an option:
1: add a word
2: undo
3: redo
4: quit
Option:
>3
This is
Select an option:
1: add a word
2: undo
3: redo
4: quit
Option:
>4
RUN SUCCESSFUL (total time: 7m 50s)
Guidelines for Grading!
35 pts possible
Use of global variables : – 15 points
Explanation / Answer
typedef struct word_
{
char word[10];
struct word_* nextWord;
struct word_* prevWord;
} Wor