Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, youll make an inventory system for a stores items, including produce and books. The starter program is an inventory system for only

 

In this assignment, youll make an inventory system for a stores items, including produce and books. The starter program is an inventory system for only produce.

Include the price of an item by adding to the Item class the protected data member int priceInDollars that stores the price in dollars of an individual item.

Write a public function SetPrice with a single int parameter prcInDllrs and returns nothing. SetPrice assigns the value of prcInDllrs to priceInDollars.

Modify the AddItemToInventory to prompt the user to Enter the price per item: $, then set the Produces price to the userentered value.

Modify Produces Print function output to include the items individual price. Here is an example output for 20 grape bundles at $3 each that expire on May 22.

Grape bundle x20 for $3 (Expires: May 22)

Add a new class Book that derives from Item. The Book class has a private data member that is a string named author. The Book class has a public function member SetAuthor with the parameter string authr that sets the private data member authors value. SetAuthor returns nothing.

The class Book overloads the Print member function with a similar output as the Produces Print function, except Expires is replaced with Author and the variable expiration is replaced with author. Here is an example output for 22 copies of To Kill a Mockingbird by Harper Lee that sells for $5 each:

To Kill a Mockingbird x22 for $5 (Author: Harper Lee)

Modify the AddItemToInventory function to allow the user to choose between adding a book (b) and produce (p). If the user does not enter b or p, then output Invalid choice then return the AddItemToInventory function.

Create a class named Inventory. The Inventory class should have one private data member:

vector inventory. The Inventory class has four public function members that have no parameters and return nothing: PrintInventory, AddItemToInventory, UpdateItemQtyInInventory, and RemoveItemFromInventory.

Development suggestion:

First convert only the PrintInventory function to be a member function of Inventory with the other functions disabled (commented out). Then, convert the other functions one by one.

Add to the Inventory class a private data member int totalInvPriceInDollars that stores the total inventory price in dollars.

Write a private member function SumInv in Inventory class that has no parameters and returns nothing. The SumInv function should set the total inventory value as a price in dollars. Since the Inventory class cannot access an Items quantity and priceInDollars, youll need to write a public member function GetTotalValueAsPrice to the Item class that returns the multiplication of the Items quantity and priceInDollars.

The SumInv function should be called at the end (but before the return statement) of each Inventory member function that modifies the inventory: AddItemToInventory, UpdateItemQtyInInventory, and RemoveItemFromInventory.

Modify the PrintInventory function to also output the total inventory value in dollars. Here is an example:

0 Grapes x2 for $3 (Expires: May)

1 To Kill a Mockingbird x4 for $5 (Author: Harper Lee) Total inventory value: $26

Here is an example program execution (user input is highlighted here for clarity):

Enter (p)rint, (a)dd, (u)pdate, (r)emove, or (q)uit: a Enter choice of adding (b)ook or (p)roduce: p

Enter name of new produce: Grape bundle Enter quantity: 20

Enter expiration date: May 12 Enter the price per item: $2

Enter (p)rint, (a)dd, (u)pdate, (r)emove, or (q)uit: p

0 - Grape bundle x20 for $2 (Expires: May 12) Total inventory value: $40

Please help!Here is what I have so far:

 #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 << 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 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 inventory; int totalInventory; //Calculate total price of items. void SumInv() { totalInventory=0; for(int k1= 0; k1GetTotalValueAsPrice(); } } }; //// Dialogue to create a new item, then add that item to the inventory vector AddItemToInventory(vector 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 UpdateItemQtyInInventory(vector 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 RemoveItemFromInventory(vector 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 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 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; } } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Big Data Interview 751 Comprehensive Questions And Expert Answers

Authors: Mr Bhanu Pratap Mahato

1st Edition

B0CLNT3NVD, 979-8865047216

More Books

Students also viewed these Databases questions

Question

What does the term deferral mean?

Answered: 1 week ago