Advertisement
Nayeemzaman

Untitled

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