Question: Step 3 : Implement RemoveLastCommand's Execute ( ) member function The RemoveLastCommand class inherits from UndoCommand and is declared in RemoveLastCommand.h . When a RemoveLastCommand

Step 3: Implement RemoveLastCommand's Execute() member function
The RemoveLastCommand class inherits from UndoCommand and is declared in RemoveLastCommand.h. When a RemoveLastCommand object is executed, the string vector's last element is removed. So when the user appends a new item to the grocery list, a RemoveLastCommand is pushed onto the stack of undo commands. Popping and executing the RemoveLastCommand then removes the item most recently added by the user.
RemoveLastCommand's sourceVector member variable and constructor are already declared:
sourceVector is a pointer to a GroceryList object's vector of strings.
The constructor takes a pointer to a vector of strings as a parameter, and assigns sourceVector with the pointer.
Implement RemoveLastCommand's Execute() member function to remove sourceVector's last element.
Step 4: Implement GroceryList's ExecuteUndo() member function
Implement GroceryList's ExecuteUndo() member function to do the following:
Pop an UndoCommand off the undo stack
Execute the popped undo command
Delete the undo command
File main.cpp has some test functions. Each constructs a GroceryListTest object from a list of string commands. Test 1 tests code implemented so far: insertion and undo of insertion. Calls to other test functions are commented-out in main(). Run your code and make sure that test 1 passes before proceeding.
Step 5: Implement the SwapCommand class and GroceryList's SwapWithUndo() member function
Implement the SwapCommand class in SwapCommand.h. The class itself is declared, but with no members. Add necessary member variables and member functions so that the command can undo swapping two items in the grocery list.
Implement GroceryList's SwapWithUndo() member function. The function swaps list items at the specified indices, then pushes a SwapCommand to undo that swap onto the undo stack.
Uncomment the two lines in main() that call test2() and display results. Run your code and make sure that both test 1 and test 2 pass.
Step 6: Implement the InsertAtCommand class and GroceryList's RemoveAtWithUndo() member function
Implement the InsertAtCommand class in InsertAtCommand.h. Add necessary member variables and member functions so that the command can undo removing a grocery list item at an arbitrary index.
Implement GroceryList's RemoveAtWithUndo() member function. The function removes the list item at the specified index, then pushes an InsertAtCommand to undo that removal onto the undo stack.
Uncomment the two lines in main() that call test3() and display results. Run your code and make sure that all tests pass. The output from main() does not affect grading, so consider adding more tests to main() before submitting code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!