Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. #define f fflush(stdin);
  7.  
  8. struct data{
  9. char name[100];
  10. int qty;
  11. int ctr;
  12. struct data *next, *prev;
  13. };
  14.  
  15. struct data *head=NULL, *tail, *curr, *temp;
  16.  
  17. void add(char name[], int qty, int ctr){
  18.  
  19. curr = (struct data*) malloc(sizeof(struct data));
  20. strcpy(curr->name, name);
  21. curr->qty = qty;
  22. curr->ctr = ctr;
  23. curr->next = NULL;
  24. curr->prev = NULL;
  25.  
  26. if(head == NULL){
  27. head = tail = curr;
  28. }else{
  29. curr->next = head;
  30. head = curr;
  31. }
  32. }
  33.  
  34. void display(char name[], int qty){
  35. int ctr=0;
  36.  
  37. temp = head;
  38. printf("-------+--------------------------------+-----------\n");
  39. printf("| No. | Name of Parts | Quantity |\n");
  40. printf("-------+--------------------------------+-----------\n");
  41. while(temp != NULL){
  42. ctr++;
  43. printf("| %2d. | %-31s| %-9d|\n", ctr, temp->name, temp->qty);
  44. temp = temp->next;
  45. }
  46. printf("-------+--------------------------------+-----------");
  47. getchar();
  48. }
  49.  
  50. void apus(int ctr){
  51.  
  52. temp = head;
  53. int num;
  54.  
  55.  
  56. if(temp == NULL){
  57. printf("\n\n\n--- There is No Order in The List ---");
  58. getchar();
  59. }else{
  60. printf("\n\n Input Number of The Order [1..%d]: ", ctr);
  61. scanf("%d", &num); fflush(stdin);
  62.  
  63. while(temp != NULL){
  64. if(temp->ctr == num) break;
  65. temp = temp->next;
  66. }
  67. system("cls");
  68. if(temp == head){
  69. head = head->next;
  70. free(temp);
  71.  
  72. if(head != NULL){
  73. head->prev = NULL;
  74. }
  75. }else if(temp == tail){
  76. tail = tail->prev;
  77. free(temp);
  78. tail->next = NULL;
  79. }else{
  80. temp->prev->next = temp->next;
  81. temp->next->prev = temp->prev;
  82. free(temp);
  83. }
  84. }
  85.  
  86. }
  87.  
  88. int main(){
  89. int menu;
  90. char name[100];
  91. int qty;
  92. int ctr=0;
  93.  
  94. do{
  95. system("cls");
  96. puts("BLUE MOTORCYCLE PARTS");
  97. puts(".....................\n");
  98. puts("1. View Order List");
  99. puts("2. Add New Order");
  100. puts("3. Take Order");
  101. puts("4. Exit\n");
  102. do{
  103. printf(">> Input choice :");
  104. scanf("%d", &menu);fflush(stdin);
  105. }while(menu<1 || menu>4);
  106.  
  107. if(menu ==1){
  108. system("cls");
  109. display(name,ctr);
  110. getchar();
  111. }
  112.  
  113. if(menu ==2){
  114. do{
  115. printf("\nInput Name of Motorcycle's Part [3..30]: ");
  116. gets(name);
  117. }while(strlen(name)<3 || strlen(name)>30);
  118. do{
  119. printf("\nInput Quantity of The Motorcycle's Part [1..20]: ");
  120. scanf("%d", &qty);f
  121. }while(qty<1 || qty>20);
  122. ++ctr;
  123. add(name, qty, ctr);
  124. printf("\n\n\n--- Add New Order Success ---");
  125. getchar();
  126. }
  127.  
  128. if(menu ==3){
  129. display(name,ctr);
  130. apus(ctr);
  131.  
  132. }
  133. }while(menu != 4);
  134.  
  135. getchar();
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement