Advertisement
Guest User

test 4

a guest
Apr 5th, 2020
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.50 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<conio.h>
  4. #include<string.h>
  5.  
  6. struct Node {
  7.     int Data;
  8.     int stock;
  9.     int price;
  10.     char pname[30];
  11.     struct Node *next;
  12. } *rear, *front = NULL;
  13.  
  14. void tampil(){
  15.     printf("BLUE MOTORCYCLE PARTS\n");
  16.     printf(". . . . . . . . . . . .\n");
  17.     printf("\n1. View Order List");
  18.     printf("\n2. Add New Order");
  19.     printf("\n3. Take Order");
  20.     printf("\n4. Exit\n");
  21. }
  22.  
  23.  
  24. void delQueue()
  25. {
  26.     int del;
  27.     struct Node *temp, *var = rear;
  28.     if (var == rear)
  29.     {
  30.         system("cls");
  31.         tabel();
  32.         printf("\n\n\nInput Number of Order [1...4] : ");
  33.         scanf("%d",&del);
  34.         rear = rear->next;
  35.         free(var);
  36.        
  37.        
  38.     }
  39.     else{
  40.         printf("\n--- There is no order in the list ---");
  41.     }
  42. }
  43.  
  44. void push(int value)
  45. {
  46.     struct Node *temp;
  47.     temp = (struct Node *) malloc(sizeof(struct Node));
  48.     temp->Data = value;
  49.     if (front == NULL)
  50.     {
  51.         front = temp;
  52.         front->next = NULL;
  53.         rear = front;
  54.     }
  55.     else
  56.     {
  57.         front->next = temp;
  58.         front = temp;
  59.         front->next = rear;
  60.     }
  61. }
  62.  
  63. void display()
  64. {
  65.     struct Node *var = rear;
  66.     if (var != NULL)
  67.     {
  68.         system("cls");
  69.         tampil();
  70.        
  71.         tabel();
  72.         while (var != front)
  73.         {
  74.             printf("\t%d", var->Data);
  75.             var = var->next;
  76.         }
  77.         if (var == front)
  78.         {
  79.             printf("\t%d", var->Data);
  80.         }
  81.         printf("\n");
  82.     }
  83.     else{
  84.         system("cls");
  85.         printf("\nQueue is Empty\n");
  86.     }
  87. }
  88.  
  89.  
  90.  
  91. void tabel(){
  92.     int quan,harga;
  93.     char name[30];
  94. printf("\t\t--- Order List ---\n");
  95. printf("-+------+-------------------------------+----------+------------+-\n");
  96. printf(" | No.  | Name Of Parts\t\t\t| Quantity | Unit Price |\n");
  97. printf("-+------+-------------------------------+----------+------------+-\n");
  98. printf(" |   1. | %c\t\t\t|     3    |  450000    |\n");
  99. printf(" |   2. | disk brake\t\t\t|     2    |  450000    |\n");
  100. printf(" |   3. | head lamp\t\t\t|     4    |  450000    |\n");
  101. printf(" |   4. | spion\t\t\t\t|     3    |  450000    |\n");
  102. printf("-+------+-------------------------------+----------+------------+-\n");
  103.  
  104. }
  105.  
  106.  
  107. int main()
  108. {
  109.     tampil();
  110.     int i = 0;
  111.     front = NULL;
  112.     while (1)
  113.     {
  114.         printf(" \n>> Input Choice : ");
  115.         scanf("%d", &i);
  116.         switch (i)
  117.         {
  118.             case 1:
  119.             {
  120.                 system("cls");
  121.                 display();
  122.                 break;
  123.             }
  124.             case 2:
  125.             {
  126.                 int value;
  127.                 printf("\nInput the name of motorcycle's parts [3...30] : ");
  128.                 scanf("%d", &value);
  129.                 if( value != 3 || value <= 20){
  130.                     printf("Type [3...30] parts name : ");
  131.                     scanf("%d",&value);
  132.                 }
  133.                 printf("Input Quantity of Motorcycle's parts [1...20] : ");
  134.                 scanf("%d",&value);
  135.                 push(value);
  136.                 display();
  137.                 break;
  138.             }
  139.             case 3:
  140.             {
  141.                 delQueue();
  142.                 display();
  143.                 break;
  144.             }
  145.             case 4:
  146.             {
  147.                 system("cls");
  148.                 printf("Thank You");
  149.                 exit(0);
  150.                
  151.             }
  152.             default:
  153.             {
  154.                 system("cls");
  155.                 printf("\nWrong choice for operation\n");
  156.             }
  157.         }
  158.     }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement