Advertisement
K11

ABC

K11
May 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. //
  2. // main.c
  3. // Thi Cuối Kỳ
  4. //
  5. // Created by Vũ Nguyễn Khánh on 5/22/18.
  6. // Copyright © 2018 Vũ Nguyễn Khánh. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12.  
  13. typedef struct
  14. {
  15. int ClassID;
  16. char CourseName[30];
  17. char Room[10];
  18. int Day;
  19. char Slots[10];
  20. } university;
  21.  
  22. university a[200];
  23. int n=0,k=0;
  24. void Input()
  25. {
  26. int m;
  27. do
  28. {
  29. printf("Nhap so luong lop : \n");
  30. scanf("%d",&m);
  31. } while(m<1 || m>200);
  32. n+=m;
  33. for(int i=0;i<n;i++)
  34. {
  35. printf("Nhap thong tin lop can them [%d] \n",i+1);
  36. printf("ClassID : "); rewind(stdin);
  37. scanf("%d",&a[i].ClassID);
  38. printf("CourseName: "); rewind(stdin);
  39. gets(a[i].CourseName);
  40. printf("Room : "); rewind(stdin);
  41. gets(a[i].Room);
  42. do
  43. {
  44. printf("Day :"); rewind(stdin);
  45. scanf("%d",&a[i].Day);
  46. } while(a[i].Day<2 && a[i].Day>7);
  47. do
  48. {
  49. printf("Slots (?-?) : "); rewind(stdin);
  50. gets(a[i].Slots);
  51. } while (a[i].Slots != '-');
  52. }
  53. k+=m;
  54. }
  55.  
  56. void Output()
  57. {
  58. for(int i=0;i<n;i++)
  59. {
  60. printf("\n\n");
  61. printf("Ma lop \t Ten mon hoc \t Ten phong \t Thu \t Tiet hoc");
  62. printf("%d \t %s \t %s \t %d \t %s",a[i].ClassID,a[i].CourseName,a[i].Room,a[i].Day,a[i].Slots);
  63. printf("\n\n");
  64. }
  65. }
  66.  
  67. void Search_Room()
  68. {
  69. char s[10];
  70. printf("Nhap ten phong muon tim : "); rewind(stdin);
  71. gets(s);
  72. for(int i=0;i<n;i++)
  73. {
  74. if(strcmp(a[i].Room,s) == 0)
  75. {
  76. printf("Ma lop \t Ten mon hoc \t Ten phong \t Thu \t Tiet hoc");
  77. printf("%d \t %s \t %s \t %d \t %s",a[i].ClassID,a[i].CourseName,a[i].Room,a[i].Day,a[i].Slots);
  78. printf("\n\n");
  79. k=0;
  80. }
  81. else
  82. {
  83. printf("Khong ton tai phong %s trong danh sach.\n",a[i].Room);
  84. }
  85. }
  86. }
  87.  
  88. void Arrange()
  89. {
  90. university tmp;
  91. for(int i=0;i<n-1;i++)
  92. for(int j=i+1;j<n;j++)
  93. {
  94. if(a[i].ClassID<a[j].ClassID)
  95. {
  96. tmp=a[i];
  97. a[i]=a[j];
  98. a[j]=tmp;
  99. }
  100. }
  101. for(int i=0;i<n;i++)
  102. {
  103. printf("Ma lop \t Ten mon hoc \t Ten phong \t Thu \t Tiet hoc");
  104. printf("%d \t %s \t %s \t %d \t %s",a[i].ClassID,a[i].CourseName,a[i].Room,a[i].Day,a[i].Slots);
  105. printf("\n\n");
  106. }
  107. }
  108.  
  109. void Check()
  110. {
  111.  
  112. for (int i = 0; i < n; i++)
  113. {
  114. for (int j = 0; j < n; j++)
  115. {
  116. if ((strcmp(a[i].Room, a[j].Room) == 0) && (atoi(a[i].Slots) == atoi(a[j].Slots)) && (a[i].Day = a[j].Day))
  117. printf("%d", a[i].ClassID);
  118. break;
  119. }
  120. }
  121.  
  122. }
  123.  
  124. void Menu()
  125. {
  126. printf("-----------------MENU-----------------");
  127. printf("1. Bo sung lop hoc.\n");
  128. printf("2. In thong tin cac lop.\n");
  129. printf("3. Tim kiem theo phong.\n");
  130. printf("4. Sap xep.\n");
  131. printf("5. Kiem tra trung phong.\n");
  132. printf("6. Thoat chuong trinh.\n");
  133. }
  134.  
  135. int Select()
  136. {
  137. int q;
  138. printf("Lua chon cua ban: ");
  139. scanf("%d",&q);
  140. if(q>0 && q<7)
  141. return q;
  142. else return Select();
  143. }
  144.  
  145. void Option()
  146. {
  147. while(1)
  148. {
  149. int Choose=Select();
  150. switch(Choose)
  151. {
  152. case 1: Input(); break;
  153. case 2: Output(); break;
  154. case 3: Search_Room(); break;
  155. case 4: Arrange(); break;
  156. case 5: Check(); break;
  157. case 6: printf("Ket thuc.\n");e xit(1); break;
  158. default: break;
  159. }
  160. }
  161. }
  162.  
  163. int main()
  164. {
  165. Menu();
  166. Select();
  167. return 0;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement