Write a program for a retail store that only sells three (category) types of mer
ID: 3539219 • Letter: W
Question
Write a program for a retail store that only sells three (category) types of merchandises: Appliance, Kitchenware and Tool. This program shall use a structure to store the following inventory data in a file, name_of_your_choice.dat:
Item Description
The program should have a menuthat allows the user to perform the following tasks:
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.
The store would be very pleased to have a properly working program, no need to optimize for performance.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int size=20;
struct Info
{
char SKU[size];
string Category;
int Quantity;
double Cost;
string Date;
};
void getrecord(fstream &);
void displayrecord(fstream &);
void editrecord(fstream &);
void wholesaleitem(fstream &, char[]);
void wholesalecate(fstream &, string);
void quantityitem(fstream &);
int main()
{
Info record={"","",0,0.0,""};
fstream Info("name_of_your_choice.dat", ios::in | ios::out | ios::binary);
for(int i=0; i<20; i++)
{
Info.write(reinterpret_cast<char *>(&record),sizeof(record));
}
Info.close();
Info.open("name_of_your_choice.dat",ios::out | ios::binary);
int menu;
string cate;
char SKU[size];
const int enter = 1,
print = 2,
change = 3,
item = 4,
category = 5,
quantity = 6,
leave = 7;
do
{
cout << "Inventory Program. "
<< endl
<< "1) Add new records to the file. "
<< "2) Display any record in the file. "
<< "3) Change any record in the file. "
<< "4) Display total wholesale value of a particular item inventory. "
<< "5) Display total wholesale value of a particular category inventory. "
<< "6) Display total quantity of all items in the inventory. "
<< "7) leave "
<< "Selection: ";
cin >> menu;
cout<< endl;
switch (menu)
{
case enter:
{
getrecord(Info);
}
break;
case print:
{
displayrecord(Info);
}
break;
case change:
{
editrecord(Info);
}
break;
case item:
{
wholesaleitem(Info, SKU);
}
break;
case category:
{
wholesalecate(Info, cate);
}
break;
case quantity:
{
quantityitem(Info);
}
break;
}
}while (menu != leave);
Info.close();
system("pause");
return 0;
}
void getrecord(fstream &file)
{
cout <<"Please enter information ";
Info record;
fstream Info("name_of_your_choice.dat", ios::out | ios::binary);
cout<<"Enter SKU(Stock Keeping Unit): ";
cin.ignore();
cin.getline(record.SKU, size);
cout<<endl<<"Enter Category: ";
cin>>record.Category;
cout<<endl<<"Enter Quantity on Hand: ";
cin>>record.Quantity;
cout<<endl<<"Enter Wholesale Cost: ";
cin>>record.Cost;
cout<<endl<<"Date Added to Inventory(mm/dd/yyyy): ";
cin>>record.Date;
Info.write(reinterpret_cast<char *>(&record),sizeof(record));
cout<<"Record added to file."<<endl;
cout<<endl;
file.close();
}
void displayrecord (fstream &file)
{
Info record;
fstream Info("name_of_your_choice.dat", ios::out | ios::binary);
long i;
cout<<"Enter the record number of the item to view:";
cin>>i;
Info.seekg(i * sizeof(record), ios::beg);
Info.read(reinterpret_cast<char *>(&record),sizeof(record));
cout<<"Enter SKU(Stock Keeping Unit): "<<record.SKU<<endl;
cout<<"Enter Category: "<<record.Category<<endl;
cout<<"Enter Quantity on Hand: "<<record.Quantity<<endl;
cout<<"Enter Wholesale Cost($): "<<record.Cost<<endl;
cout<<"Date Added to Inventory(mm/dd/yyyy): "<<record.Date<<endl;
cout<<endl;
if(file.fail())
file.clear();
file.close();
}
void editrecord(fstream &file)
{
Info record;
fstream Info("name_of_your_choice.dat", ios::out | ios::binary);
long i;
cout << "Please enter the speaker you want to edit."<<endl;
cin >> i;
cout<<"Enter SKU(Stock Keeping Unit): ";
cin>>record.SKU;
cout<<endl<<"Enter Category: ";
cin>>record.Category;
cout<<endl<<"Enter Quantity on Hand: ";
cin>>record.Quantity;
cout<<endl<<"Enter Wholesale Cost: ";
cin>>record.Cost;
cout<<endl<<"Date Added to Inventory(mm/dd/yyyy): ";
cin>>record.Date;
cout<<endl;
Info.seekp(i * sizeof(record), ios::beg);
Info.write(reinterpret_cast<char *>(&record),sizeof(record));
Info.close();
}
void wholesaleitem(fstream &file,char SKU[size])
{
Info record;
fstream Info("name_of_your_choice.dat", ios::out | ios::binary);
double sum = 0;
while(!Info.eof())
{
Info.read(reinterpret_cast<char *>(&record),sizeof(record));
if(record.SKU == SKU)
{
sum += record.Cost;
}
}
cout<<"The total Wholesale Cost of the item "<<record.SKU<<" is : "<<sum<<endl;
if(file.fail())
file.clear();
file.close();
}
void wholesalecate(fstream &file,string category)
{
Info record;
fstream Info("name_of_your_choice.dat", ios::out | ios::binary);
double sum = 0;
while(!Info.eof())
{
Info.read(reinterpret_cast<char *>(&record),sizeof(record));
if(record.Category == category)
{
sum += record.Cost;
}
}
cout<<"The total Wholesale Cost of the Category "<<record.Category<<" is : "<<sum<<endl;
if(file.fail())
file.clear();
file.close();
}
void quantityitem(fstream &file)
{
Info record;
fstream Info("name_of_your_choice.dat", ios::out | ios::binary);
double sum = 0;
while(!Info.eof())
{
Info.read(reinterpret_cast<char *>(&record),sizeof(record));
sum += record.Quantity;
}
cout<<"The total Quantity of all items in the Inventory is "<<sum<<endl;
if(file.fail())
file.clear();
file.close();
}
i think it has error..
Explanation / Answer
add #include <stdlib.h> to resolve compilation error to include system function
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.