Advertisement
huutho_96

Untitled

Mar 26th, 2015
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <conio.h>
  4. using namespace std;
  5. const int MAX = 50;
  6. struct monhoc
  7. {
  8. char d_ma[5];
  9. char d_hoten[50];
  10. int d_stc;
  11. };
  12. struct dsmonhoc{
  13. int n;
  14. monhoc elem[MAX];
  15. };
  16. void khoitao(dsmonhoc &m)
  17. {
  18. m.n = 0;
  19. }
  20. int Empty(dsmonhoc m)
  21. {
  22. return (m.n == 0) ? 1 : 0;
  23. }
  24. int Full(dsmonhoc m)
  25. {
  26. return (m.n = MAX) ? 1 : 0;
  27. }
  28. void nhap(monhoc &m)
  29. {
  30. cout << " Ma Mon Hoc:\t";
  31. cin >> m.d_ma;
  32. cin.ignore(1);
  33. cout << " Ten Mon Hoc :\t";
  34. cin.getline(m.d_hoten, 50);
  35.  
  36. cout << " So tin chi :\t";
  37. cin >> m.d_stc;
  38. cout << "+-------------------------------------------------------------------+ \n";
  39. }
  40. void xuat(monhoc m)
  41. {
  42. cout << setw(10) << m.d_ma << setw(20) << m.d_hoten << setw(25) << m.d_stc << endl;
  43. cout << "+-------------------------------------------------------------------+ \n";
  44. }
  45. void nhapds(dsmonhoc&m)
  46. {
  47.  
  48. cout << "Nhap So Luong mon hoc: ";
  49. cin >> m.n;
  50. for (int i = 0; i < m.n; i++)
  51. {
  52. cout << "+-------------------------------------------------------------------+ \n";
  53. cout << "Nhap Thong Tin Cho MH Thu [" << i + 1 << "]--" << endl;
  54. nhap(m.elem[i]);
  55. }
  56. }
  57. void xuatds(dsmonhoc m)
  58. {
  59. if (Empty(m) == 1)
  60. cout << "Danh Sach Rong\n";
  61. else
  62. {
  63. system("cls");
  64. cout << " Danh Sach Gom " << m.n << " Mon Hoc " << endl; "\n";
  65. cout << "+-------------------------------------------------------------------+ \n";
  66. cout << "+MH Lan Luot Co Thong Tin: Ma,Ho Ten,So tin Chi," << endl;
  67. cout << "+-------------------------------------------------------------------+ \n";
  68. cout << setw(10) << "Ma Mon Hoc|" << setw(20) << " Ten Mon Hoc|" << setw(25) << "So tin chi|" << endl;
  69. cout << "+-------------------------------------------------------------------+ \n";
  70. for (int i = 0; i < m.n; i++)
  71. {
  72. xuat(m.elem[i]);
  73.  
  74. }
  75. }
  76. }
  77. void them(dsmonhoc &m)
  78. {
  79. int pos;
  80. monhoc x;
  81. if (Empty(m) == 1)
  82. cout << "Danh Sach Rong";
  83. else
  84. {
  85. cout << "Vi tri can them vao mon hoc : ";
  86. cin >> pos;
  87. pos = pos - 1;
  88. if (pos < 0 || pos > m.n - 1)
  89. cout << "Sai Vi tri ";
  90. else
  91. {
  92.  
  93. nhap(x);
  94. for (int i = m.n - 1; i >= pos; i--)
  95. {
  96. m.elem[i + 1] = m.elem[i];
  97. m.elem[pos] = x;
  98. m.n++;
  99. break;
  100. }
  101. }
  102. }
  103. }
  104. void xoa(dsmonhoc & m)
  105. {
  106. int pos;
  107. monhoc x;
  108. if (Empty(m) == 1)
  109. cout << "Danh Sach Rong";
  110. else
  111. {
  112. cout << "Vi tri can xoa mon hoc : ";
  113. cin >> pos;
  114. pos = pos + 1;
  115. if (pos > 0 || pos > m.n + 1)
  116. cout << "Sai Vi tri ";
  117. else
  118. {
  119.  
  120. nhap(x);
  121. for (int i = pos + 1; i <= m.n; i++)
  122. {
  123. m.elem[i - 1] = m.elem[i];
  124. //m.elem[pos] = x;
  125. m.n--;
  126. break;
  127. }
  128. }
  129. }
  130. }
  131. void sua(dsmonhoc &m)
  132. {
  133. int pos;
  134. monhoc x;
  135. if (Empty(m) == 1)
  136. cout << "Danh Sach Rong";
  137. else
  138. {
  139. cout << "Vi tri can sua vao mon hoc : ";
  140. cin >> pos;
  141. pos = pos - 1;
  142. if (pos < 0 || pos > m.n - 1)
  143. cout << "Sai Vi tri ";
  144. else
  145. {
  146. nhap(x);
  147. //for (int i = m.n- 1; i >= pos; i--)
  148. //{
  149. //m.elem[i+1] = m.elem[i];
  150. m.elem[pos] = x;
  151. //m.n++;
  152. //break;
  153. }
  154. }
  155. }
  156. void HoanVi(monhoc &a, monhoc&b)
  157. {
  158. monhoc temp;
  159. temp = a;
  160. a = b;
  161. b = temp;
  162. }
  163. void SapXep(dsmonhoc &m)
  164. {
  165. int menu3;
  166. cout << "\n1.Sap xep theo ma.";
  167. cout << "\n2.Sap xep theo ten.";
  168. cout << "\n3.Sap xep theo gia.";
  169. cout << "\n4.Tro lai.";
  170. cout << "\nChon:";
  171. cin >> menu3;
  172. switch (menu3)
  173. {
  174. case 1:
  175. int menu4;
  176. cout << "\n1.Selection Sort.";
  177. cout << "\n2.Bubble Sort";
  178.  
  179. cout << "\nChon:";
  180. cin >> menu4;
  181. switch (menu4)
  182. {
  183. case 1:
  184. for (int i = 0; i < m.n - 1; i++)
  185. for (int j = i + 1; j < m.n; j++)
  186. if (strcmp(m.elem[i].d_ma, m.elem[j].d_ma)>0)
  187. {
  188. HoanVi(m.elem[i], m.elem[j]);
  189. }
  190. break;
  191. case 2:
  192. for (int i = 0; i < m.n - 1; i++)
  193. for (int j = m.n - 1; j > i; j--)
  194. if (strcmp(m.elem[j].d_ma, m.elem[j - 1].d_ma) > 0)
  195. {
  196. HoanVi(m.elem[j], m.elem[j - 1]);
  197. }
  198. break;
  199. }
  200. break;
  201. case 2:
  202. int menu5;
  203. cout << "\n1.Selection Sort.";
  204. cout << "\n2.Bubble Sort";
  205. cout << "\nChon:";
  206. cin >> menu5;
  207. switch (menu5)
  208. {
  209. case 1:
  210. for (int i = 0; i < m.n - 1; i++)
  211. for (int j = i + 1; j < m.n; j++)
  212. if (strcmp(m.elem[i].d_hoten, m.elem[j].d_hoten) > 0)
  213. {
  214. HoanVi(m.elem[i], m.elem[j]);
  215. }
  216. break;
  217. case 2:
  218. for (int i = 0; i < m.n - 1; i++)
  219. for (int j = m.n - 1; j > i; j--)
  220. if (strcmp(m.elem[j].d_hoten, m.elem[j - 1].d_hoten) > 0)
  221. {
  222. HoanVi(m.elem[j], m.elem[j - 1]);
  223. }
  224. break;
  225. }
  226. break;
  227. /*case 3:
  228. int menu6;
  229. cout << "\n1.Selection Sort.";
  230. cout << "\n2.Bubble Sort";
  231. cout << "\nChon:";
  232. cin >> menu6;
  233. switch (menu6)
  234. {
  235. case 1:
  236. for (int i = 0; i < hh.n - 1; i++)
  237. for (int j = i + 1; j < hh.n; j++)
  238. if (hh.dshh[i].gia > hh.dshh[j].gia)
  239. {
  240. HoanVi(hh.dshh[i], hh.dshh[j]);
  241. }
  242. break;
  243. case 2:
  244. for (int i = 0; i < hh.n - 1; i++)
  245. for (int j = hh.n- 1; j >i; j--)
  246. if (hh.dshh[j].gia > hh.dshh[j - 1].gia)
  247. {
  248. HoanVi(hh.dshh[j], hh.dshh[j-1]);
  249. }
  250. break;
  251. }
  252. break;
  253. case 4:
  254. break;
  255. }
  256. }*/
  257. }
  258. }
  259. int nhaplai()
  260. {
  261. int chon;
  262. system("cls");
  263. cout << endl << endl;
  264. //system("color b");
  265. cout << " | Nhom 2: Vo Tan Nam____Bui Binh Minh_____ LOP: C13-TH01 |\n";
  266. cout << " +=================================================+ \n";
  267. cout << " | CHUONG TRINH QUAN LY MON HOC | \n";
  268. cout << " |-------------------------------------------------| \n";
  269. cout << " 1. Them Danh Sach Mon Hoc \n";
  270. cout << " 2. Xuat Danh Sach Mon hoc. \n";
  271. cout << " 3. Them 1 Mon hoc. \n";
  272. cout << " 4. Xoa 1 Mon Hoc \n";
  273. cout << " 5. Sua mon hoc \n";
  274. cout << " 6. sap xep mon hoc \n";
  275. cout << " +-------------------------------------------------+ \n";
  276. cout << endl;
  277. cout << "Nhap So De Chon Menu: ";
  278. cin >> chon;
  279. return chon;
  280. }
  281. void main()
  282. {
  283. dsmonhoc m;
  284. khoitao(m);
  285. int chon;
  286. chon = nhaplai();
  287. switch (chon)
  288. {
  289. case 1:
  290. nhapds(m);
  291. cout << "Nhap Phim Bat Ky De Quay Ve";
  292. _getch();
  293. nhaplai();
  294. break;
  295. case 2:
  296. xuatds(m);
  297. cout << "Nhap Phim Bat Ky De Quay Ve";
  298. _getch();
  299. nhaplai();
  300. break;
  301. case 3:
  302. them(m);
  303. cout << "Nhap Phim Bat Ky De Quay Ve";
  304. _getch();
  305. nhaplai();
  306. break;
  307. //}
  308. //}
  309. //if(chon < 0)
  310. //{
  311. //cout << "Nhap Sai Vui Long Nhap Lai !!";
  312. //goto nhaplai;
  313. //}
  314. case 4:
  315. xoa(m);
  316. cout << "Nhap Phim Bat Ky De Quay Ve";
  317. _getch();
  318. nhaplai();
  319. //break;
  320. //if(chon< 0)
  321. //{
  322. //cout << "Nhap Sai Vui Long Nhap Lai !!";
  323. //goto nhaplai;
  324. //}
  325. case 5:
  326. sua(m);
  327. cout << "Nhap Phim Bat Ky De Quay Ve";
  328. _getch();
  329. nhaplai();
  330. //break;
  331. //}
  332. //if(chon< 0)
  333. //{
  334. //cout << "Nhap Sai Vui Long Nhap Lai !!";
  335. //goto nhaplai;
  336. //}
  337. case 6:
  338. cout << "\n5.Sap xep thong tin hang hoa theo 1 tieu chi nao do:" << endl;
  339. SapXep(m);
  340. /*XuatDS(m)*/;
  341. /*break;*/
  342. _getch();
  343. nhaplai();
  344. }
  345. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement