C++ Assignment Write a menu-driven program that will (1) create, update and disp
ID: 3721119 • Letter: C
Question
C++ Assignment
Write a menu-driven program that will (1) create, update and display inventory data using an Inventory class, (2) create a binary Transaction file, (3) apply the transactions against the inventory, and (4) calculate a profit projection for inventory items.
Requirements
Create file InventoryClass.h which defines InventoryClass that has the following members:
A member variable for the item id (an integer)
A member variable for up to a 50 character the item description
A member variable for holding the quantity of items on hand
A constructor and the appropriate set and get functions
A print function that displays the item id, description, and quantity on hand
Feel free to add any additional member functions you might need.
Create file InventoryCostClass.h which defines InventoryCostClass that is derived from InventoryClass. The InventoryCostClass should have the following members:
A member variable for wholesale cost (a double)
A member variable for retail price (a double)
A member variable for the inventory update date in the format mm/dd/yyyy
A constructor and the appropriate set and get functions
A print function that overrides the print function in the base class. The InventoryCostClass’s print function should invoke the InventoryClass’s print function and then display the wholesale cost, retail price, and inventory update date
Feel free to add any additional member functions you might need.
In the main function, the program will repeatedly display a menu containing several options:
Store the Inventory: In main, create a size 50 array (using dynamic allocation) of Inventory objects. In a function, have the user enter the inventory data. Validate the data as follows: the item ID is 6 digits, each cost and price is greater than zero, and wholesale cost is less than retail price.
Create Transactions: in the second function, create a binary Transaction file containing multiple sets of 3 elements:
-item ID-6 digits
-transaction code (AI-add to inventory; RI-reduce from inventory; CW-change wholesale cost; CR-change retail price; CD-change item description)
-transaction data (for AI and RI-integers; for CW and CR-double; for CD-up to 50 characters)
Have the user enter the binary file name (of your choosing) in main, but open the binary file in the second function. Also have the user enter the data for the binary file in the function. Validate the transaction data as described above.
Update Inventory: in a function, match the transactions in the binary file to the array of Inventory objects and update the array of objects (remember to update the date field with today's date if the quantity is changed).
Display Inventory: in a function, display the updated Inventory data.
Compute a Profit Projection: in a function, have the user enter the item id for a which profit projection is desired. Compute the profit projection using the formula ((retail price * quantity on hand) – (wholesale cost * quantity on hand)). Display the Item ID, item description, profit projection.
End Program.
Explanation / Answer
#include <iostream>
using namespace std;
class inventory
{
private:
int productNum[10];
int productCount[10];
double productPrice[10];
public:
int locator;
void retrieve();
void init();
void store();
}inv1;
void setItemNumber(int &temp)
{
do
{
cout << " Please enter the item number (if finished please enter '0'): ";
cout << " Number must be positive: " << endl;
cin >> temp;
} while (temp < 0);
}
void setQuantity(int &temp)
{
do
{
cout << " Please enter the Quantity: ";
cout << " Number must be positive: " << endl;
cin >> temp;
} while (temp < 0);
}
void setPrice(double &price)
{
do
{
cout << " Please enter the Price: ";
cout << " Number must be positive: " << endl;
cin >> price;
} while (price < 0);
}
void inventory :: init()
{
int counter = 0;
while (counter < 10)
{
productCount[counter] = 0;
productNum[counter] = 0;
productPrice[counter]= 0;
counter++;
locator = counter;
}
}
void inventory :: store()
{
int counter = 0, temp = 0;
double price = 0;
cout << " Welcome to the inventory control system" << endl;
cout << "When finished please enter '0' for the item number" << endl;
while (counter < locator)
{
setItemNumber(temp);
if(temp == 0)
{
locator = counter;
return;
}
productNum[counter]=temp;
setQuantity(temp);
productCount[counter]=temp;
setPrice(price);
productPrice[counter]=price;
counter++;
}
}
void inventory :: retrieve()
{
int counter = 0;
double total = 0;
cout << "Product Number Product Count Price" << endl;
cout << "_______________________________________________________" << endl;
while (counter < locator)
{
cout << productNum[counter];
cout << " " << productCount[counter];
cout << " " << productPrice[counter] << endl;
total = productCount[counter] * productPrice[counter] + total;
counter++;
}
cout << "Your total inventory is valued at: $" << total << endl;
}
int main()
{
inv1.init();
inv1.store();
inv1.retrieve();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.