Guest User

Untitled

a guest
Feb 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. using namespace std;
  6. struct Sinhvien //tạo 1 truong thuoc tinh sinh vien
  7. {
  8. string masv;
  9. string tensv;
  10. string lop;
  11. double diem;
  12. };
  13. void Themsinhvien(); //khai bao ham
  14. Sinhvien arrSv[50]; // khai bao mang sinh vien voi toi da 50 sinh vien de luu tru .
  15. int ind = 0;//chi so mang de xem so luong sinh vien da them
  16. void Lietketatcasinhvien();
  17. void Timkiemsinhvien(string masv);
  18. void Xoasinhvien(string masv);
  19. void Lietkesinhvientheolop(string lop);
  20. void Chinhsuathongtin();
  21. bool kiemtra(string masv, int vitri); //kiem tra su tom tai sinh vien trong mang
  22. int main()
  23. {
  24. int luachon;
  25. while (true)
  26. {
  27. do
  28. {
  29. cout<< " Chuong trinh quan li sinh vien"<<endl;
  30. cout<< " 1. Them sinh vien"<<endl;
  31. cout<< " 2. Tim kiem sinh vien"<<endl;
  32. cout<< " 3. Chinh sua thong tin sinh vien "<<endl;
  33. cout<< " 4. Xoa sinh vien "<<endl;
  34. cout<< " 5.Liet ke danh sach sinh vien theo lop"<<endl;
  35. cout<< " 6.Liet ke danh sach tat ca sinh vien "<<endl;
  36. cout<< " 7. Thoat "<<endl;
  37. cout<< " Lua chon: ";
  38. cin>>luachon;
  39. system("clear");
  40. }
  41. while (luachon < 1 || luachon>7);
  42. switch(luachon)
  43. {
  44. case 1:
  45. {
  46. Themsinhvien();
  47. cout<<"Back";
  48. system("PAUSE>NULL");
  49. break;
  50. }
  51. case 2:
  52. { string msv;
  53. cout<<"Nhap ma: ";
  54. getline(cin,msv);
  55. cin.ignore();
  56. Timkiemsinhvien(msv);
  57. cout<<"Back";
  58. system("PAUSE>NULL");
  59. break;
  60. }
  61. case 3:
  62. { string msv;
  63. cout<<" Chinh sua thong tin sinh vien "<<endl;
  64. cin.ignore();
  65. cout<<"Nhap ma sinh vien";
  66. getline(cin, msv);
  67.  
  68. Chinhsuathongtin();
  69. cout<<"Back";
  70. system("PAUSE>NULL");
  71. break;
  72. }
  73. case 4:
  74. { string masv;
  75. cout<<" Xoa sinh vien "<<endl;
  76. cin.ignore();
  77. cout<<"Nhap ma sinh vien";
  78. getline(cin,masv);
  79. Xoasinhvien(masv);
  80. cout<<"Back";
  81. system("PAUSE>NULL");
  82. break;
  83. }
  84. case 5:
  85. { string lop;
  86. cin.ignore();
  87. cout<<"Nhap lop: ";
  88. getline(cin,lop);
  89. Lietkesinhvientheolop( lop);
  90. cout<<"Back";
  91. system("PAUSE>NULL");
  92. break;
  93. }
  94. case 6:
  95. { Lietketatcasinhvien();
  96. cout<<"Back";
  97. system("PAUSE>NULL");
  98. break;
  99. }
  100. case 7:
  101. exit(1);
  102. }
  103. }
  104. return 0;
  105. }
  106. void Themsinhvien ()
  107. { // tạo đối tượng cho lớp sinh viên
  108.  
  109.  
  110. int n;
  111. cout<<"Nhap so sinh vien can them:"<<endl;
  112. cin>>n;
  113. for (int i=0;i<n;i++)
  114. {
  115. Sinhvien tmpsv;// sinh vien gan cho bien temp
  116. cin.ignore();
  117. cout<<"Nhap ma sinh vien: ";
  118. getline(cin, tmpsv.masv);
  119. cout<<"Nhap ten sinh vien: ";
  120. getline(cin, tmpsv.tensv);
  121. cout<<"Nhap lop: ";
  122. getline(cin, tmpsv.lop);
  123. cout<<"Nhap diem: ";
  124. cin>>tmpsv.diem;
  125. arrSv[ind] = tmpsv;
  126. ind++;
  127. }
  128.  
  129. }
  130. void Lietketatcasinhvien()
  131. {
  132. cout<<"Danh sach tat ca cac sinh vien"<<endl;
  133. cout<<"Ma sinh vien"<<" "<<"Ten sinh vien"
  134. <<" "<<"Lop"<<" "<<"Diem"<<endl;
  135. for (int i =0; i <ind;i++)
  136. cout<<arrSv[i].masv<<" "<<arrSv[i].tensv<<" "
  137. <<arrSv[i].lop<<" "<<arrSv[i].diem<<endl;
  138. }
  139. void Timkiemsinhvien(string masv)
  140. {
  141. for (int i=0; i < ind; i++)
  142. {
  143. if (masv == arrSv[i].masv)
  144. {
  145. cout<<"Ten sinh vien: "<<arrSv[i].tensv<<endl;
  146. cout<<"Lop: "<<arrSv[i].lop<<endl;
  147. cout<<"Diem: "<<arrSv[i].diem<<endl;
  148. return ;
  149. }
  150. }
  151. cout<<"khong co ma sinh vien nay";
  152. }
  153. void Xoasinhvien(string masv)
  154. {
  155. for (int i =0; i<ind; i++)
  156. {
  157. if (masv == arrSv[i].masv)
  158. {
  159. for (int j=0; j< ind -1; j++)
  160. arrSv[j] = arrSv[j+1];
  161. ind --; // sau khi xoa phantu thì giam tong di 1 sinh vien
  162. cout<<"Da xoa"<<endl;
  163. return;
  164. }
  165. }
  166. cout<<"khong tim thay sinh vien"<<endl;
  167. }
  168. void Lietkesinhvientheolop(string lop)
  169. {
  170. int count = 0;
  171. for (int i =0; i<ind; i++)
  172. {
  173. if (lop == arrSv[i].lop)
  174. {
  175. cout<<arrSv[i].masv<<arrSv[i].tensv<<arrSv[i].lop<<arrSv[i].diem<<endl;
  176. }
  177. }
  178. if(count==0 )
  179. cout<<"Sinh vien khong thuoc lop nay"<<endl;
  180. }
  181. void Chinhsuathongtin(){};
  182. bool kiemtra(string masv, int vitri)
  183. {
  184. bool check = false;
  185. for (int i=0;i< ind;i++)
  186. {
  187. if(masv == arrSv[i].masv)
  188. {
  189. vitri=i;
  190. check = true;
  191. break;
  192. }
  193. break ;
  194. }
  195. }
Add Comment
Please, Sign In to add comment