Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class NhanVien
- {
- protected:
- string Ten, NgaySinh;
- int Luong, LuongCoBan;
- virtual void Input(istream &in) = 0;
- virtual void Output(ostream &out) const = 0;
- public:
- virtual void TinhLuong() = 0;
- int LayLuong(){ return this->Luong; }
- friend istream& operator >> (istream &in, NhanVien &NV)
- {
- fflush(stdin);
- cout << "Nhap Ten: ";
- getline(in, NV.Ten);
- cout << "Nhap Ngay Sinh: ";
- getline(in, NV.NgaySinh);
- cout << "Nhap Luong Can Ban: ";
- in >> NV.LuongCoBan;
- fflush(stdin);
- NV.Input(in);
- return in;
- }
- friend ostream& operator << (ostream& out, const NhanVien &NV)
- {
- out << "Ten: " << NV.Ten << endl;
- out << "Ngay Sinh: " << NV.NgaySinh << endl;
- out << "Luong Can Ban: " << NV.LuongCoBan << endl;
- NV.Output(out);
- out << "Luong: " << NV.Luong << endl;
- return out;
- }
- };
- class NhanVienVanPhong : public NhanVien
- {
- private:
- int SoNgayLamViec, TroCap;
- protected:
- virtual void Input(istream &in)
- {
- cout << "So Ngay Lam Viec: ";
- in >> SoNgayLamViec;
- cout << "Tro Cap: ";
- in >> TroCap;
- }
- virtual void Output(ostream &out) const
- {
- out << "So Ngay Lam Viec: " << SoNgayLamViec << endl;
- out << "Tro Cap: " << TroCap << endl;
- }
- public:
- void TinhLuong()
- {
- Luong = LuongCoBan + SoNgayLamViec * 200000 + TroCap;
- }
- };
- class NhanVienQuanLy : public NhanVien
- {
- private:
- int HeSoChucVu, Thuong;
- protected:
- void Input(istream &in)
- {
- cout << "He So Chuc Vu: ";
- in >> HeSoChucVu;
- cout << "Thuong: ";
- in >> Thuong;
- }
- void Output(ostream &out) const
- {
- out << "He So Chuc Vu: " << HeSoChucVu << endl;
- out << "Thuong: " << Thuong << endl;
- }
- public:
- void TinhLuong()
- {
- Luong = LuongCoBan * HeSoChucVu + Thuong;
- }
- };
- class NhanVienSanXuat : public NhanVien
- {
- private:
- int SoSanPham;
- protected:
- void Input(istream &in)
- {
- cout << "So San Pham: ";
- in >> SoSanPham;
- }
- void Output(ostream &out) const
- {
- cout << "So San Pham: " << SoSanPham << endl;
- }
- public:
- void TinhLuong()
- {
- Luong = LuongCoBan + SoSanPham * 2000;
- }
- };
- class DanhSachNhanVien
- {
- private:
- NhanVien **NV;
- int SoNhanVien;
- int TongLuong;
- public:
- DanhSachNhanVien()
- {
- TongLuong = 0;
- SoNhanVien = 0;
- NV = NULL;
- }
- friend istream& operator >> (istream& in, DanhSachNhanVien &DS)
- {
- int LoaiNhanVien;
- cout << "Nhap So Nhan Vien: ";
- in >> DS.SoNhanVien;
- DS.NV = new NhanVien*[DS.SoNhanVien];
- for (int i = 0; i < DS.SoNhanVien; i++)
- {
- do
- {
- system("cls");
- cout << "1. Nhan Vien Van Phong\n2. Nhan Vien Quan Ly\n3. Nhan Vien San Xuat\n";
- cout << "Nhap so tuong ung: ";
- in >> LoaiNhanVien;
- } while (LoaiNhanVien < 1 || LoaiNhanVien > 3);
- switch (LoaiNhanVien)
- {
- case 1:
- DS.NV[i] = new NhanVienVanPhong;
- break;
- case 2:
- DS.NV[i] = new NhanVienQuanLy;
- break;
- case 3:
- DS.NV[i] = new NhanVienSanXuat;
- break;
- }
- in >> *DS.NV[i];
- }
- return in;
- }
- friend ostream& operator << (ostream& out, DanhSachNhanVien DS)
- {
- system("cls");
- for (int i = 0; i < DS.SoNhanVien; i++)
- {
- out << *DS.NV[i] << endl;
- }
- return out;
- }
- void TinhTongLuong()
- {
- for (int i = 0; i < SoNhanVien; i++)
- {
- NV[i]->TinhLuong();
- TongLuong += NV[i]->LayLuong();
- }
- }
- int GetTongLuong(){ return TongLuong; };
- ~DanhSachNhanVien()
- {
- //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
- /* for (int i = 0; i < SoNhanVien; i++)
- delete NV[i];*/
- }
- };
- void main()
- {
- DanhSachNhanVien DS;
- cin >> DS;
- DS.TinhTongLuong();
- cout << DS.GetTongLuong();
- cout << DS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement