Advertisement
Nayeemzaman

supershop

Apr 9th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.05 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include <stdlib.h>
  4.  
  5. typedef struct Node
  6. {
  7.     char code[20];
  8.     char type[20];
  9.     char name[50];
  10.     char ch[20];
  11.     int price;
  12.     int num;
  13.     char date[20];
  14.     struct Node *next;
  15. } node;
  16. int t=0;
  17. 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])
  18. {
  19.     while(p->next != NULL)
  20.     {
  21.         p = p->next;
  22.     }
  23.     p->next = (node *)malloc(sizeof(node));
  24.  
  25.     strcpy(p->next->name,name);
  26.     strcpy(p->next->code,code);
  27.     p->next->num = num;
  28.     strcpy(p->next->ch,ch);
  29.     strcpy(p->next->type,type);
  30.     p->next->price = price;
  31.     strcpy(p->next->date,ex_date);
  32.     p->next->next = NULL;
  33. }
  34.  
  35. void edit_data(node *p,char code[])
  36. {
  37.     int n,ct=0;
  38.     //char name1[20];
  39.     //char code1[20];
  40.     int num1;
  41.     int price1;
  42.     char name1[50];
  43.     char code1[20];
  44.     char type1[20];
  45.     //node *temp = search(p,id);
  46.     p = p->next;
  47.     while(p != NULL)
  48.     {
  49.         if(strcmp(p->code,code) == 0)
  50.         {
  51.             printf("\n****Product's Data To Edit****\n");
  52.  
  53.             printf("Product name        : %s\n", p->name);
  54.             printf("Product CODE        : %s\n", p->code);
  55.             printf("Total amount of Products: %d %s\n",p->num,p->ch);
  56.             printf("Product TYPE        : %s\n", p->type);
  57.             printf("Product PRICE       : %d\n", p->price);
  58.             printf("Product EXPIRED DATE: %s\n\n", p->date);
  59.  
  60.             printf("Select your option to Edit the case: ");
  61.  
  62.             scanf("%d",&n);
  63.  
  64.             if(n == 1)
  65.             {
  66.                 printf("Enter the NAME of Product: ");
  67.                 scanf(" %[^\n]s", name1);
  68.                 strcpy(p->name,name1);
  69.             }
  70.             else if(n == 2)
  71.             {
  72.                 printf("Enter the CODE: ");
  73.                 scanf("%s",&code1);
  74.                 strcpy(p->code,code1);
  75.             }
  76.             else if(n == 3)
  77.             {
  78.                 printf("Enter the Total amount of Products : ");
  79.                 scanf("%d",&num1);
  80.                 p->num = num1;
  81.             }
  82.             else if(n == 4)
  83.             {
  84.                 printf("Enter Product TYPE: ");
  85.                 scanf("%s",type1);
  86.                 strcpy(p->type,type1);
  87.             }
  88.             else if(n == 5)
  89.             {
  90.                 printf("Enter Product PRICE: ");
  91.                 scanf("%d",&price1);
  92.                 p->price = price1;
  93.             }
  94.             else
  95.             {
  96.                 printf("\nError Selection!!\n");
  97.             }
  98.         }
  99.         ct++;
  100.         p = p -> next;
  101.     }
  102.     if(ct == 0)
  103.         printf("\nElement not Found!\n");
  104.  
  105. }
  106.  
  107. void search(node *p, char type[20])
  108. {
  109.     int ct=0;
  110.     p = p->next;
  111.  
  112.     //node *temp = p;
  113.  
  114.     printf("\n****Displaying Searched Information****\n");
  115.  
  116.     while(p != NULL)
  117.     {
  118.         if(strcmp(p->type,type) == 0)
  119.         {
  120.             ct++;
  121.  
  122.             printf("Product name        : %s\n", p->name);
  123.             printf("Product CODE        : %s\n", p->code);
  124.             printf("Number of Products  : %d Pieces\n",p->num);
  125.             printf("Product TYPE        : %s\n", p->type);
  126.             printf("Product PRICE       : %d\n", p->price);
  127.             printf("Product EXPIRED DATE: %s\n\n", p->date);
  128.         }
  129.         p = p -> next;
  130.     }
  131.     if(ct == 0)
  132.         printf("Sorry!Element not found.\n");
  133.     else
  134.         printf("Total %s Items are %d\n",type,ct);
  135. }
  136.  
  137. int sold(node *p, char code[20],int pc)
  138. {
  139.     int ct=0,sum=0;
  140.     //node *temp;
  141.     while(p->next != NULL)
  142.     {
  143.  
  144.         if(strcmp(p->next->code,code) == 0)
  145.         {
  146.             if(pc > p->next->num)
  147.             {
  148.                 printf("Not Enough Element in Storage!\n\n");
  149.                 return 0;
  150.             }
  151.             sum = pc*p->next->price;
  152.  
  153.             p->next->num = p->next->num - pc;
  154.             return sum;
  155.         }
  156.         p = p->next;
  157.     }
  158.     if(ct == 0)
  159.     {
  160.         printf("Element Not Found!!\n");
  161.     }
  162. }
  163.  
  164. void display(node *p)
  165. {
  166.     while(p -> next != NULL)
  167.     {
  168.         printf("Product name        : %s\n", p->next->name);
  169.         printf("Product CODE        : %s\n", p->next->code);
  170.         printf("Number of Products  : %d %s\n",p->next->num,p->next->ch);
  171.         printf("Product TYPE        : %s\n", p->next->type);
  172.         printf("Product PRICE       : %d\n", p->next->price);
  173.         printf("Product EXPIRED DATE: %s\n\n", p->next->date);
  174.         //printf("Student name: %s\n", p->next->name);
  175.         p = p->next;
  176.     }
  177. }
  178. int total(int sum)
  179. {
  180.    t = t + sum;
  181.    return t;
  182. }
  183. void delete(node *p, char code[20])
  184. {
  185.     int ct=0;
  186.     node *temp;
  187.     while(p->next != NULL)
  188.     {
  189.         if(strcmp(p->next->code,code) == 0)
  190.         {
  191.             ct++;
  192.             temp = p->next;
  193.             p->next = temp->next;
  194.             free(temp);
  195.             return 0;
  196.         }
  197.         p = p->next;
  198.     }
  199.     if(ct == 0)
  200.     {
  201.         printf("Element Not Found!!\n");
  202.     }
  203. }
  204. void slip(node *p,char code[],int p)
  205. {
  206.  
  207. }
  208. int main()
  209. {
  210.     int n,p,s;
  211.     char q;
  212.     char ch[20];
  213.     char ch1[20];
  214.     char name[50];
  215.     char code[20];
  216.     char type[20];
  217.     int num;
  218.     int price;
  219.     char ex_date[20];
  220.  
  221.     node *start = (node *)malloc(sizeof(node));
  222.     start -> next = NULL;
  223.  
  224.     while(1)
  225.     {
  226.         printf("\n\n1. Insert Product data\n");
  227.         printf("2. Buyer's BILL\n");
  228.         printf("3. Display\n");
  229.         printf("4. Total SALE\n");
  230.         printf("5. Search\n");
  231.         printf("6. Edit Product information\n");
  232.         printf("7. Delete product\n");
  233.  
  234.         printf("\nEnter your choice: ");
  235.  
  236.         scanf(" %c",&q);
  237.  
  238.         switch(q)
  239.         {
  240.         case '1':
  241.             printf("\nIf your want to EXIT the case press '0' else press any key\n");
  242.             scanf("%d",&s);
  243.  
  244.             if(s == 0)
  245.                 break;
  246.             else{
  247.             printf("\n\nEnter Product information\n\n");
  248.             printf("Enter name: ");
  249.             scanf(" %[^\n]s", name);
  250.             printf("Enter CODE: ");
  251.             scanf("%s", code);
  252.             printf("Number of product: ");
  253.             scanf("%d %s",&num,ch);
  254.             printf("Enter Product Type: ");
  255.             scanf(" %s", type);
  256.             printf("Enter Product Price: ");
  257.             scanf("%d", &price);
  258.             printf("Enter Product Expired Date: ");
  259.             scanf(" %s", ex_date);
  260.  
  261.             insert_after(start,name,code,num,ch,type,price,ex_date);
  262.             }
  263.             break;
  264.  
  265.         case '2':
  266.             printf("\nIf your want to EXIT the case press '0' else press any key\n");
  267.             scanf("%d",&s);
  268.  
  269.             if(s == 0)
  270.                 break;
  271.             else{
  272.             printf("How many Types of ITEM: ");
  273.             scanf("%d",&n);
  274.             int sum =0;
  275.             for(int i=0; i<n; i++){
  276.                     printf("Enter the Product code: ");
  277.                     scanf("%s", code);
  278.                     printf("Amount of product? :- ");
  279.                     scanf("%d %s",&p,ch1);
  280.                     sum = sum+ sold(start,code,p);
  281.                     slip(start,code,p);
  282.             }
  283.             total(sum);
  284.             printf("\nTotal BILL: %d taka\n",sum);
  285.             }
  286.             break;
  287.  
  288.         case '3':
  289.             printf("\nIf your want to EXIT the case press '0' else press any key\n");
  290.             scanf("%d",&s);
  291.  
  292.             if(s == 0)
  293.                 break;
  294.             else{
  295.             printf("\n\n****Product's information****\n\n");
  296.             display(start);
  297.             }
  298.             break;
  299.         case '4':
  300.             printf("\nIf your want to EXIT the case press '0' else press any key\n");
  301.             scanf("%d",&s);
  302.  
  303.             if(s == 0)
  304.                 break;
  305.             else{
  306.                 printf("\nTotal Daily SALE: %d\n",t);
  307.             }
  308.             break;
  309.         case '5':
  310.             printf("\nIf your want to EXIT the case press '0' else press any key\n");
  311.             scanf("%d",&s);
  312.  
  313.             if(s == 0)
  314.                 break;
  315.             else{
  316.             printf("Enter the Product TYPE: ");
  317.             scanf("%s",type);
  318.             search(start,type);
  319.             }
  320.             break;
  321.         case '6':
  322.             printf("\nIf your want to EXIT the case press '0' else press any key\n");
  323.             scanf("%d",&s);
  324.  
  325.             if(s == 0)
  326.                 break;
  327.             else{
  328.             printf("\nEnter the Product CODE to Edit data: ");
  329.             scanf("%s",code);
  330.             edit_data(start,code);
  331.             }
  332.             break;
  333.         case '7':
  334.             printf("\nIf your want to EXIT the case press '0' else press any key\n");
  335.             scanf("%d",&s);
  336.  
  337.             if(s == 0)
  338.                 break;
  339.             else{
  340.                 printf("\nEnter the Product CODE to Delete: ");
  341.                 scanf("%s",code);
  342.                 delete(start,code);
  343.             }
  344.         default:
  345.             printf("Invalid choice.Try again!\n");
  346.             break;
  347.         }
  348.     }
  349. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement