Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this. The question can be found here http://www.chegg.com/homew

ID: 3844252 • Letter: I

Question

 I need help with this. The question can be found here http://www.chegg.com/homework-help/questions-and-answers/assignment-ll-make-inventory-system-store-s-items-including-produce-books-starter-program--q9333691   #include <iostream> #include <string> #include <vector> #include <sstream> using namespace std;  class Item { public:     void SetName(string nm)//newName     { name = nm; };      void SetQuantity(int qnty)//new Quant     { quantity = qnty; };      void SetPrice(int prcInDllrs)     {  priceInDollars = prcInDllrs;}     //Total value of item     int GetTotalValueAsPrice()     {         return priceInDollars*quantity;     }      virtual void Print()     { cout << name << " " << quantity << endl; };      virtual ~Item()     { return; }; protected:     string name;     int  quantity;     int priceInDollars; };  class Produce : public Item { // Derived from Item class public:     void SetExpiration(string expir)     { expiration = expir; };     void Print()     { cout << name << " x" << quantity            << " for $" << priceInDollars //step1            << " (Expires: " << expiration << ")"            << endl;     }; private:     string expiration; };  //Derived book class: Step 2 class Book : public Item { public:     //Set the author's name     void SetAuthor(string authr)     {         author = authr;     };     //Print book information     void Print()     {         cout << name << " x" << quantity              << " for $" << priceInDollars //step1              << " (Author: " << author << ")"              << endl;     }; private:     string author; }; class Inventory { public:     void PrintInventory(vector<Item *> inventory) {         int k1 = 0;         int totalInventory;//int totalInvPriceInDollars         if (inventory.size() == 0) {             cout << "Inventory is empty." << endl;         } else {             for (k1 = 0; k1 < inventory.size(); ++k1) {                 cout << k1 << " - ";                 inventory.at(k1)->Print();             }             cout << "Total inventory value: $" << totalInventory << endl;         }      };  //private: //    vector<Item*> inventory; //    int totalInventory; //    //Calculate total price of items. //    void SumInv() //    { //        totalInventory=0; //        for(int k1= 0; k1<inventory.size(); ++k1) //        { //            totalInventory+=inventory.at(k1)->GetTotalValueAsPrice(); //        } //    } //};  //// Dialogue to create a new item, then add that item to the inventory     vector<Item *> AddItemToInventory(vector<Item *> inventory) {         Produce *prdc;         Book *book;         string usrInptName = "";         string usrInptQntyStr = "";         istringstream inSS;         int inputPrice = 0;         int usrInptQnty = 0;         string usrInptExpr = "";         string usrIndexChoice = " ";         string bookAUTHOR = "";         string bookTITLE = "";  //Get user choice of adding either a book or produce         do {             cout << "Enter choice of adding (b)ook or (p)roduce: ";             getline(cin, usrIndexChoice);             if (usrIndexChoice != "b" && usrIndexChoice != "p") {                 cout << "Invalid Choice" << endl;             }         } while (usrIndexChoice != "b" && usrIndexChoice != "p");          //Add new produce         if (usrIndexChoice == "p") {             //Info needed for new produce             cout << "Enter new produce name: ";             getline(cin, usrInptName);              cout << "Enter quantity: ";             getline(cin, usrInptQntyStr);             inSS.str(usrInptQntyStr);             inSS >> usrInptQnty;             inSS.clear();              cout << "Enter expiration date: ";             getline(cin, usrInptExpr);              cout << "Enter the price per item : $";             cin >> inputPrice;              prdc = new Produce;             prdc->SetName(usrInptName);             prdc->SetQuantity(usrInptQnty);             prdc->SetExpiration(usrInptExpr);             prdc->SetPrice(inputPrice);              inventory.push_back(prdc);              return inventory;         }          //Adding new book to inventory         if (usrIndexChoice == "b") {             //Get book info             cout << "Enter name of new book: ";             getline(cin, bookTITLE);              cout << "Enter quantity: ";             getline(cin, usrInptQntyStr);             inSS.str(usrInptQntyStr);             inSS >> usrInptQnty;             inSS.clear();              cout << "Enter author: ";             getline(cin, bookAUTHOR);              cout << "Enter price per item: $";             cin >> inputPrice;              book = new Book;             book->SetName(bookTITLE);             book->SetQuantity(usrInptQnty);             book->SetAuthor(bookAUTHOR);             book->SetPrice(inputPrice);             //Add book to inventory vector             inventory.push_back(book);              return inventory;             // };             // SumInv();         }   //// Dialogue to update the quantity of an item, then update that item in the inventory         vector<Item *> UpdateItemQtyInInventory(vector<Item *> inventory) {             string usrIndexChoiceStr = "";             unsigned int usrIndexChoice = 0;             istringstream inSS;             string usrInptQntyStr = "";             int usrInptQnty = 0;              if (inventory.size() == 0) {                 cout << "No items to update." << endl;             } else {                 PrintInventory(inventory);                  do {                     cout << "Update which item #: ";                     getline(cin, usrIndexChoiceStr);                     inSS.str(usrIndexChoiceStr);                     inSS >> usrIndexChoice;                     inSS.clear();                 } while (!(usrIndexChoice < inventory.size()));                  cout << "Enter new quantity: ";                 getline(cin, usrInptQntyStr);                 inSS.str(usrInptQntyStr);                 inSS >> usrInptQnty;                 inSS.clear();                  inventory.at(usrIndexChoice)->SetQuantity(usrInptQnty);             };             // SumInv();             return inventory;         } //// Dialogue to remove a specific item, then remove that specific item from the inventory         vector<Item *> RemoveItemFromInventory(vector<Item *> inventory) {             istringstream inSS;             string usrIndexChoiceStr = "";             unsigned int usrIndexChoice = 0;             string usrInptQntyStr = "";              if (inventory.size() == 0) {                 cout << "No items to remove." << endl;             } else {                 PrintInventory(inventory);                  do {                     cout << "Remove which item #: ";                     getline(cin, usrIndexChoiceStr);                     inSS.str(usrIndexChoiceStr);                     inSS >> usrIndexChoice;                     inSS.clear();                 } while (!(usrIndexChoice < inventory.size()));                  inventory.erase(inventory.begin() + usrIndexChoice);                  //SumInv();                  return inventory;             }             private:             vector<Item *> inventory;             int totalInventory;             //Calculate total price of items.             void SumInv() {                 totalInventory = 0;                 for (int k1 = 0; k1 < inventory.size(); ++k1) {                     totalInventory += inventory.at(k1)->GetTotalValueAsPrice();                 }             }         };          int main() {             vector<Item *> inventory;             string usrInptOptn = "default";              while (true) {                 // Get user choice                 cout << " Enter (p)rint, (a)dd, (u)pdate, (r)emove, or (q)uit: ";                 getline(cin, usrInptOptn);                  // Process user choice                 if (usrInptOptn.size() == 0) {                     continue;                 } else if (usrInptOptn.at(0) == 'p') {                     PrintInventory(inventory);                 } else if (usrInptOptn.at(0) == 'a') {                     inventory = AddItemToInventory(inventory);                 } else if (usrInptOptn.at(0) == 'u') {                     inventory = UpdateItemQtyInInventory(inventory);                 } else if (usrInptOptn.at(0) == 'r') {                     inventory = RemoveItemFromInventory(inventory);                 } else if (usrInptOptn.at(0) == 'q') {                     cout << " Good bye." << endl;                     break;                 }             }              return 0;         }     } } 

Explanation / Answer

#include #include #include #include using namespace std; class Item { public: void SetName(string nm)//newName { name = nm; }; void SetQuantity(int qnty)//new Quant { quantity = qnty; }; void SetPrice(int prcInDllrs) { priceInDollars = prcInDllrs;} //Total value of item int GetTotalValueAsPrice() { return priceInDollars*quantity; } virtual void Print() { cout