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])
- {
- 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];
- //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",&num1);
- p->num = num1;
- }
- 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("\nElement not Found!\n");
- }
- void search(node *p, char type[20])
- {
- int ct=0;
- p = p->next;
- //node *temp = p;
- printf("\n****Displaying Searched Information****\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("Number 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!Element 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 Element 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("Element 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("Number 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 slip(node *p,char code[],int p)
- {
- }
- int main()
- {
- 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\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("\nEnter your choice: ");
- scanf(" %c",&q);
- switch(q)
- {
- case '1':
- 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\nEnter Product information\n\n");
- printf("Enter name: ");
- scanf(" %[^\n]s", name);
- printf("Enter CODE: ");
- scanf("%s", code);
- printf("Number 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':
- 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("\nTotal BILL: %d taka\n",sum);
- }
- break;
- case '3':
- 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****Product's information****\n\n");
- display(start);
- }
- break;
- case '4':
- printf("\nIf your want to EXIT the case press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else{
- printf("\nTotal Daily SALE: %d\n",t);
- }
- break;
- case '5':
- 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':
- 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':
- 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);
- }
- default:
- printf("Invalid choice.Try again!\n");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement