Write a program that uses a structure to store the following inventory data in a
ID: 3626643 • Letter: W
Question
Write a program that uses a structure to store the following inventory data in a file:
Item description
Quantity on hand
Wholesale cost
Retail cost
Date added to inventory
The program should have a menu that allows the user to perform the following tasks:
• Add new records to the file.
• Display any record in the file.
• Change any record in the file.
Input Validation: The program should not accept quantities, or wholesale or retail costs less than 0. The program should not accept dates that the programmer determines are unreasonable.
Explanation / Answer
i see that maybe u didn`t get the idea from my previous answer i wrote most of the program using a struct and the function i gave to u .
what is left is just to make an ofstream variable and write the information to it if u don`t know how to do that message me and i will tell u how to do it :)
please rate and i am sure this is at least helpful
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
struct inventory
{
string Item[20];
int Quantity[20] ;
int Wholesale[20];
int Retail[20] ;
string Date[20] ;
};
void main()
{
inventory lists;
static string list[20];
static int amount[20];
string item;
int count=0;
int choise=0;
int j=0;
char c;
string date;
while (choise !=4)
{
cout<<"enter a choise from the lsit"<<endl;
cout<<"1: Add new records to the file. 2: remove any record in the file. 3: Display any record in the file. (4)Quit"<<endl;
cin>>choise;
if(choise ==1)
{
cout<<"type the item name "<<endl;
cin>>(lists.Item[count]);
item=lists.Item[count];
while (item[j])//to get it to upper string
{
c=item[j];
putchar (toupper(c));
j++;
}
lists.Item[count]=item;
cout<<" enter the quantity"<<endl;
cin>>(lists.Quantity[count]);
cout<<"enter the wholesale cost"<<endl;
cin>>lists.Wholesale[count];
cout<<"enter the retail cost"<<endl;
cin>>lists.Retail[count];
cout<<"enter the date the item was added in form(1/1/1111)"<<endl;
cin>>date;
lists.Date[count]=date;
if(lists.Quantity[count] <0)
{
while(lists.Quantity[count] <0)
{
cout<<"quantity is less than acceptble "<<endl;
cin>>lists.Quantity[count];
}
}
if(lists.Wholesale[count] <0)
{
while(lists.Wholesale[count] <0)
{
cout<<"Wholesale is less than acceptble "<<endl;
cin>>lists.Wholesale[count];
}
}
if(lists.Retail[count] <0)
{
while(lists.Retail[count] <0)
{
cout<<"Retail is less than acceptble "<<endl;
cin>>lists.Retail[count];
}
}
count++;
}
else if(choise ==2)
{
cout<<"type the item"<<endl;
cin>>item;
j=0;
while (item[j])//to get it to upper string
{
c=item[j];
putchar (toupper(c));
j++;
}
for(int i=0;i<count;i++)
if(item == (lists.Item[i]))
{
lists.Item[i]="";
lists.Item[i]=lists.Quantity[i]=lists.Retail[i]=lists.Wholesale[i]=0;
lists.Date[i]="";
}
else cout<<"the item "<<item<<" is not in the list"<<endl;
}
else if(choise == 3)
{
cout<<"please enter the name of the item you the record for"<<endl;
cin>>item;
j=0;
while (item[j])//to get it to upper string
{
c=item[j];
putchar (toupper(c));
j++;
}
for(int i=0;i<count;i++)
if(item == (lists.Item[i]))
{
cout<<" Item "<<lists.Item[i] <<endl <<"Quantity "<<lists.Quantity[i]<<endl <<"Retail "<<lists.Retail[i]<<endl
<<"Wholesale "<<lists.Wholesale[i]<<endl;
cout<<"date added "<<lists.Date[i]<<endl;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.