| |

Question: Code to Edit: #include “ListItem.h” #include #include #include usin – Free Chegg Question Answer

14.10 LAB: Grocery shopping list (list) Given a ListItem class, complete main() using the built-in list type to create a link

Code to Edit:

#include “ListItem.h”
#include
#include
#include

using namespace std;

int main (int argc, char* argv[]) {
// TODO: Declare a list called shoppingList of type ListItem

string item;

// TODO: Read inputs (items) and add them to the shoppingList list
// Read inputs until a -1 is input


// TODO: Print the shoppingList list using the PrintNodeData() function

return 0;
}

==============

VIEW ONLY PAGES:

ListItem.h

#ifndef LISTITEMH
#define LISTITEMH

#include

using namespace std;

class ListItem {
public:
ListItem();

ListItem(string itemInit);

// Print this node
void PrintNodeData();

private:
string item;
};

#endif

============

ListItem.cpp

#include “ListItem.h”
#include

ListItem::ListItem() {
item = “”;
}

ListItem::ListItem(string itemInit) {
item = itemInit;
}

// Print this node
void ListItem::PrintNodeData() {
cout << item << endl;
}

Transcribed text From Image: 14.10 LAB: Grocery shopping list (list) Given a ListItem class, complete main() using the built-in list type to create a linked list called shoppingList. The program should read items from input (ending with -1), adding each item to shoppingList, and output each item in shoppingList using the PrintNodeData function Ex. If the input is: milk broad eggs waffles cereal the output is: milk bread eggs waffles cereal
Current file: main.cpp Load default template... ONLY EDIT MAIN.CPP 1 #include "ListItem.h" 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 int main (int argc, char* argv[]) { 9 // TODO: Declare a list called shoppingList of type ListItem 10 11 string item; 12 13 // TODO: Read inputs (items) and add them to the shoppingList list 14 // Read inputs until a -1 is input 15 16 17 // TODO: Print the shoppingList list using the PrintNodeData() function 18 19 return 0; 20 }
File is marked as read only Current file: ListItem.h READ ONLY 1 #ifndef LISTITEMH 2 #define LISTITEMH 3 4 #include 5 6 using namespace std; 7 8 class ListItem { 9 public: 10 ListItem(); 11 12 ListItem(string itemInit); 13 14 // Print this node 15 void PrintNodeData(); 16 17 private: 18 string item; 19 }; 20 21 #endif
File is marked as read only Current file: Listltem.cpp READ ONLY !! ز 1 #include "ListItem.h" 2 #include 3 4 ListItem:: ListItem() { 5 item = 6 } 7 8 ListItem::ListItem(string itemInit) { 9 item = itemInit; 10 11 12 // Print this node 13 void ListItem: :PrintNodeData() { 14 cout

Expert Chegg Question Answer:

free chegg question answer
Smart Teacher From Answerie.com
Answer:

Answer


SOLUTION-
I have solve the problem in C++ code with screenshot for easy understanding 🙂

CODE-

Below is the complete main.cpp code

main.cpp –

#include “ListItem.h”
#include<string>
#include<list>
#include<iostream>

using namespace std;

int main(int argc, char const *argv[])
{
list<ListItem> shoppingList;
string item;
while(true){
getline(cin,item);
if(item==”-1″)
break;
ListItem l1(item);
shoppingList.push_back(l1);
}
for (auto it=shoppingList.begin(); it != shoppingList.end(); it++)
{
(*it).PrintNodeData();
}
return 0;
}


SCREENSHOT-

IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
—————-PLEASE RATE THE ANSWER———–THANK YOU!!!!!!!!———-


Free Chegg Question Answer

Leave a Reply

Your email address will not be published. Required fields are marked *