Advertisement
huutho_96

Câu 3 cuối kì OOP Đại học CNTT

May 22nd, 2015
1,457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. //https://www.facebook.com/pages/C%C3%B9ng-h%E1%BB%8Dc-l%E1%BA%ADp-tr%C3%ACnh/632038696941833
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. class SinhVien
  7. {
  8. protected:
  9. string MSSV, HoTen, DiaChi;
  10. int TongChi;
  11. float DTB;
  12. virtual void Input(istream &in) = 0;
  13. virtual void Output(ostream &out) const = 0;
  14. public:
  15. friend istream& operator >> (istream& in, SinhVien &SV)
  16. {
  17. fflush(stdin);
  18. cout << "Ten: ";
  19. getline(in, SV.HoTen);
  20. cout << "MSSV: ";
  21. getline(in, SV.MSSV);
  22. cout << "Dia Chi: ";
  23. getline(in, SV.DiaChi);
  24. cout << "Tong Chi: ";
  25. in >> SV.TongChi;
  26. cout << "DTB: ";
  27. in >> SV.DTB;
  28. SV.Input(in);
  29. return in;
  30. }
  31. friend ostream& operator << (ostream& out, const SinhVien &SV)
  32. {
  33. fflush(stdin);
  34. out << "Ten: " << SV.HoTen << endl;
  35. out << "MSSV: " << SV.MSSV << endl;
  36. out << "Dia Chi: " << SV.DiaChi << endl;
  37. out << "Tong Chi: " << SV.TongChi << endl;
  38. out << "DTB: " << SV.DTB << endl;
  39. SV.Output(out);
  40. return out;
  41. }
  42. virtual int XetTotNghiep() = 0;
  43. float GetDTB(){ return this->DTB; }
  44. int KieuSinhVien;
  45. };
  46.  
  47. class SVDH : public SinhVien
  48. {
  49. private:
  50. string TenLuanVan;
  51. float DiemLV;
  52. public:
  53. void Input(istream &in)
  54. {
  55. fflush(stdin);
  56. cout << "Ten Luan Van: ";
  57. getline(in, this->TenLuanVan);
  58. cout << "Diem Luan Van: ";
  59. in >> this->DiemLV;
  60. }
  61. void Output(ostream &out) const
  62. {
  63. out << "Ten Luan Van: " << this->TenLuanVan << endl;
  64. out << "Diem Luan Van: " << this->DiemLV << endl;
  65. }
  66. int XetTotNghiep()
  67. {
  68. if (this->TongChi >= 170 && this->DiemLV >= 5.0 && this->DTB >= 5.0) return 1;
  69. return 0;
  70. }
  71.  
  72. };
  73.  
  74. class SVCD : public SinhVien
  75. {
  76. private:
  77. float DiemTN;
  78. public:
  79. void Input(istream &in)
  80. {
  81. cout << "Diem Tot Nghiep: ";
  82. in >> this->DiemTN;
  83. }
  84. void Output(ostream &out) const
  85. {
  86. out << "Diem Tot Nghiep: " << this->DiemTN << endl;
  87. }
  88. int XetTotNghiep()
  89. {
  90. if (this->TongChi >= 120 && this->DiemTN >= 5.0 && this->DTB >= 5.0) return 1;
  91. return 0;
  92. }
  93.  
  94. };
  95.  
  96. void main()
  97. {
  98. SinhVien **SV = NULL;
  99. int SoSinhVien, LuaChon;
  100. do
  101. {
  102. system("cls");
  103. cout << "So Sinh Vien Can Nhap: ";
  104. cin >> SoSinhVien;
  105. } while (SoSinhVien <= 0);
  106. SV = new SinhVien*[SoSinhVien];
  107.  
  108. for (int i = 0; i < SoSinhVien; i++)
  109. {
  110. system("cls");
  111. cout << " Nhap SV thu: " << i + 1 << endl;
  112. do
  113. {
  114. cout << "1. Dai Hoc\n2. Cao Dang\n\tLua chon: ";
  115. cin >> LuaChon;
  116. } while (LuaChon <= 0 || LuaChon >= 3);
  117. switch (LuaChon)
  118. {
  119. case 1:
  120. SV[i] = new SVDH;
  121. break;
  122. case 2:
  123. SV[i] = new SVCD;
  124. break;
  125. }
  126. SV[i]->KieuSinhVien = LuaChon;
  127. cin >> *SV[i];
  128. }
  129.  
  130. int SVTN = 0;
  131. for (int i = 0; i < SoSinhVien; i++)
  132. {
  133. if (SV[i]->XetTotNghiep() == 1) SVTN++;
  134. }
  135. cout << "So SV duoc tot nghiep: " << SVTN << endl;
  136. float max = -1;
  137. for (int i = 0; i < SoSinhVien; i++)
  138. {
  139. if (SV[i]->KieuSinhVien == 1)
  140. {
  141. if (max < SV[i]->GetDTB())
  142. {
  143. max = SV[i]->GetDTB();
  144. }
  145. }
  146. }
  147. if (max < 0) cout << "Ca truong deu thap diem, cu the DTB = 0\n";
  148. else cout << "SV Dai Hoc Co DTB Cao Nhat: " << max << endl;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement