Advertisement
huutho_96

Hướng dẫn giải đề OOP học kì 1 năm 2015 - 2016 UIT

Jun 21st, 2016
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.97 KB | None | 0 0
  1. //#include <iostream>
  2. //using namespace std;
  3. //
  4. //class PhanSo
  5. //{
  6. //  int tuso, mauso;
  7. //public:
  8. //  PhanSo(int tu = 0, int mau = 1)
  9. //  {
  10. //      tuso = tu;
  11. //      mauso = mau;
  12. //  }
  13. //
  14. //  PhanSo operator + (PhanSo c) //*this b la PhanSo c
  15. //  {
  16. //      PhanSo p;
  17. //      p.tuso = this->tuso * c.mauso + this->mauso * c.tuso;
  18. //      p.mauso = this->mauso * c.mauso;
  19. //      return p;
  20. //  }
  21. //  void Xuat()
  22. //  {
  23. //      cout << this->tuso << " / " << this->mauso;
  24. //  }
  25. //};
  26. //
  27. //
  28. //
  29. //void main()
  30. //{
  31. //  PhanSo a;
  32. //  PhanSo b(1, 2);
  33. //  PhanSo c(3);
  34. //
  35. //  a = b + c;
  36. //  a.Xuat();
  37. //}
  38.  
  39. //NhanVien: ma nv, ho ten, tuoi, sdt, luong cb, mail, luong
  40. //LTV: so gio lam them
  41. //KCV: so loi phat hien duoc
  42.  
  43.  
  44. #include <iostream>
  45. #include <string>
  46. using namespace std;
  47.  
  48. class NhanVien
  49. {
  50. protected:
  51.     string MaNv, HoTen, SDT, Mail;
  52.     int Tuoi, Luong, LuongCB;
  53. public:
  54.     virtual void Nhap()
  55.     {
  56.         fflush(stdin);
  57.         cout << "HoTen: ";
  58.         getline(cin, HoTen);
  59.         cout << "MaNv: ";
  60.         getline(cin, MaNv);
  61.         cout << "Mail: ";
  62.         getline(cin, Mail);
  63.         cout << "SDT: ";
  64.         getline(cin, SDT);
  65.  
  66.         cout << "Tuoi: ";
  67.         cin >> Tuoi;
  68.         cout << "Luong co ban: ";
  69.         cin >> LuongCB;
  70.     }
  71.     virtual void Xuat()
  72.     {
  73.         cout << "HoTen: " << HoTen << endl;
  74.         cout << "MaNv: " << MaNv << endl;
  75.         cout << "Mail: " << Mail << endl;
  76.         cout << "SDT: " << SDT << endl;
  77.         cout << "Tuoi: " << Tuoi << endl;
  78.         cout << "Luong co ban: " << LuongCB << endl;
  79.     }
  80.     virtual void TinhLuong()
  81.     {
  82.  
  83.     }
  84.  
  85.     int LayLuong()
  86.     {
  87.         return Luong;
  88.     }
  89. };
  90. class LapTrinhVien : public NhanVien
  91. {
  92.     int SoGioLamThem;
  93. public:
  94.     void Nhap()
  95.     {
  96.         NhanVien::Nhap();
  97.         cout << "So gio lam them: ";
  98.         cin >> SoGioLamThem;
  99.     }
  100.     void Xuat()
  101.     {
  102.         NhanVien::Xuat();
  103.         cout << "So gio lam them: " << SoGioLamThem << endl;
  104.         cout << "Luong: " << Luong << endl;
  105.     }
  106.     void TinhLuong()
  107.     {
  108.         Luong = LuongCB + SoGioLamThem * 200000;
  109.     }
  110. };
  111. class KiemChungVien : public NhanVien
  112. {
  113.     int SoLoiPhatHien;
  114. public:
  115.     void Nhap()
  116.     {
  117.         NhanVien::Nhap();
  118.         cout << "So loi phat hien: ";
  119.         cin >> SoLoiPhatHien;
  120.     }
  121.     void Xuat()
  122.     {
  123.         NhanVien::Xuat();
  124.         cout << "So loi phat hien: " << SoLoiPhatHien << endl;
  125.         cout << "Luong: " << Luong << endl;
  126.     }
  127.     void TinhLuong()
  128.     {
  129.         Luong = LuongCB + SoLoiPhatHien * 50000;
  130.     }
  131. };
  132.  
  133.  
  134. class DSNV
  135. {
  136.     NhanVien *NV[1024];
  137.     int n;
  138. public:
  139.     void Nhap()
  140.     {
  141.         cout << "So nhan vien trong cong ty (n < 1024): ";
  142.         cin >> n;
  143.  
  144.         for (int i = 0; i < n; i++)
  145.         {
  146.             int c;
  147.             cout << "1. Lap trinh vien\n2. Kiem chung vien\nLua Chon: ";
  148.             cin >> c;
  149.  
  150.             if (c == 1)
  151.                 NV[i] = new LapTrinhVien();
  152.             else if (c == 2)
  153.                 NV[i] = new KiemChungVien();
  154.  
  155.             NV[i]->Nhap();
  156.             NV[i]->TinhLuong();
  157.         }
  158.     }
  159.  
  160.     void LietKe()
  161.     {
  162.         int LuongTB = 0;
  163.         for (int i = 0; i < n; i++)
  164.         {
  165.             LuongTB += NV[i]->LayLuong();
  166.         }
  167.         LuongTB = LuongTB / n;
  168.         for (int i = 0; i < n; i++)
  169.         {
  170.             if (NV[i]->LayLuong() <= LuongTB)
  171.                 NV[i]->Xuat();
  172.         }
  173.     }
  174. };
  175.  
  176.  
  177. void main()
  178. {
  179.     DSNV ds;
  180.     ds.Nhap();
  181.     ds.LietKe();
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement