Advertisement
axelso

Soal strukdat 02

Mar 19th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. //int jumlah=0;
  5.  
  6. void clear()
  7. {
  8. for(int i=0;i<25;i++)
  9. {
  10. printf("\n");
  11. }
  12. }
  13.  
  14. struct data
  15. {
  16. char name[21];
  17. char type[100];
  18. int quantity;
  19. int price;
  20. struct data *next;
  21. }*head=NULL,*tail=NULL,*curr=NULL;
  22.  
  23. void pushTail(char name[],char type[],int quantity,int price)
  24. {
  25. curr=(struct data*)malloc(sizeof(struct data));
  26. strcpy(curr->name,name);
  27. strcpy(curr->type,type);
  28. curr->quantity=quantity;
  29. curr->price=price;
  30. curr->next=NULL;
  31.  
  32. if(head == NULL)
  33. {
  34. head=tail=curr;
  35. }
  36. else
  37. {
  38. tail->next=curr;
  39. tail=curr;
  40. }
  41. tail->next=NULL;
  42. }
  43.  
  44. void itemlist()
  45. {
  46. clear();
  47. int i=1;
  48. printf("=============================================================================\n");
  49. printf("%5s. | %-20s | %-20s | %-10s | %-10s |\n","No.","Name","Type","Quantity","Price");
  50. printf("=============================================================================\n");
  51. curr=head;//posisi curr di head
  52. while(curr != head)
  53. {
  54. printf("%5d. | %-20s | %-20s | %-10d | %-10d |\n",i,curr->name,curr->type,curr->quantity,curr->price);
  55. curr=curr->next;
  56. i++;
  57. }
  58. printf("=============================================================================\n");
  59. getchar();
  60. }
  61.  
  62. void additem(char name[],char type[],int quantity, int price)
  63. {
  64. char *tempname[21];
  65. char *temptype[100];
  66. int *tempqty;
  67. int *tempprice;
  68. do{
  69. printf("Input name fo the new item[3..20] = ");
  70. scanf("%[^\n]",&tempname);fflush(stdin);
  71. }while(strlen(*tempname)<3 || strlen(*tempname)>20);
  72. strcpy(name,*tempname);
  73.  
  74. do{
  75. printf("input type of the new item[processor/graphic card/memory] = ");
  76. scanf("%[^\n]",temptype);fflush(stdin);
  77. }while(strcmp(*temptype,"processor")==1 ||strcmp(*temptype,"graphic card")==1 || strcmp(*temptype,"memory")==1);
  78. strcpy(type,*temptype);
  79.  
  80. do{
  81. printf("input Quantity of the new item[1..20] = ");
  82. scanf("%[^\n]",*tempqty);fflush(stdin);
  83. }while(*tempqty<1 || *tempqty>20);
  84. quantity=*tempqty;
  85.  
  86. do{
  87. printf("input Price of the new item[1..$1000] = $");
  88. scanf("%[^\n]",tempprice);fflush(stdin);
  89. }while(*tempprice<1 || *tempprice>1000);
  90. price=*tempprice;
  91. clear();
  92. printf("--- add new item success ---");
  93.  
  94. }
  95.  
  96. void menu()
  97. {
  98. clear();
  99. puts("BLUE COMPUTER ADMINISTRATOR");
  100. puts("+++++++++++++++++++++++++++");
  101. puts("1. Item List");
  102. puts("2. Add (PUSH) New Item");
  103. puts("3. Exit");
  104. printf(">> Input your choice : ");
  105. }
  106.  
  107. int main()
  108. {
  109. int choose;
  110.  
  111. do{
  112. choose=0;
  113. menu();
  114. scanf("%d",&choose);fflush(stdin);
  115. switch(choose)
  116. {
  117. case 1:itemlist();break;
  118. case 2:additem();break;
  119.  
  120. }
  121. }while(choose !=3);
  122.  
  123.  
  124.  
  125.  
  126. getchar();
  127. return 0;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement