You are on page 1of 14

//Project on ONLINE SHOPPING #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(); class purchase //Class to declare product code { //Quantity,price and description public: long int code; long int price; }; class shop //Class to declare { //variables needed in shopping public: long int code; char decsy[20]; long float price; int cat; long int qon; void dispdata(); void getdata() //Member function { //to accept data clrscr(); cout<<"\n\n\nEnter the category number\n\n1 for electronics"; cout<<"\n\n\n2 for vehicles\n\n\n3 for jwellery\n\n\nEnter ur choice "; cin>>cat; cout<<endl; clrscr(); cout<<"Enter the code no of the item\n\n"; cin>>code; cout<<endl; cout<<"Enter description\n\n"; gets(decsy); cout<<endl; cout<<"Enter the price\n\n"; cin>>price; cout<<endl;

cout<<"Enter the quantity\n"; cin>>qon; cout<<"Data has been entered"; } }; void shop::dispdata() { cout<<code<<"\t\t"; cout<<decsy<<" \t\t\t"; cout<<price<<"\t\t"; cout<<cat<<"\t\t"; cout<<qon; cout<<endl<<endl; } void basket(int p) { 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(); } //To add products to basket //for bill generation //To display data

void main() { home(); }

//Main function

void create1() //To create file initially { clrscr(); cout<<"\n\n"; shop s; fstream fb; fb.open("product.dat",ios::out|ios::binary); char rep; do { s.getdata(); fb.write((char *)&s,sizeof(s)); cout<<"\n\n\t Want to add more records"; cin>>rep; }while(rep=='y' || rep=='Y'); fb.close(); getch(); }

void addfile() //To add to file { clrscr(); cout<<"\n\n"; shop s; fstream fb; fb.open("product.dat",ios::app|ios::binary); char rep; do { s.getdata(); fb.write((char *)&s,sizeof(s)); cout<<"\n\n\tWant to add more records"; cin>>rep; }while(rep=='y' || rep=='Y'); fb.close(); getch(); } void delfile() { clrscr(); int r; //To delete products

char rep; shop s; cout<<" \n\n\nEnter the item code u want to delete\n\n"; cin>>r; fstream fb,ft; fb.open("product.dat",ios::in|ios::binary); ft.open("tempu.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); 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(); } void modfile() { //To modify product

clrscr(); int r; char rep; shop s; cout<<"Enter the item code u want to modify\n\n"; cin>>r; fstream fb,ft; fb.open("product.dat",ios::in|ios::binary); ft.open("tempu.dat",ios::out|ios::binary); 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; } void bill() //function to generate bill { clrscr(); void delfile2(); shop s; fstream fj; fj.open("basket.dat",ios::in|ios::binary); cout<<"\nYour basket has following items\n\n"; cout<<" NAME CODE PRICE\n\n\n"; int sum=0; fj.read((char *)&s,sizeof(s)); do { cout<<s.decsy<<" "<<s.code<<" cout<<"\n\n"; sum+=s.price; fj.read((char *)&s,sizeof(s)); }while(fj); fj.close(); int choice; getch(); clrscr();

"<<s.price;

cout<<"\n\n\nTo generate your bill, press 1\n"; cout<<"\nTo delete some item, press 2\n"; cout<<"\nTo reject full order and exit, press 3\n\n"; cout<<"Enter your choice "; cin>>choice; switch(choice) { case 1: char add[150]; cout<<"\n\nYour bill amount is---- Rs"<<sum; float tax=.008*sum; cout<<"\n\nTax on your billed amount is Rs "<<tax; cout<<"\n\nTotal round figure bill is Rs "<<sum+tax; getch(); cout<<"\nEnter your residence address\n "; gets(add); cout<<"Your product will be delivered to you within 2 days\n"; cout<<"Please ensure the full payment of bill at the time of delivery\n"; getch(); 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; cout<<"\n\nEnter new quantity\n"; getch(); cin>>s.qon; ft.write((char *)&s,sizeof(s)); cout<<"\n\nNew quantity has been registered\n"; } 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; }

void electronics() { shop t;

//Electronics section

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 vehicles() //vehicles 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 "; cout<<"DESCRIPTION "; cout<<"PRICE "; cout<<"CATEGORY "; cout<<"QUANTITY"; cout<<endl<<endl; do {

if(t.cat==2) 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 chose has been added to your basket"; cout<<"\n\nTo Continue your shopping press 1, To go to homepage, press 2\n\n"; cin>>ch; } while(ch!=2); } }

void shopping() //main menu for shopper { clrscr(); int w; cout<<"\n\n\n--------------------------------------------------------------------------------"; cout<<" WELCOME TO ONLINE BAZAAR\n"; cout<<"--------------------------------------------------------------------------------"; cout<<" \n\n !!!!!! PAISA VASOOL!!!!!\n"; cout<<" \n ####CATAGORIES#####\n\n"; cout<<" \n1. ELECTRONICS\n\n"; cout<<" \n2. VEHICLES\n\n"; cout<<" \n3. JWELLERY\n\n"; cout<<" \n4. BACK\n"; cout<<endl<<endl<<"Enter your choice"; cin>>w; switch(w) //to select category { case 1: electronics(); break;

case 2: vehicles(); break; case 3: jwellery(); break; case 4: home(); break; } } void admin() //administration section { int c; do { clrscr(); cout<<endl<<endl<<endl<<endl; cout<<" \t\t\t Hello Administrator\n\n "; cout<<"\n\t\tChoose from the Menu options \n\n"; cout<<"\t\t1. CREATE FOR FIRST TIME (This will erase all previous data)\n\n\n"; cout<<"\t\t2. ADD PRODUCT \n\n\n"; cout<<"\t\t3. DELETE A PRODUCT \n\n\n"; cout<<"\t\t4. MODIFY\n\n\n"; cout<<"\t\t5. STOCK UPDATION\n\n\n"; cout<<"\t\t6. BACK\n\n\n"; cout<<"\t\tEnter your choice ---- "; cin>>c; switch(c) { case 1: char ch; clrscr(); cout<<"\n\n\tAre you sure to erase all previous data if there?(y/n)\n"; cin>>ch; if(ch=='y') create1(); else return; break; case 2: addfile(); break; case 3: delfile(); break; case 4:

modfile(); break; case 5: stock(); break; case 6: return; } }while(c!=5); } 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<<"--------------------------------------------------------------------------------"; cout<<" \n !!!!!! PAISA VASOOL!!!!!\n"; cout<<" \n\n\t\t ####CATEGORIES#####\n\n"; cout<<"\t\t1. ADMINISTRATION \n\n\n"; cout<<"\t\t2. SHOPPING \n\n\n"; cout<<"\t\t3. YOUR BASKET\n\n\n"; cout<<"\t\t4. BYE BYE (EXIT) \n\n\n"; cout<<" Enter your choice ----- "; cin>>ch; switch(ch) { case 1: clrscr(); 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); }