Professional Documents
Culture Documents
#include<fstream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
#include<ctype.h>
#include<stdlib.h>
#include<process.h>
#include<stdio.h>
#include<string.h>
void home();
cout<<code<<"\t\t";
cout<<decsy<<" \t\t\t";
cout<<price<<"\t\t";
cout<<cat<<"\t\t";
cout<<qon;
cout<<endl<<endl;
}
fstream fb;
fstream fp;
fb.open("product.dat",ios::in|ios::binary);
fp.open("basket.dat",ios::app|ios::binary);
shop s;
fb.read((char *)&s,sizeof(s));
do
{
if(p==s.code)
{
s.dispdata();
s.qon--;
cout<<"\n";
cout<<endl;
fp.write((char *)&s,sizeof(s));
}
fb.read((char *)&s,sizeof(s));
}while(fb);
fb.close();
fp.close();
}
if(r!=s.code)
{
ft.write((char *)&s,sizeof(s));
}
else
{
flag++;
}
fb.read((char *)&s,sizeof(s));
}while(fb);
fb.close();
ft.close();
if(flag==0)
cout<<"No such item\n\n";
else
{
cout<<"\nITEM HAS BEEN DELETED\n\n";
}
remove("product.dat");
rename("tempu.dat","product.dat");
cout<<"\n\nTo move back, press 0\n ";
cout<<"To delete more product, press any other digit\n";
int d;
cin>>d;
if(d==0)
return;
else
delfile();
fb.read((char *)&s,sizeof(s));
do
{
if(r==s.code)
{
cout<<"Old data is \n \n ";
cout<<" CODE ";
cout<<" NAME ";
cout<<" PRICE ";
cout<<" CATEGORY ";
cout<<" QUANTITY\n\n\n";
s.dispdata();
cout<<"Enter new data\n";
getch();
s.getdata();
ft.write((char *)&s,sizeof(s));
}
else
{
ft.write((char *)&s,sizeof(s));
cout<<"\nNo such item exists\n";
cout<<"\nPress enter to go back";
getch();
return;
}
getch();
fb.read((char *)&s,sizeof(s));
}while(fb);
ft.close();
fb.close();
remove("product.dat");
rename("tempu.dat","product.dat");
cout<<"\n\nTo move back, press 0\n";
int d;
cin>>d;
if(d==0)
return;
}
break;
case 2:
delfile2();
break;
case 3:
exit(0);
}
}
void stock()
{
clrscr();
int r;
char rep;
shop s;
cout<<"Enter the item code u want to update\n\n";
cin>>r;
fstream fb,ft;
fb.open("product.dat",ios::in|ios::binary);
ft.open("tempu2.dat",ios::out|ios::binary);
fb.read((char *)&s,sizeof(s));
do
{
if(r==s.code)
{
cout<<"\n\nOld quantity is ";
cout<<s.qon;
else
{
ft.write((char *)&s,sizeof(s));
cout<<"\nNo such item exists\n";
cout<<"\nPress enter to go back";
getch();
return;
}
getch();
fb.read((char *)&s,sizeof(s));
}while(fb);
ft.close();
fb.close();
remove("product.dat");
rename("tempu2.dat","product.dat");
cout<<"\n\nTo move back, press 0\n";
int d;
cin>>d;
if(d==0)
return;
}
void delfile2() //To delete product from basket
{
int r;
char rep;
shop s;
cout<<"Enter the item code u want to delete\n\n";
cin>>r;
fstream fb,ft;
fb.open("basket.dat",ios::in|ios::binary);
fb.open("tempu1.dat",ios::out|ios::binary);
int flag=0;
fb.read((char *)&s,sizeof(s));
do
{
if(r!=s.code)
{
ft.write((char *)&s,sizeof(s));
}
else
{
flag++;
}
fb.read((char *)&s,sizeof(s));
}while(fb);
ft.close();
fb.close();
if(flag==1)
{
cout<<"ITEM DELETED";
cout<<"No. of items deleted are "<<flag;
}
else
cout<<"\n NO ITEMS DELETED ";
remove("basket.dat");
rename("tempu1.dat","basket.dat");
cout<<"\n\nTo Generate bill press 0";
int d;
cin>>d;
if(d==0)
return;
}
fstream fp;
fp.open("product.dat",ios::in|ios::binary);
clrscr();
fp.read((char *)&t,sizeof(t));
cout<<endl<<endl;
cout<<"CODE DESCRIPTION PRICE CATEGORY QUANTITY "<<endl;
cout<<endl<<endl;
do
{
if(t.cat==1)
t.dispdata();
fp.read((char *)&t,sizeof(t));
}while(fp);
fp.close();
int toad,l,m;
cout<<"To return back, press 2, to buy press 1\n\n";
cin>>l;
if(l==2)
return;
else
{
int ch;
do
{
cout<<"\nTo buy the product, enter the product code from the list\n\n";
cin>>toad;
basket(toad);
cout<<"\nThe product you have chosen has been added to your basket\n\n";
cout<<"\n\nTo Continue your shopping press 1, To go to homepage, press 2\n\n";
cin>>ch;
}while(ch!=2);
}
}
void jwellery() //jwellery section
{
shop t;
fstream fp;
fp.open("product.dat",ios::in|ios::binary);
clrscr();
fp.read((char *)&t,sizeof(t));
cout<<endl<<endl;
cout<<"CODE DESCRIPTION PRICE CATEGORY QUANTITY "<<endl;
cout<<endl<<endl;
do
{
if(t.cat==3)
t.dispdata();
fp.read((char *)&t,sizeof(t));
}while(fp);
fp.close();
int toad,l,m;
cout<<"To return back, press 2, to buy press 1\n\n";
cin>>l;
if(l==2)
return;
else
{
int ch;
do
{ cout<<"\nTo buy the product, enter the product code from the list\n\n";
cin>>toad;
basket(toad);
cout<<"\nThe product you have chosen has been added to your basket\n";
cout<<"\n\nTo Continue your shopping press 1, To go to homepage, press 2\n\n";
cin>>ch;
} while(ch!=2);
}
void home()
{
textbackground(RED);
textcolor(BLACK);
fstream fp;
fp.open("basket.dat",ios::out|ios::binary);
fp.close();
int ch;
do
{
clrscr();
cout<<"\n\n--------------------------------------------------------------------------------";
cout<<" WELCOME TO ONLINE BAZAAR\n";
cout<<"--------------------------------------------------------------------------------";
char *pass;
gotoxy(12,12);
pass = getpass("Input the password:");
if(strcmp(pass,"1234")==0)
admin();
else
cout<<"\n\nwrong password\n\n";
getch();
break;
case 2:
shopping();
break;
case 3:
bill();
break;
case 4:
exit(0);
break;
}
}while(ch!=4);
}