SlideShare a Scribd company logo
1 of 12
Download to read offline
#include
#include
#include
#include "GroceryList.h"
using namespace std;
bool ParseIndices(std::string str, int& outIndex1, int& outIndex2);
int main(int argc, char *argv[]){
//initalize s new grocery list
GroceryList groceryList;
string command;
bool quit = false;
while(!quit){
getline (cin, command);
if(command == "print"){
groceryList.Print(cout);
}
else if(0== command.find("add")){
groceryList.AddWithUndo(command.substr(4));
}
else if(0 == command.find("removeat")){
int index = stoi(command.substr(9));
groceryList.RemoveWithUndo(index);
}
else if(0 == command.find("swap")){
int index1 = -1, index2 = -1;
if(ParseIndices(command.substr(5), index1,index2)){
groceryList.SwapWithUndo(index1, index2);
}
else if(command=="undo"){
if(0==grocerList.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 0;
}
bool ParseIndices(std::string str, int& outIndex1, int& outIndex2){
auto spaceIndex = str.find(" ");
if(spaceIndex == strinh::npis){
return false;
}
outIndex1 = stoi(str);
outIndex2 = stoi(str.substr(spaceIndex +1));
return true;
}
the RemoveLastCommand class inherits from UndoCommand and is declared in
RemoveLastCommand.h When a RemoveLastCommand object executed, the strinh vectors last
element is removed. So when the user appends a new item in 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 user.
RemoveLastCommands sourceVector member variable and constructir are already declared
sourceVector is a pointer to a GroceryList objects vector of strings.
The constructor takes a pointer to a vector of strings as a parameter, and assigns sourceVectors
witb the pointer.
implement RemoveLastCommandS Execute() member function to remove sourceVectors last
element.
c++ c++
class RemoveLastCommand : public UndoCommand{
private:
std::vector* sourceVector;
Public:
RemoveLastCommand(std::vector* vector){
sourceVector = vector;
}
void Execute() override{
// code here
};
#endif
implement GroceryLists ExecuteUndo() member function
to di following
pop an UndoCommand off the undo stack
Execute the popped undo command
Delete the undo command
File main.cpp had a code that reads in a list of commands one per line that allows for basic
testing of basic operations. So after implementing ExecuteUndo() run program with the
following input:
add bananas
add grapes
add strawberries
print
undo
print
undo
print
quit
verify that the ouput is 0. banana
1. grapes and so forth
class GroceryList{
protected:
std::vector listItems;
std::stackundostack;
public:
virtual voif AddWithUndo(std:: string newItemName({
listItems.push_back(newItemName);
//make an undo command that removes //the last item and push onto stack
undoStack.push(new RemoveLastCommand(&listItem));
}
virtual void RemoveAtWithUndo(int removalIndex){
//code here
}
void SwapWithUndo(int index1, int index2){
//code here
}
virtual void ExecuteUndo(){
if(!undoStack.empty()){
undoCommand* undoCommand = undoStack.top();
undoStack.pop();
undo->Execute();
delet undoCommand;
}
}
virtual int GetListSize() const{
return(int) listItems.size();
}
virtual int GetUndoStackSize() const{
return(int) undoStack.size();
}
virtual std:: vector GetVectorCopy() const{
return listItems;
}
virtuak void Print(std:: ostream& outputstream){
for(size_t i = 0; i < listItems.size(); i++){
outputstream <
#include
#include
#include "GroceryList.h"
using namespace std;
bool ParseIndices(std::string str, int& outIndex1, int& outIndex2);
int main(int argc, char *argv[]){
//initalize s new grocery list
GroceryList groceryList;
string command;
bool quit = false;
while(!quit){
getline (cin, command);
if(command == "print"){
groceryList.Print(cout);
}
else if(0== command.find("add")){
groceryList.AddWithUndo(command.substr(4));
}
else if(0 == command.find("removeat")){
int index = stoi(command.substr(9));
groceryList.RemoveWithUndo(index);
}
else if(0 == command.find("swap")){
int index1 = -1, index2 = -1;
if(ParseIndices(command.substr(5), index1,index2)){
groceryList.SwapWithUndo(index1, index2);
}
else if(command=="undo"){
if(0==grocerList.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 0;
}
bool ParseIndices(std::string str, int& outIndex1, int& outIndex2){
auto spaceIndex = str.find(" ");
if(spaceIndex == strinh::npis){
return false;
}
outIndex1 = stoi(str);
outIndex2 = stoi(str.substr(spaceIndex +1));
return true;
}
the RemoveLastCommand class inherits from UndoCommand and is declared in
RemoveLastCommand.h When a RemoveLastCommand object executed, the strinh vectors last
element is removed. So when the user appends a new item in 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 user.
RemoveLastCommands sourceVector member variable and constructir are already declared
sourceVector is a pointer to a GroceryList objects vector of strings.
The constructor takes a pointer to a vector of strings as a parameter, and assigns sourceVectors
witb the pointer.
implement RemoveLastCommandS Execute() member function to remove sourceVectors last
element.
c++ c++
class RemoveLastCommand : public UndoCommand{
private:
std::vector* sourceVector;
Public:
RemoveLastCommand(std::vector* vector){
sourceVector = vector;
}
void Execute() override{
// code here
};
#endif
implement GroceryLists ExecuteUndo() member function
to di following
pop an UndoCommand off the undo stack
Execute the popped undo command
Delete the undo command
File main.cpp had a code that reads in a list of commands one per line that allows for basic
testing of basic operations. So after implementing ExecuteUndo() run program with the
following input:
add bananas
add grapes
add strawberries
print
undo
print
undo
print
quit
verify that the ouput is 0. banana
1. grapes and so forth
class GroceryList{
protected:
std::vector listItems;
std::stackundostack;
public:
virtual voif AddWithUndo(std:: string newItemName({
listItems.push_back(newItemName);
//make an undo command that removes //the last item and push onto stack
undoStack.push(new RemoveLastCommand(&listItem));
}
virtual void RemoveAtWithUndo(int removalIndex){
//code here
}
void SwapWithUndo(int index1, int index2){
//code here
}
virtual void ExecuteUndo(){
if(!undoStack.empty()){
undoCommand* undoCommand = undoStack.top();
undoStack.pop();
undo->Execute();
delet undoCommand;
}
}
virtual int GetListSize() const{
return(int) listItems.size();
}
virtual int GetUndoStackSize() const{
return(int) undoStack.size();
}
virtual std:: vector GetVectorCopy() const{
return listItems;
}
virtuak void Print(std:: ostream& outputstream){
for(size_t i = 0; i < listItems.size(); i++){
outputstream <
#include
#include "GroceryList.h"
using namespace std;
bool ParseIndices(std::string str, int& outIndex1, int& outIndex2);
int main(int argc, char *argv[]){
//initalize s new grocery list
GroceryList groceryList;
string command;
bool quit = false;
while(!quit){
getline (cin, command);
if(command == "print"){
groceryList.Print(cout);
}
else if(0== command.find("add")){
groceryList.AddWithUndo(command.substr(4));
}
else if(0 == command.find("removeat")){
int index = stoi(command.substr(9));
groceryList.RemoveWithUndo(index);
}
else if(0 == command.find("swap")){
int index1 = -1, index2 = -1;
if(ParseIndices(command.substr(5), index1,index2)){
groceryList.SwapWithUndo(index1, index2);
}
else if(command=="undo"){
if(0==grocerList.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 0;
}
bool ParseIndices(std::string str, int& outIndex1, int& outIndex2){
auto spaceIndex = str.find(" ");
if(spaceIndex == strinh::npis){
return false;
}
outIndex1 = stoi(str);
outIndex2 = stoi(str.substr(spaceIndex +1));
return true;
}
the RemoveLastCommand class inherits from UndoCommand and is declared in
RemoveLastCommand.h When a RemoveLastCommand object executed, the strinh vectors last
element is removed. So when the user appends a new item in 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 user.
RemoveLastCommands sourceVector member variable and constructir are already declared
sourceVector is a pointer to a GroceryList objects vector of strings.
The constructor takes a pointer to a vector of strings as a parameter, and assigns sourceVectors
witb the pointer.
implement RemoveLastCommandS Execute() member function to remove sourceVectors last
element.
c++ c++
class RemoveLastCommand : public UndoCommand{
private:
std::vector* sourceVector;
Public:
RemoveLastCommand(std::vector* vector){
sourceVector = vector;
}
void Execute() override{
// code here
};
#endif
implement GroceryLists ExecuteUndo() member function
to di following
pop an UndoCommand off the undo stack
Execute the popped undo command
Delete the undo command
File main.cpp had a code that reads in a list of commands one per line that allows for basic
testing of basic operations. So after implementing ExecuteUndo() run program with the
following input:
add bananas
add grapes
add strawberries
print
undo
print
undo
print
quit
verify that the ouput is 0. banana
1. grapes and so forth
class GroceryList{
protected:
std::vector listItems;
std::stackundostack;
public:
virtual voif AddWithUndo(std:: string newItemName({
listItems.push_back(newItemName);
//make an undo command that removes //the last item and push onto stack
undoStack.push(new RemoveLastCommand(&listItem));
}
virtual void RemoveAtWithUndo(int removalIndex){
//code here
}
void SwapWithUndo(int index1, int index2){
//code here
}
virtual void ExecuteUndo(){
if(!undoStack.empty()){
undoCommand* undoCommand = undoStack.top();
undoStack.pop();
undo->Execute();
delet undoCommand;
}
}
virtual int GetListSize() const{
return(int) listItems.size();
}
virtual int GetUndoStackSize() const{
return(int) undoStack.size();
}
virtual std:: vector GetVectorCopy() const{
return listItems;
}
virtuak void Print(std:: ostream& outputstream){
for(size_t i = 0; i < listItems.size(); i++){
outputstream <

More Related Content

Similar to #includeiostream#includestack#includestring #include .pdf

The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210Mahmoud Samir Fayed
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utilsroxlu
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfmail931892
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++mustkeem khan
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diplomamustkeem khan
 
#include iostream     Provides cout. #include cstdlib   .pdf
 #include iostream      Provides cout. #include cstdlib   .pdf #include iostream      Provides cout. #include cstdlib   .pdf
#include iostream     Provides cout. #include cstdlib   .pdfaptind
 
#include iostream     Provides cout. #include cstdlib   .pdf
 #include iostream      Provides cout. #include cstdlib   .pdf #include iostream      Provides cout. #include cstdlib   .pdf
#include iostream     Provides cout. #include cstdlib   .pdfaptind
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfmichardsonkhaicarr37
 
Page 1 of 2 Updated on 2020-01-23 CPS 151Spring 2020 .docx
Page 1 of 2  Updated on 2020-01-23 CPS 151Spring 2020 .docxPage 1 of 2  Updated on 2020-01-23 CPS 151Spring 2020 .docx
Page 1 of 2 Updated on 2020-01-23 CPS 151Spring 2020 .docxkarlhennesey
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
 
20180721 code defragment
20180721 code defragment20180721 code defragment
20180721 code defragmentChiwon Song
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfcalderoncasto9163
 
Import java
Import javaImport java
Import javaheni2121
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
 
PQTimer.java A simple driver program to run timing t.docx
  PQTimer.java     A simple driver program to run timing t.docx  PQTimer.java     A simple driver program to run timing t.docx
PQTimer.java A simple driver program to run timing t.docxjoyjonna282
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfkostikjaylonshaewe47
 

Similar to #includeiostream#includestack#includestring #include .pdf (20)

The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
#include iostream     Provides cout. #include cstdlib   .pdf
 #include iostream      Provides cout. #include cstdlib   .pdf #include iostream      Provides cout. #include cstdlib   .pdf
#include iostream     Provides cout. #include cstdlib   .pdf
 
#include iostream     Provides cout. #include cstdlib   .pdf
 #include iostream      Provides cout. #include cstdlib   .pdf #include iostream      Provides cout. #include cstdlib   .pdf
#include iostream     Provides cout. #include cstdlib   .pdf
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
Page 1 of 2 Updated on 2020-01-23 CPS 151Spring 2020 .docx
Page 1 of 2  Updated on 2020-01-23 CPS 151Spring 2020 .docxPage 1 of 2  Updated on 2020-01-23 CPS 151Spring 2020 .docx
Page 1 of 2 Updated on 2020-01-23 CPS 151Spring 2020 .docx
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
 
20180721 code defragment
20180721 code defragment20180721 code defragment
20180721 code defragment
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
 
Import java
Import javaImport java
Import java
 
week-16x
week-16xweek-16x
week-16x
 
Array Cont
Array ContArray Cont
Array Cont
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
Lab 3
Lab 3Lab 3
Lab 3
 
PQTimer.java A simple driver program to run timing t.docx
  PQTimer.java     A simple driver program to run timing t.docx  PQTimer.java     A simple driver program to run timing t.docx
PQTimer.java A simple driver program to run timing t.docx
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
 
Function C++
Function C++ Function C++
Function C++
 

More from srinivas9922

they should clearly communicate what the model component represents. .pdf
they should clearly communicate what the model component represents. .pdfthey should clearly communicate what the model component represents. .pdf
they should clearly communicate what the model component represents. .pdfsrinivas9922
 
1. How did ODO operationalize the definition of an adult with a disa.pdf
1. How did ODO operationalize the definition of an adult with a disa.pdf1. How did ODO operationalize the definition of an adult with a disa.pdf
1. How did ODO operationalize the definition of an adult with a disa.pdfsrinivas9922
 
Write a program that do the following 1. Define one integer variable.pdf
Write a program that do the following 1. Define one integer variable.pdfWrite a program that do the following 1. Define one integer variable.pdf
Write a program that do the following 1. Define one integer variable.pdfsrinivas9922
 
Which of the following statements about location is FALSE LatLong.pdf
Which of the following statements about location is FALSE LatLong.pdfWhich of the following statements about location is FALSE LatLong.pdf
Which of the following statements about location is FALSE LatLong.pdfsrinivas9922
 
#include iostream#include iomanip#include fstreamusing n.pdf
#include iostream#include iomanip#include fstreamusing n.pdf#include iostream#include iomanip#include fstreamusing n.pdf
#include iostream#include iomanip#include fstreamusing n.pdfsrinivas9922
 
1) Supongamos que los gobiernos federal, estatal y local de Estados .pdf
1) Supongamos que los gobiernos federal, estatal y local de Estados .pdf1) Supongamos que los gobiernos federal, estatal y local de Estados .pdf
1) Supongamos que los gobiernos federal, estatal y local de Estados .pdfsrinivas9922
 
1) Create logical design for the following ERD (20pts) MEMBER Member.pdf
1) Create logical design for the following ERD (20pts) MEMBER Member.pdf1) Create logical design for the following ERD (20pts) MEMBER Member.pdf
1) Create logical design for the following ERD (20pts) MEMBER Member.pdfsrinivas9922
 

More from srinivas9922 (7)

they should clearly communicate what the model component represents. .pdf
they should clearly communicate what the model component represents. .pdfthey should clearly communicate what the model component represents. .pdf
they should clearly communicate what the model component represents. .pdf
 
1. How did ODO operationalize the definition of an adult with a disa.pdf
1. How did ODO operationalize the definition of an adult with a disa.pdf1. How did ODO operationalize the definition of an adult with a disa.pdf
1. How did ODO operationalize the definition of an adult with a disa.pdf
 
Write a program that do the following 1. Define one integer variable.pdf
Write a program that do the following 1. Define one integer variable.pdfWrite a program that do the following 1. Define one integer variable.pdf
Write a program that do the following 1. Define one integer variable.pdf
 
Which of the following statements about location is FALSE LatLong.pdf
Which of the following statements about location is FALSE LatLong.pdfWhich of the following statements about location is FALSE LatLong.pdf
Which of the following statements about location is FALSE LatLong.pdf
 
#include iostream#include iomanip#include fstreamusing n.pdf
#include iostream#include iomanip#include fstreamusing n.pdf#include iostream#include iomanip#include fstreamusing n.pdf
#include iostream#include iomanip#include fstreamusing n.pdf
 
1) Supongamos que los gobiernos federal, estatal y local de Estados .pdf
1) Supongamos que los gobiernos federal, estatal y local de Estados .pdf1) Supongamos que los gobiernos federal, estatal y local de Estados .pdf
1) Supongamos que los gobiernos federal, estatal y local de Estados .pdf
 
1) Create logical design for the following ERD (20pts) MEMBER Member.pdf
1) Create logical design for the following ERD (20pts) MEMBER Member.pdf1) Create logical design for the following ERD (20pts) MEMBER Member.pdf
1) Create logical design for the following ERD (20pts) MEMBER Member.pdf
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 

Recently uploaded (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 

#includeiostream#includestack#includestring #include .pdf

  • 1. #include #include #include #include "GroceryList.h" using namespace std; bool ParseIndices(std::string str, int& outIndex1, int& outIndex2); int main(int argc, char *argv[]){ //initalize s new grocery list GroceryList groceryList; string command; bool quit = false; while(!quit){ getline (cin, command); if(command == "print"){ groceryList.Print(cout); } else if(0== command.find("add")){ groceryList.AddWithUndo(command.substr(4)); } else if(0 == command.find("removeat")){ int index = stoi(command.substr(9)); groceryList.RemoveWithUndo(index); } else if(0 == command.find("swap")){ int index1 = -1, index2 = -1; if(ParseIndices(command.substr(5), index1,index2)){ groceryList.SwapWithUndo(index1, index2); } else if(command=="undo"){ if(0==grocerList.GetUndoStackSize()){ cout<< "Cannot execute undo because undo stack is empty"<< endl; }
  • 2. else{ groceryList.ExecuteUndo(); } else if(command==" quit"){ quit == true; } else{ cout<<"Unknown command:<< command << endl; } } return 0; } bool ParseIndices(std::string str, int& outIndex1, int& outIndex2){ auto spaceIndex = str.find(" "); if(spaceIndex == strinh::npis){ return false; } outIndex1 = stoi(str); outIndex2 = stoi(str.substr(spaceIndex +1)); return true; } the RemoveLastCommand class inherits from UndoCommand and is declared in RemoveLastCommand.h When a RemoveLastCommand object executed, the strinh vectors last element is removed. So when the user appends a new item in 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 user. RemoveLastCommands sourceVector member variable and constructir are already declared sourceVector is a pointer to a GroceryList objects vector of strings. The constructor takes a pointer to a vector of strings as a parameter, and assigns sourceVectors witb the pointer. implement RemoveLastCommandS Execute() member function to remove sourceVectors last element. c++ c++
  • 3. class RemoveLastCommand : public UndoCommand{ private: std::vector* sourceVector; Public: RemoveLastCommand(std::vector* vector){ sourceVector = vector; } void Execute() override{ // code here }; #endif implement GroceryLists ExecuteUndo() member function to di following pop an UndoCommand off the undo stack Execute the popped undo command Delete the undo command File main.cpp had a code that reads in a list of commands one per line that allows for basic testing of basic operations. So after implementing ExecuteUndo() run program with the following input: add bananas add grapes add strawberries print undo print undo print quit verify that the ouput is 0. banana 1. grapes and so forth class GroceryList{ protected: std::vector listItems; std::stackundostack;
  • 4. public: virtual voif AddWithUndo(std:: string newItemName({ listItems.push_back(newItemName); //make an undo command that removes //the last item and push onto stack undoStack.push(new RemoveLastCommand(&listItem)); } virtual void RemoveAtWithUndo(int removalIndex){ //code here } void SwapWithUndo(int index1, int index2){ //code here } virtual void ExecuteUndo(){ if(!undoStack.empty()){ undoCommand* undoCommand = undoStack.top(); undoStack.pop(); undo->Execute(); delet undoCommand; } } virtual int GetListSize() const{ return(int) listItems.size(); } virtual int GetUndoStackSize() const{ return(int) undoStack.size(); } virtual std:: vector GetVectorCopy() const{ return listItems; } virtuak void Print(std:: ostream& outputstream){ for(size_t i = 0; i < listItems.size(); i++){ outputstream < #include #include #include "GroceryList.h" using namespace std;
  • 5. bool ParseIndices(std::string str, int& outIndex1, int& outIndex2); int main(int argc, char *argv[]){ //initalize s new grocery list GroceryList groceryList; string command; bool quit = false; while(!quit){ getline (cin, command); if(command == "print"){ groceryList.Print(cout); } else if(0== command.find("add")){ groceryList.AddWithUndo(command.substr(4)); } else if(0 == command.find("removeat")){ int index = stoi(command.substr(9)); groceryList.RemoveWithUndo(index); } else if(0 == command.find("swap")){ int index1 = -1, index2 = -1; if(ParseIndices(command.substr(5), index1,index2)){ groceryList.SwapWithUndo(index1, index2); } else if(command=="undo"){ if(0==grocerList.GetUndoStackSize()){ cout<< "Cannot execute undo because undo stack is empty"<< endl; } else{ groceryList.ExecuteUndo(); } else if(command==" quit"){ quit == true; } else{
  • 6. cout<<"Unknown command:<< command << endl; } } return 0; } bool ParseIndices(std::string str, int& outIndex1, int& outIndex2){ auto spaceIndex = str.find(" "); if(spaceIndex == strinh::npis){ return false; } outIndex1 = stoi(str); outIndex2 = stoi(str.substr(spaceIndex +1)); return true; } the RemoveLastCommand class inherits from UndoCommand and is declared in RemoveLastCommand.h When a RemoveLastCommand object executed, the strinh vectors last element is removed. So when the user appends a new item in 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 user. RemoveLastCommands sourceVector member variable and constructir are already declared sourceVector is a pointer to a GroceryList objects vector of strings. The constructor takes a pointer to a vector of strings as a parameter, and assigns sourceVectors witb the pointer. implement RemoveLastCommandS Execute() member function to remove sourceVectors last element. c++ c++ class RemoveLastCommand : public UndoCommand{ private: std::vector* sourceVector; Public: RemoveLastCommand(std::vector* vector){ sourceVector = vector; }
  • 7. void Execute() override{ // code here }; #endif implement GroceryLists ExecuteUndo() member function to di following pop an UndoCommand off the undo stack Execute the popped undo command Delete the undo command File main.cpp had a code that reads in a list of commands one per line that allows for basic testing of basic operations. So after implementing ExecuteUndo() run program with the following input: add bananas add grapes add strawberries print undo print undo print quit verify that the ouput is 0. banana 1. grapes and so forth class GroceryList{ protected: std::vector listItems; std::stackundostack; public: virtual voif AddWithUndo(std:: string newItemName({ listItems.push_back(newItemName); //make an undo command that removes //the last item and push onto stack undoStack.push(new RemoveLastCommand(&listItem)); } virtual void RemoveAtWithUndo(int removalIndex){
  • 8. //code here } void SwapWithUndo(int index1, int index2){ //code here } virtual void ExecuteUndo(){ if(!undoStack.empty()){ undoCommand* undoCommand = undoStack.top(); undoStack.pop(); undo->Execute(); delet undoCommand; } } virtual int GetListSize() const{ return(int) listItems.size(); } virtual int GetUndoStackSize() const{ return(int) undoStack.size(); } virtual std:: vector GetVectorCopy() const{ return listItems; } virtuak void Print(std:: ostream& outputstream){ for(size_t i = 0; i < listItems.size(); i++){ outputstream < #include #include "GroceryList.h" using namespace std; bool ParseIndices(std::string str, int& outIndex1, int& outIndex2); int main(int argc, char *argv[]){ //initalize s new grocery list GroceryList groceryList; string command; bool quit = false;
  • 9. while(!quit){ getline (cin, command); if(command == "print"){ groceryList.Print(cout); } else if(0== command.find("add")){ groceryList.AddWithUndo(command.substr(4)); } else if(0 == command.find("removeat")){ int index = stoi(command.substr(9)); groceryList.RemoveWithUndo(index); } else if(0 == command.find("swap")){ int index1 = -1, index2 = -1; if(ParseIndices(command.substr(5), index1,index2)){ groceryList.SwapWithUndo(index1, index2); } else if(command=="undo"){ if(0==grocerList.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 0; } bool ParseIndices(std::string str, int& outIndex1, int& outIndex2){ auto spaceIndex = str.find(" "); if(spaceIndex == strinh::npis){
  • 10. return false; } outIndex1 = stoi(str); outIndex2 = stoi(str.substr(spaceIndex +1)); return true; } the RemoveLastCommand class inherits from UndoCommand and is declared in RemoveLastCommand.h When a RemoveLastCommand object executed, the strinh vectors last element is removed. So when the user appends a new item in 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 user. RemoveLastCommands sourceVector member variable and constructir are already declared sourceVector is a pointer to a GroceryList objects vector of strings. The constructor takes a pointer to a vector of strings as a parameter, and assigns sourceVectors witb the pointer. implement RemoveLastCommandS Execute() member function to remove sourceVectors last element. c++ c++ class RemoveLastCommand : public UndoCommand{ private: std::vector* sourceVector; Public: RemoveLastCommand(std::vector* vector){ sourceVector = vector; } void Execute() override{ // code here }; #endif implement GroceryLists ExecuteUndo() member function to di following
  • 11. pop an UndoCommand off the undo stack Execute the popped undo command Delete the undo command File main.cpp had a code that reads in a list of commands one per line that allows for basic testing of basic operations. So after implementing ExecuteUndo() run program with the following input: add bananas add grapes add strawberries print undo print undo print quit verify that the ouput is 0. banana 1. grapes and so forth class GroceryList{ protected: std::vector listItems; std::stackundostack; public: virtual voif AddWithUndo(std:: string newItemName({ listItems.push_back(newItemName); //make an undo command that removes //the last item and push onto stack undoStack.push(new RemoveLastCommand(&listItem)); } virtual void RemoveAtWithUndo(int removalIndex){ //code here } void SwapWithUndo(int index1, int index2){ //code here } virtual void ExecuteUndo(){ if(!undoStack.empty()){ undoCommand* undoCommand = undoStack.top();
  • 12. undoStack.pop(); undo->Execute(); delet undoCommand; } } virtual int GetListSize() const{ return(int) listItems.size(); } virtual int GetUndoStackSize() const{ return(int) undoStack.size(); } virtual std:: vector GetVectorCopy() const{ return listItems; } virtuak void Print(std:: ostream& outputstream){ for(size_t i = 0; i < listItems.size(); i++){ outputstream <