Nayeemzaman

supershop

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