Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<malloc.h>
  5.  
  6. struct sual{
  7. int price;
  8. char customer[20];
  9. char dress[20];
  10. struct sual *next;
  11. };
  12.  
  13. struct sual *start = NULL;
  14.  
  15. void menu(){
  16.  
  17.  
  18. printf("BLUE DRESS SHOP CASHIER QUEUE\n");
  19. printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
  20. printf("1. view queue\n");
  21. printf("2. add customer to queue\n");
  22. printf("3. serve to customer\n");
  23. printf("4. exit\n");
  24. printf("input :");
  25. }
  26.  
  27. struct sual *add(struct sual *start){
  28. struct sual *newsual,*ptr;
  29. int harga;
  30. char pembeli[20],pakaian[20];
  31.  
  32. do{
  33. printf("input customer's [3...20]: " );
  34. scanf("%[^\n]",pembeli);
  35. getchar();
  36. }while (strlen(pembeli)<3 || strlen(pembeli)>20);
  37.  
  38. do{
  39. printf("input dress's [3...20]: " );
  40. scanf("%[^\n]",pakaian);
  41. getchar();
  42. }while (strlen(pakaian)<3 || strlen(pakaian)>20);
  43.  
  44. do {
  45. printf("input dress's price[$3...$999] : ");
  46. scanf("%d",&harga );
  47. } while(harga < 3 || harga > 999);
  48.  
  49. newsual= (struct sual*)malloc(sizeof(struct sual));
  50. strcpy(newsual->customer,pembeli);
  51. strcpy(newsual->dress,pakaian);
  52. newsual -> price = harga;
  53. ptr=start;
  54. if (start == NULL) {
  55. newsual -> next = start;
  56. start = newsual;
  57. }else{
  58. newsual -> next = NULL;
  59. while(ptr -> next != NULL){
  60. ptr = ptr -> next; }
  61. ptr -> next = newsual;
  62. }
  63.  
  64. return start;
  65. }
  66.  
  67. struct sual *queue(struct sual *start) {
  68. struct sual *ptr;
  69.  
  70.  
  71. ptr = start;
  72. if(ptr == NULL){
  73. printf("\ntidak ada data...");
  74. }else{
  75. printf("| customer's name | dress's name | price($)\n\n");
  76. while (ptr != NULL){
  77. printf("| %-15s | %-15s | %-10d \t\n",ptr->customer,ptr->dress,ptr->price );
  78. ptr = ptr -> next;
  79. }
  80. }
  81. getchar();
  82. return start;
  83. }
  84.  
  85.  
  86. struct sual *sell(struct sual *start){
  87. struct sual *ptr;
  88. ptr = start;
  89. if (start == NULL) {
  90. printf("------------- NO Queue------------");
  91. }else if(start != NULL){
  92. printf("-------------- has been served -------------\n" );
  93. start = start -> next;
  94. free(ptr);
  95. }
  96. getchar();
  97. return start;
  98. }
  99.  
  100. struct sual *example(struct sual *start){
  101. struct sual *kastemer1;
  102.  
  103. kastemer1 = (struct sual *)malloc(sizeof(struct sual));
  104.  
  105. start = kastemer1;
  106.  
  107. strcpy(kastemer1->customer, "ali");
  108. strcpy(kastemer1->dress, "kaos golkar");
  109. kastemer1->price = 67;
  110. kastemer1->next = NULL;
  111.  
  112. return start;
  113. }
  114.  
  115.  
  116. int main(){
  117. int pilih;
  118.  
  119. start = example(start);
  120. do{
  121. system("cls");
  122. menu();
  123. scanf("%d",&pilih );
  124. getchar();
  125. if(pilih==1){
  126. start=queue(start);
  127. }else if(pilih==2){
  128. start=add(start);
  129. }else if(pilih==3){
  130. start=sell(start);
  131. }
  132. }while(pilih !=4);
  133. return 0;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement