Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include <stdlib.h>
- typedef struct Node
- {
- char code[20];
- char type[20];
- char name[50];
- char ch[20];
- int price;
- int num;
- char date[20];
- struct Node *next;
- } node;
- int t=0;
- void insert_after(node *p,char name[50],char code[20],int num,char ch[20],char type[20],int price,char ex_date[20])
- {
- //char name1[20]
- while(p->next != NULL)
- {
- p = p->next;
- }
- p->next = (node *)malloc(sizeof(node));
- strcpy(p->next->name,name);
- strcpy(p->next->code,code);
- p->next->num = num;
- strcpy(p->next->ch,ch);
- strcpy(p->next->type,type);
- p->next->price = price;
- strcpy(p->next->date,ex_date);
- p->next->next = NULL;
- }
- void edit_data(node *p,char code[])
- {
- int n,ct=0;
- //char name1[20];
- //char code1[20];
- int num1;
- int price1;
- char name1[50];
- char code1[20];
- char type1[20];
- char ch1[20];
- //node *temp = search(p,id);
- p = p->next;
- while(p != NULL)
- {
- if(strcmp(p->code,code) == 0)
- {
- printf("\n****Product's Data To Edit****\n");
- printf("Product name : %s\n", p->name);
- printf("Product CODE : %s\n", p->code);
- printf("Total amount of Products: %d %s\n",p->num,p->ch);
- printf("Product TYPE : %s\n", p->type);
- printf("Product PRICE : %d\n", p->price);
- printf("Product EXPIRED DATE: %s\n\n", p->date);
- printf("Select your option to Edit the case: ");
- scanf("%d",&n);
- if(n == 1)
- {
- printf("Enter the NAME of Product: ");
- scanf(" %[^\n]s", name1);
- strcpy(p->name,name1);
- }
- else if(n == 2)
- {
- printf("Enter the CODE: ");
- scanf("%s",&code1);
- strcpy(p->code,code1);
- }
- else if(n == 3)
- {
- printf("Enter the Total amount of Products : ");
- scanf("%d %s",&num1,ch1);
- p->num = num1;
- strcpy(p->ch,ch1);
- }
- else if(n == 4)
- {
- printf("Enter Product TYPE: ");
- scanf("%s",type1);
- strcpy(p->type,type1);
- }
- else if(n == 5)
- {
- printf("Enter Product PRICE: ");
- scanf("%d",&price1);
- p->price = price1;
- }
- else
- {
- printf("\nError Selection!!\n");
- }
- }
- ct++;
- p = p -> next;
- }
- if(ct == 0)
- printf("\nProduct not Found!\n");
- }
- void search(node *p, char type[20])
- {
- int ct=0;
- p = p->next;
- //node *temp = p;
- printf("\n----------------------------------------------------------------\n");
- printf(" ****Displaying Searched Product's information**** ");
- printf("\n----------------------------------------------------------------\n");
- while(p != NULL)
- {
- if(strcmp(p->type,type) == 0)
- {
- ct++;
- printf(" Product name : %s\n", p->name);
- printf(" Product CODE : %s\n", p->code);
- printf(" Total amount of Products : %d Pieces\n",p->num);
- printf(" Product TYPE : %s\n", p->type);
- printf(" Product PRICE : %d\n", p->price);
- printf(" Product EXPIRED DATE: %s\n\n", p->date);
- }
- p = p -> next;
- }
- if(ct == 0)
- printf("Sorry!Product not found.\n");
- else
- printf("Total %s Items are %d\n",type,ct);
- }
- int sold(node *p, char code[20],int pc)
- {
- int ct=0,sum=0;
- //node *temp;
- while(p->next != NULL)
- {
- if(strcmp(p->next->code,code) == 0)
- {
- if(pc > p->next->num)
- {
- printf("Not Enough Product in Storage!\n\n");
- return 0;
- }
- sum = pc*p->next->price;
- p->next->num = p->next->num - pc;
- return sum;
- }
- p = p->next;
- }
- if(ct == 0)
- {
- printf("Product Not Found!!\n");
- }
- }
- void display(node *p)
- {
- while(p -> next != NULL)
- {
- printf(" Product name : %s\n", p->next->name);
- printf(" Product CODE : %s\n", p->next->code);
- printf(" Total amount of Products : %d %s\n",p->next->num,p->next->ch);
- printf(" Product TYPE : %s\n", p->next->type);
- printf(" Product PRICE : %d\n", p->next->price);
- printf(" Product EXPIRED DATE: %s\n\n", p->next->date);
- //printf("Student name: %s\n", p->next->name);
- p = p->next;
- }
- }
- int total(int sum)
- {
- t = t + sum;
- return t;
- }
- void delete(node *p, char code[20])
- {
- int ct=0;
- node *temp;
- while(p->next != NULL)
- {
- if(strcmp(p->next->code,code) == 0)
- {
- ct++;
- temp = p->next;
- p->next = temp->next;
- free(temp);
- return 0;
- }
- p = p->next;
- }
- if(ct == 0)
- {
- printf("Element Not Found!!\n");
- }
- }
- void check_code(node *p,char code[])
- {
- while(p->next != NULL)
- {
- if(strcmp(p->next->code,code)==0)
- {
- printf("\nThis CODE Already exists!\n");
- printf("Enter a new code please! :- ");
- scanf("%s",code);
- }
- p = p->next;
- }
- }
- int main()
- {
- system("color f0");
- //system("font 2b");
- int n,p,s;
- char q;
- char ch[20];
- char ch1[20];
- char name[50];
- char code[20];
- char type[20];
- int num;
- int price;
- char ex_date[20];
- node *start = (node *)malloc(sizeof(node));
- start -> next = NULL;
- while(1)
- {
- printf("\n----------------------------------------------------------------------------\n");
- printf(" Welcome to Supershop Management System" );
- printf("\n----------------------------------------------------------------------------\n");
- printf("\tLog in as:\n");
- printf(" \n\t\t 1. ADMIN \n\n\t\t 0. EXIT");
- printf("\n----------------------------------------------------------------------------\n");
- printf(" " );
- printf("\n----------------------------------------------------------------------------\n");
- printf("\n\tEnter Choice:\t\t");
- int choice;
- scanf("%d",&choice);
- switch(choice)
- {
- case 1:
- while(1)
- {
- printf("\n1. Insert Product data\n");
- printf("2. Buyer's BILL\n");
- printf("3. Display\n");
- printf("4. Total SALE\n");
- printf("5. Search\n");
- printf("6. Edit Product information\n");
- printf("7. Delete product\n");
- printf("8. Exit the programme\n");
- printf("\nEnter choice: ");
- scanf(" %c",&q);
- switch(q)
- {
- case '1':
- system("CLS");
- printf("\nIf your want to EXIT the case press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("\n---------------------------------------------------------------\n");
- printf(" Enter Product information ");
- printf("\n---------------------------------------------------------------\n");
- //printf("\n\nEnter Product information\n\n");
- printf("Enter name: ");
- scanf(" %[^\n]s", name);
- printf("Enter CODE: ");
- scanf("%s", code);
- check_code(start,code);
- printf("Total amount of product: ");
- scanf("%d %s",&num,ch);
- printf("Enter Product Type: ");
- scanf(" %s", type);
- printf("Enter Product Price: ");
- scanf("%d", &price);
- printf("Enter Product Expired Date: ");
- scanf(" %s", ex_date);
- insert_after(start,name,code,num,ch,type,price,ex_date);
- }
- break;
- case '2':
- system("CLS");
- printf("\nIf your want to EXIT the case press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("How many Types of ITEM: ");
- scanf("%d",&n);
- int sum =0;
- for(int i=0; i<n; i++)
- {
- printf("Enter the Product code: ");
- scanf("%s", code);
- printf("Amount of product? :- ");
- scanf("%d %s",&p,ch1);
- sum = sum+ sold(start,code,p);
- //slip(start,code,p);
- }
- total(sum);
- printf("\n---------------------------------------\n");
- printf(" Total BILL: %d taka ",sum);
- printf("\n---------------------------------------\n");
- }
- break;
- case '3':
- system("CLS");
- printf("\nIf your want to EXIT the case press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("\n----------------------------------------------\n");
- printf(" ****Product's information**** ");
- printf("\n----------------------------------------------\n");
- display(start);
- }
- break;
- case '4':
- system("CLS");
- printf("\nIf your want to EXIT the case press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("\n---------------------------------------\n");
- printf(" Total Daily SALE: %d taka ",t);
- printf("\n---------------------------------------\n");
- }
- break;
- case '5':
- system("CLS");
- printf("\nIf your want to EXIT the case press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("Enter the Product TYPE: ");
- scanf("%s",type);
- search(start,type);
- }
- break;
- case '6':
- system("CLS");
- printf("\nIf your want to EXIT the case press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("\nEnter the Product CODE to Edit data: ");
- scanf("%s",code);
- edit_data(start,code);
- }
- break;
- case '7':
- system("CLS");
- printf("\nIf your want to EXIT the case press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("\nEnter the Product CODE to Delete: ");
- scanf("%s",code);
- delete(start,code);
- }
- case '8':
- exit(0);
- default:
- system("CLS");
- printf("Invalid choice.Try again!\n");
- break;
- }
- }
- break;
- case 0:
- exit(0);
- //break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement