#Include #Include #Include #Include #Include #Include
#Include #Include #Include #Include #Include #Include
h> struct gry { char name[100]; int quantity,price; }gy[300]; int m; inline void enterproduct(); inline void changeinventory(); inline void makesale(); inline void inventoryreport(); inline int login(); inline void Select(); inline void fileupgrade(); inline void passupdate(); int main() { FILE *p=fopen("grocery.dat","r"); while(!feof(p)) { fflush(stdin); fgets(gy[m].name,100,p); strlwr(gy[m].name); fscanf(p,"%d",&gy[m].quantity); fscanf(p,"%d",&gy[m++].price); } fclose(p); system("cls"); printf("\n\n\n\t\t\tMIZAN GROCERY\n\n\n"); if(!login()) { printf("\n\n\n\t\tAuthentication Failed\n\n\t\tTry Again\n\n\t\tpress any key to continue . . ."); getch(); main(); } Select(); return 0; } inline int login() { char pass[30],c[20]; FILE *p=fopen("login.dll","r"); fgets(pass,100,p); int b,g=0,f; system("cls"); printf("\n\n\n\t\t\tMIZAN GROCERY\n\n\n"); printf("\n\n\t\tPassword: "); for(b=0;; b++) { c[b]=getch(); if(c[b]!=8 && c[b]!=13)printf("*");
} c[b]='\0'; for(b=0; b<3; b++) { system("cls"); printf("\n\n\n\t\tLogging in"); for(f=0; f<4; f++) { printf(" . "); Sleep(80); } } return (!strcmp(pass,c));
else if(c[b]==8) { if(!g)b--; else b-=2; g++; system("cls"); printf("\n\n\n\t\t\tMIZAN GROCERY\n\n\n"); printf("\n\n\t\tPassword: "); for(f=0; f<b; f++)printf("*"); } else if(c[b]==13)break;
} inline void Select() { int choice=1,MAX_OPTION=5; char input; do { system("cls"); printf("\n==========USE UP-DOWN ARROW KEY TO SELECT===========\n\n"); if(choice==1) printf(" ==> 1. E N T E R\tA\tP R O D U C T\n\n"); else printf("\t 1. Enter a Product\n\n"); if(choice==2) printf(" ==> 2. C H A N G E \tI N V E N T O R Y\n\n"); else printf("\t 2. Change Inventory\n\n"); if(choice==3) printf(" ==> 3. M A K E\tS A L E\n\n"); else printf("\t 3. Make Sale\n\n"); if(choice==4) printf(" ==> 4. I N V E N T O R Y\tR E P O R T\n\n"); else printf("\t 4. Inventory report\n\n"); if(choice==5) printf(" ==> 5. P A S S W O R D\tU P D A T E\n\n"); else printf("\t 5. Password update\n\n"); if(choice==0) printf(" ==> 0. E X I T.\n\n"); else
printf("\t 0. Exit.\n\n"); input=getch(); if(input==72) choice--; else if(input==80) choice++; if(choice>MAX_OPTION) choice=0; else if(choice<0) choice=MAX_OPTION; }while(input!=13); switch(choice) { case 1: enterproduct(); break; case 2: changeinventory(); break; case 3: makesale(); break; case 4: inventoryreport(); break; case 5: passupdate(); break; case 0: exit(0); break; } } inline void enterproduct() { int a,b=1,c; char s[100]; system("cls"); printf("\n\n\n\t\tEnter the name of the product: "); fflush(stdin); gets(s); strcat(s,"\n"); strlwr(s); for(a=0 ; (strcmp(s,gy[a].name))!=0 && (a<m) ; a++); if(a==m) { printf("\n\n\t\tPrice: "); scanf("%d",&gy[m].price); strcpy(gy[m].name,s); printf("\n\n\t\tQuantity: "); scanf("%d",&gy[m++].quantity); printf("\n\n\t\tThe product is successfully added to the inventory."); } else printf("\n\n\t\tThe product you entered already exists . . . "); printf("\n\t\tpress any key to continue . . . .");
} inline void changeinventory() { int a; char s[100]; system("cls"); while(!login()) { printf("\n\n\t\tLog in error . . . . \n\n\t\tpress enter to go to main menu . . . .\n\n\t\tor press any other key to log in"); if(getch()==13)Select(); else changeinventory(); } system("cls"); printf("\n\n\n\t\tEnter the name of the product: "); fflush(stdin); gets(s); strcat(s,"\n"); strlwr(s); for(a=0;strcmp(gy[a].name,s)!=0 && a<m ;a++); if(a==m) { printf("\n\n\t\tYour product doesn't exist . . \n\n\t\tpress any key to go to main menu . . .\n\n\tor press enter to give the correct product name . . . ."); if(getch()==13)changeinventory(); Select(); } printf("\n\n\t\tThe present amount: %d",gy[a].quantity); printf("\n\n\t\tEnter the new amount: "); scanf("%d",&gy[a].quantity); fileupgrade(); printf("\n\n\t\tThe inventory has been upgraded. \n\n\t\tpress any key to continue . . . ."); getch(); Select(); } inline void makesale() { int a,b,c; char s[100]; system("cls"); printf("\n\n\n\t\tEnter the name of product: "); fflush(stdin); gets(s); strcat(s,"\n"); strlwr(s); for(a=0 ; (strcmp(s,gy[a].name))!=0 && (a<m) ; a++); if(a==m) { printf("\n\n\n\t\tYour product doesn't exists . . . . \n\n\t\tpress any key to enter the correct product name . . . . \n\n\t\tor press enter to go to main menu . . . . "); if(getch()==13)Select();
else makesale(); } printf("\n\n\t\tEnter the amount: "); scanf("%d",&b); if(gy[a].quantity<b) { printf("\n\n\t\tThis much amount is not available in the inventory . . . .\n\n\t\tpress enter to go to main menu . . . .\n\n\t\tpress any other key to sale again . . . ."); if(getch()==13)Select(); makesale(); } gy[a].quantity-=b; printf("\n\n\t\tBill: %d\n\n\t\tAmount left in the inventory: %d\n\n\t\tpress any key to go to main menu . . . ",gy[a].price*b,gy[a].quantity); fileupgrade(); getch(); Select(); } inline void inventoryreport() { int a,b=0; char s[100]; system("cls"); while(!login()) { printf("\n\n\t\tLog in error . . . . \n\n\t\tpress enter to go to main menu . . . .\n\n\t\tor press any other key to log in"); if(getch()==13)Select(); else changeinventory(); } system("cls"); printf("\n\n\t\tInventory Report\n\n "); for(a=0;a<m;a++) { b+=gy[a].price*gy[a].quantity; printf("\n\tproduct name: %s\n\tUnit price: %d\n\tAvailable amount: %d\n\tWorth: %d\n",gy[a].name,gy[a].price,gy[a].quantity,gy[a].price*gy[a].quantity); } printf("\n\n\t\tTotal worth of the inventory: %d\n\n\t\tpress any key to go to main menu . . . ",b); getch(); Select(); } inline void fileupgrade() { FILE *p=fopen("grocery.dat","w"); for(register int a=0; a<m; a++) fprintf(p,"%s%d\n%d",gy[a].name,gy[a].quantity,gy[a].price); fclose(p); } inline void passupdate() { int b,g,f,h[5]={1,1,1,1,1}; char a[30],d[30],c[30];
FILE *p=fopen("login.dll","r"); fgets(a,30,p); fclose(p); system("cls"); if(!login()) { printf("\n\n\t\tlog in error\n\n\t\tpress enter to go to main menu . . . . \n\n\t\tor press other key to log in . . . ."); if(getch()==13)Select(); passupdate(); } system("cls"); printf("\n\n\t\tEnter new password: "); for(b=0;; b++) { c[b]=getch(); if(c[b]!=8 && c[b]!=13)printf("*"); else if(c[b]==8) { if(!g)b--; else b-=2; g++; system("cls"); printf("\n\n\t\tEnter new password: "); for(f=0; f<b; f++)printf("*"); } else if(c[b]==13)break; } c[b]='\0'; for(b=0;c[b]!='\0';b++) { if(isupper(c[b]))h[0]=0; if(islower(c[b]))h[1]=0; if(isdigit(c[b]))h[2]=0; if(!isalnum(c[b]))h[3]=0; } if(h[0]||h[1]||h[2]||h[3]) { if(h[0])printf("\n\n\t\tEnter a upper case"); if(h[1])printf("\n\n\t\tEnter a lower case"); if(h[2])printf("\n\n\t\tEnter a digit"); if(h[3])printf("\n\n\t\tEnter a special character"); printf("\n\n\t\tpress enter to goto update password\n\n\t\tor press enter to goto main menu"); if(getch()==13)Select(); passupdate(); } p=fopen("login.dll","w"); fprintf(p,"%s",c); fclose(p); printf("\n\n\t\tPassword successfully updated . . . . \n\n\t\tpress any key to go to main menu . . . ."); getch(); Select(); }