C++ code ONLY!!!! Inventory Items: We\'re going to do an inventory management sy
ID: 3911001 • Letter: C
Question
C++ code ONLY!!!!
Inventory Items:
We're going to do an inventory management system. In the real world, this would use a database, not a file. A single inventory item contains:
item names (or description), like "socks, - red" or "socks - blue". This has to be a character string that WILL include spaces.
item numbers that are unique to the item, similar to UPC codes, like 121821 or 128122. Even though they look like numbers, they are really character strings.
a price, like 4.99, a double.
a quantity on hand, like 13, an integer.
Your program will need to manage arrays of these items.
-----------------------------------------------------------------------------------
Menu:
Your code need to have the following features, all accessible from a menu.
Add a new inventory item to the data into the array in memory. You'll type in the inventory number, description, quantity and price. This will also update the number of items on the menu screen.
List the inventory (in the array in memory) on the screen in neat columns. Display it in chucks of 15 items with a pause in between.
Search the inventory (in the array in memory) for an item by inventory number. If found, print the stored info, otherwise print 'not found'.
Calculate the total value on hand of the inventory (in the array in memory). The sum is the accumulation of all the (quantities * prices).
Save the array in memory to a disk file. It can then be loaded later.
Read from a disk file to the array in memory. This will overwrite the array in memory with new information from the disk. If you data isn't saved, it will be lost. That how is SHOULD work!
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Menu Sample:
56 items stored
1) Add an item to memory
2) Search memory for an item
3) List what's in memory
4) Total value on hand
5) Save to a file
6) Read in from a file
0) Exit Program
Enter Choice:
-------------------------------------------------------------------------------------------------------------------
How to store the arrays: Parallel Arrays Option
You can maintain 4 arrays, one for each type. You will need to be careful to keep the items in the same position.
string descriptions[1000];
string idNumbers[1000];
float prices[1000];
int quantity[1000];
In this scenario, an item will be spread over the 4 arrays, but all at the same index.
------------------------------------------------------------------------------------------------------------------------------
How to store the data on the disk:
You are required to use the following text based format
Socks - Blue (in the inventory file)
74627204651538
4.99
27
Yellow Socks
25435567456723452345
7.99
27
Each individual item is stored in 4 separate lines. Records follow each other directly.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
class item
{
private:
char name[20];
int code[20];
float price[20];
int z;
public:
void add_(void);
void delete_(void);
void sell_(void);
void display_(void);
void initial(void){z=0;}
};
void item :: add_(void)
{
clrscr();
cout<<" Enter the item category : ";
cin>>name[z];
cout<<"Enter the item code : ";
cin>>code[z];
cout<<"Enter the price of the item: ";
cin>>price[z];
z++;
}
void item :: delete_(void)
{
int i,j;
clrscr();
cout<<" Please enter the item code:";
cin>>i;
for(j=0;j<z;j++)
{
if(code[j]==i)
{
price[j]=0;
cout<<" The item is deleted from the list.";
getch();
break;
}
}
}
void item :: sell_(void)
{
char a;
int i,j;
float total_price=0;
clrscr();
cout<<" Enter the item code:";
cin>>i;
for(j=0;j<z;j++)
{
if (code[j]==i)
{
if(price[j]==0)
{
cout<<" Sorry.There is no item left in this catefory.";
cout<<" Do you want to buy another item? y "<<endl;
cin>>a;
if (a=='y')
{
cout<<" Enter the item code:";
cin>>i;
j=-1;
}
else if (a=='Y')
{
cout<<" Enter the item code:";
cin>>i;
j=-1;
}
else
{
if (total_price!=0)
{
cout<<" Your total price is: ";
cout<<total_price<<" Taka."<<" Thank You.";
}
cout<<"Bye...bye...";
break;
}
}
else
{
cout<<"Item category is: "<<name[j];
cout<<" Item price is : "<<price[j]<<"tk."<<endl;
total_price+=price[j];
price[j]=0;
cout<<" Do you want to buy another item:y ";
cin>>a;
if (a=='y')
{
cout<<" Enter the item code:";
cin>>i;
j=-1;
}
else if (a=='Y')
{
cout<<" Enter the item code:";
cin>>i;
j=-1;
}
else
{ clrscr();
cout<<" Your total price is: ";
cout<<total_price<<"Taka."<<" Thank You.";
break;
}
}
}
}
getch();
}
void item :: display_()
{
int i,j=1;
clrscr();
for(i=0;i<z;i++)
{
cout<<j<<".Item category is: "<<name[i];
cout<<" Item code is : "<<code[i];
cout<<" Item price is : "<<price[i]<<"tk."<<endl<<endl;
j++;
}
getch();
}
int main ()
{
int i;
item shoping_mall;
clrscr();
shoping_mall.initial();
while(1)
{
cout<<" What do you want to do?"<<endl;
cout<<" 1: Add a new item.";
cout<<" 2: Delete an item.";
cout<<" 3: Sale an item.";
cout<<" 4: Display all items.";
cout<<" 5: Exit"<<endl;
cout<<" Choose a number:";
cin>>i;
switch(i)
{
case 1:
{
shoping_mall.add_();
break;
}
case 2:
{
shoping_mall.delete_();
break;
}
case 3:
{
shoping_mall.sell_();
break;
}
case 4:
{
shoping_mall.display_();
break;
}
case 5:
{
cout<<"Good Bye! Thank you.";
break;
}
}
if (i==5)
break;
clrscr();
}
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.