Question: lab 5 . 1 0 Code provided Main.cpp #include #include #include GroceryList.h #include GroceryListTest.h using namespace std; int main ( ) { bool
lab
Code provided
Main.cpp
#include
#include
#include "GroceryList.h
#include "GroceryListTest.h
using namespace std;
int main
bool testpass test;
cout "Test : testpass "PASS" : "FAIL" endl endl;
Initialize a new grocery list
GroceryList groceryList;
string command;
bool quit false;
while quit
getlinecin command;
Process user input
if command "print"
groceryList.Printcout;
else if command.findadd
groceryList.AddWithUndocommandsubstr;
else if command.findremoveat
int index stoicommandsubstr;
groceryList.RemoveAtWithUndoindex;
else if command.findswap
int index index;
if ParseIndicescommandsubstr index index
groceryList.SwapWithUndoindex index;
else
cout swap command requires two indices, separated ;
cout by a space. Ex: swap endl;
else if command "undo"
if groceryList.GetUndoStackSize
cout "Cannot execute undo because undo stack is empty" endl;
else
groceryList.ExecuteUndo;
else if command "quit"
quit true;
else
cout "Unknown command: command endl;
return ;
bool ParseIndicesstd::string str int& outIndex int& outIndex
auto spaceIndex strfind;
if spaceIndex string::npos
return false;
outIndex stoistr;
outIndex stoistrsubstrspaceIndex ;
return true;
UndoCommand.h
#ifndef UNDOCOMMANDH
#define UNDOCOMMANDH
class UndoCommand
public:
virtual ~UndoCommand
virtual void Execute;
;
#endif
RemoveLastCommand.h
#ifndef REMOVELASTCOMMANDH
#define REMOVELASTCOMMANDH
#include
#include
#include "UndoCommand.h
class RemoveLastCommand : public UndoCommand
private:
std::vector sourceVector;
public:
RemoveLastCommandstd::vector vector
sourceVector vector;
void Execute override
Your code here
;
#endif
SwapCommand.h
#ifndef SWAPCOMMANDH
#define SWAPCOMMANDH
#include
#include
#include "UndoCommand.h
class SwapCommand : public UndoCommand
private:
Your member variable declarations here
public:
Your constructor code here
void Execute override
Your code here
;
#endif
InsertAtCommand.h
#ifndef INSERTATCOMMANDH
#define INSERTATCOMMANDH
#include
#include
#include "UndoCommand.h
class InsertAtCommand : public UndoCommand
private:
Your member variable declarations here
public:
Your constructor code here
void Execute override
Your code here
;
#endif
GroceryList.h
#ifndef GROCERYLISTH
#define GROCERYLISTH
#include
#include
#include "UndoCommand.h
#include "RemoveLastCommand.h
#include "InsertAtCommand.h
#include "SwapCommand.h
class GroceryList
protected:
std::vector listItems;
std::stack undoStack;
public:
virtual void AddWithUndostd::string newItemName
Add the new list item
listItems.pushbacknewItemName;
Make an undo command that removes the last item and push onto stack
undoStack.pushnew RemoveLastCommand&listItems;
virtual void RemoveAtWithUndoint removalIndex
Your code here
virtual void SwapWithUndoint index int index
Your code here
Pops and executes the undo command at the top of the undo stack. Then
deletes the executed command.
virtual void ExecuteUndo
Your code here
virtual int GetListSize const
return intlistItemssize;
virtual int GetUndoStackSize const
return intundoStacksize;
virtual std::vector GetVectorCopy const
return listItems;
virtual void Printstd::ostream& outputStream
for sizet i ; i listItems.size; i
outputStream i listItemsi std::endl;
;
#endif
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
