Advertisement
huutho_96

Đa Hình

May 21st, 2015
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. class NhanVien
  5. {
  6. protected:
  7. string Ten, NgaySinh;
  8. int Luong, LuongCoBan;
  9. virtual void Input(istream &in) = 0;
  10. virtual void Output(ostream &out) const = 0;
  11. public:
  12. virtual void TinhLuong() = 0;
  13. int LayLuong(){ return this->Luong; }
  14. friend istream& operator >> (istream &in, NhanVien &NV)
  15. {
  16. fflush(stdin);
  17. cout << "Nhap Ten: ";
  18. getline(in, NV.Ten);
  19. cout << "Nhap Ngay Sinh: ";
  20. getline(in, NV.NgaySinh);
  21. cout << "Nhap Luong Can Ban: ";
  22. in >> NV.LuongCoBan;
  23. fflush(stdin);
  24. NV.Input(in);
  25. return in;
  26. }
  27. friend ostream& operator << (ostream& out, const NhanVien &NV)
  28. {
  29. out << "Ten: " << NV.Ten << endl;
  30. out << "Ngay Sinh: " << NV.NgaySinh << endl;
  31. out << "Luong Can Ban: " << NV.LuongCoBan << endl;
  32. NV.Output(out);
  33. out << "Luong: " << NV.Luong << endl;
  34. return out;
  35. }
  36. };
  37.  
  38. class NhanVienVanPhong : public NhanVien
  39. {
  40. private:
  41. int SoNgayLamViec, TroCap;
  42. protected:
  43. virtual void Input(istream &in)
  44. {
  45. cout << "So Ngay Lam Viec: ";
  46. in >> SoNgayLamViec;
  47. cout << "Tro Cap: ";
  48. in >> TroCap;
  49. }
  50. virtual void Output(ostream &out) const
  51. {
  52. out << "So Ngay Lam Viec: " << SoNgayLamViec << endl;
  53. out << "Tro Cap: " << TroCap << endl;
  54. }
  55. public:
  56. void TinhLuong()
  57. {
  58. Luong = LuongCoBan + SoNgayLamViec * 200000 + TroCap;
  59. }
  60. };
  61.  
  62. class NhanVienQuanLy : public NhanVien
  63. {
  64. private:
  65. int HeSoChucVu, Thuong;
  66. protected:
  67. void Input(istream &in)
  68. {
  69. cout << "He So Chuc Vu: ";
  70. in >> HeSoChucVu;
  71. cout << "Thuong: ";
  72. in >> Thuong;
  73. }
  74. void Output(ostream &out) const
  75. {
  76. out << "He So Chuc Vu: " << HeSoChucVu << endl;
  77. out << "Thuong: " << Thuong << endl;
  78. }
  79. public:
  80. void TinhLuong()
  81. {
  82. Luong = LuongCoBan * HeSoChucVu + Thuong;
  83. }
  84. };
  85.  
  86. class NhanVienSanXuat : public NhanVien
  87. {
  88. private:
  89. int SoSanPham;
  90. protected:
  91. void Input(istream &in)
  92. {
  93. cout << "So San Pham: ";
  94. in >> SoSanPham;
  95. }
  96. void Output(ostream &out) const
  97. {
  98. cout << "So San Pham: " << SoSanPham << endl;
  99. }
  100. public:
  101. void TinhLuong()
  102. {
  103. Luong = LuongCoBan + SoSanPham * 2000;
  104. }
  105. };
  106.  
  107. class DanhSachNhanVien
  108. {
  109. private:
  110. NhanVien **NV;
  111. int SoNhanVien;
  112. int TongLuong;
  113. public:
  114. DanhSachNhanVien()
  115. {
  116. TongLuong = 0;
  117. SoNhanVien = 0;
  118. NV = NULL;
  119. }
  120. friend istream& operator >> (istream& in, DanhSachNhanVien &DS)
  121. {
  122. int LoaiNhanVien;
  123. cout << "Nhap So Nhan Vien: ";
  124. in >> DS.SoNhanVien;
  125. DS.NV = new NhanVien*[DS.SoNhanVien];
  126. for (int i = 0; i < DS.SoNhanVien; i++)
  127. {
  128. do
  129. {
  130. system("cls");
  131. cout << "1. Nhan Vien Van Phong\n2. Nhan Vien Quan Ly\n3. Nhan Vien San Xuat\n";
  132. cout << "Nhap so tuong ung: ";
  133. in >> LoaiNhanVien;
  134. } while (LoaiNhanVien < 1 || LoaiNhanVien > 3);
  135. switch (LoaiNhanVien)
  136. {
  137. case 1:
  138. DS.NV[i] = new NhanVienVanPhong;
  139. break;
  140. case 2:
  141. DS.NV[i] = new NhanVienQuanLy;
  142. break;
  143. case 3:
  144. DS.NV[i] = new NhanVienSanXuat;
  145. break;
  146. }
  147. in >> *DS.NV[i];
  148. }
  149. return in;
  150. }
  151. friend ostream& operator << (ostream& out, DanhSachNhanVien DS)
  152. {
  153. system("cls");
  154. for (int i = 0; i < DS.SoNhanVien; i++)
  155. {
  156. out << *DS.NV[i] << endl;
  157. }
  158. return out;
  159. }
  160. void TinhTongLuong()
  161. {
  162. for (int i = 0; i < SoNhanVien; i++)
  163. {
  164. NV[i]->TinhLuong();
  165. TongLuong += NV[i]->LayLuong();
  166. }
  167. }
  168. int GetTongLuong(){ return TongLuong; };
  169. ~DanhSachNhanVien()
  170. {
  171. //chưa có contructor sao chép nên việc truyền tham trị sẽ sinh ra lỗi nên mình không để destructor hoạt động
  172. /* for (int i = 0; i < SoNhanVien; i++)
  173. delete NV[i];*/
  174. }
  175. };
  176. void main()
  177. {
  178. DanhSachNhanVien DS;
  179. cin >> DS;
  180.  
  181. DS.TinhTongLuong();
  182. cout << DS.GetTongLuong();
  183. cout << DS;
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement