{
int pID;
char name [50];
float price, qty;
public:
void create_product ()
{
cout<<"\nPlease Enter The Product ID of the product ";
cin>>pID;
cout<<"\nPlease enter the Name of the Product";
gets(name);
cout<<"\nPlease enter the price of the Product";
cin>>price ;
}
void show_product()
{
cout<<"\nThe Product ID of the Product :"<<pID;
cout<<"\nThe Name of the product :";
puts(name);
}
int retpID()
{return pID; }
float retprice()
{return price;}
char* retname()
{return name;}
};
//declaration for the stream object
fstream fp;
product pr;
//function to write in file
void write_product();
{
fp.open("Shop.dat",ios::|ios::app);
pr.create_product();
fp.write((char*)&pr,sizeof(product));
fp.close();
cout<<"\n\nTHE PRODUCT HAS BEEN CREATED";
system("pause");
}
//functions to read records form file
void display_all()
{
system("cls");
cout<<"\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n";
fp.open("Shop.dat",ios::in);
while(fp.read((char*)&pr,sizeof(product)))
{
pr.show_product();
cout<<"\n\n==========================\n";
system("pause");
}
fp.close();
system("pause");
}
//function to read specific record from file
void display_sp(int n)
{
int flag=0;
fp.open("Shop.dat",ios::in);
while(fp.read((char*)&pr,sizeof(product)))
{
if (pr.retpID()==n)
{
system("cls");
pr.show_product();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<"\n\nrecord not exist";
system("pause");
}
//function to modify record of file
void modify_product();
{
int no, found=0;
system("cls");
cout<<"\n\nTo Modify";
cout<<"\n\n\tPlease Enter the Product ID of the product";
cin>>ID;
fp.open("Shop.dat",ios::in|ios::out);
while(fp.read((char*)&pr,sizeof(product))&& found==0)
{
if(pr.retpID()==ID)
{
pr.show_product();
cout<<"\nPlease Enter The New Details Of Product"<<endl;
pr.create_product();
int pos=-1*sizeof(pr);
fp.seekp(pos,ios::cur);
fp.write((char*)&pr,sizeof(product));
cout<<"\n\n\tRECORD UPDATED";
found=1;
}
fp.close();
if(found==0)
cout<<"\n\nRECORD NOT FOUND";
system("pause");
}
}
//function to delete record of file
void delete_product()
{
int no;
system ("cls");
cout<<"\n\n\nDelete Record";
cout<<"\n\nPlease Enter the Product ID of the product You want to delete";
cin>>ID;
fp.open("Shop.dat",ios::in|ios::out);
fstream.fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&pr,sizeof(product)))
{
if(pr.retpID()!=ID)
{
fp2.write((char*)&pr,sizeof(product));
void menu()
{
system("cls");
fp.open("Shop.dat",ios::in);
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN\n\n\nGO TO ADMIN MENU TO CREATE FILE";
cout<<"\n\n\n:::Program is Closing:::";
system("pause");
exit(0);
//function to place order and generate bill for products
void place_order()
{
int order_arr[50],quan[50],c=0;
float amt,total=0;
char ch='Y';
menu();
cout<<"\n=======================";
cout<<"\n STATE YOUR ORDER ";
cout<<"\n=======================";
do
{
cout<<"\n\nEnter The Product ID of the product :";
cin>>order_arr[c];
cout<<"\nQuantity in number :";
cin>>quan[c];
c++;
cout<<"\nDo You Want Another Product ? (y/n)";
cin>>ch;
}while (ch=='y'||ch=='Y');
cout<<"\n\nThank You For Placing The Order";
system("cls");
system("pause");
cout<<"\n\n******INVOICE*********\n";
cout<<"\nPr ID \tPr Name\tQuantity\tAmount\tAmount after %\n";
for(int x=0;x<=c;x++)
{
fp.open("Shop.dat",ios::in);
fp.read((char*)&pr,sizeof(product));
while(!fp.eof())
{
if(pr.retpID()==order_arr[x])
{
amt=pr.retprice()*quan[x];