Untitled

 avatar
unknown
plain_text
2 years ago
8.3 kB
13
Indexable
#include <iostream>
#include <vector>
using namespace std;

class nhanVien
{
protected:
    int ID;
    std::string hoTen;
    double luongCB;
    double luongHT;
public:
    virtual void xuat() = 0;
    virtual void tinhLuongHT() = 0;
    nhanVien(int ID, std::string hoTen, double luongCB, double luongHT)
    {
        this->ID = ID;
        this->hoTen = hoTen;
        this->luongCB = luongCB;
        this->luongHT = luongHT;

    }
    int getID()
    {
        return this->ID;
    }

    double getLuongHT()
    {
        return this->luongHT;
    }

    void setLuongCB(double luongCB)
    {
        this->luongCB = luongCB;
    }

    double getLuongCB()
    {
        return this->luongCB;
    }



};

class nhanVienVanPhong :public nhanVien
{
private:
    int soGioLam;
public:

    nhanVienVanPhong(int ID, std::string hoTen, double luongCB, int soGioLam, double luongHT) : nhanVien(ID, hoTen, luongCB, luongHT) 
    {
        this->soGioLam = soGioLam;
    }
    void xuat() override
    {
        cout << this->ID << " nhanVien VanPhong " << this->hoTen << " luong CB " << this->luongCB << " so gio lam " << this->soGioLam << " luong HT " << this->luongHT << endl;
    }

    void tinhLuongHT() override
    {
        if (this->soGioLam < 100)
            this->luongHT = (this->luongCB + this->soGioLam * 220000);
        else
            this->luongHT = (this->luongCB + this->soGioLam * 220000) + 5000000;
    }
};
class nhanVienSanXuat :public nhanVien
{
private:
    int soSanPham;
public:

    nhanVienSanXuat(int ID, std::string hoTen, double luongCB, int soSanPham, double luongHT) : nhanVien(ID, hoTen, luongCB, luongHT)
    {
        this->soSanPham = soSanPham;
    }
    void xuat() override
    {
        cout << this->ID << " nhanVien SanXuat " << this->hoTen << " luong CB " << this->luongCB << " so san pham " << this->soSanPham << " luong HT " << this->luongHT << endl;
    }

    void tinhLuongHT() override
    {
        if (this->soSanPham < 150)
            this->luongHT = (this->luongCB + this->soSanPham * 175000);
        else
            this->luongHT = (this->luongCB + this->soSanPham * 220000) * 1.2;

    }
};

class nhanVienQuanLy :public nhanVien
{
private:
    double heSoChucVu;
    double thuong;
public:
    nhanVienQuanLy(int ID, std::string hoTen, double luongCB, double heSoChucVu, double thuong, double luongHT) : nhanVien(ID, hoTen, luongCB, luongHT)
    {
        this->heSoChucVu = heSoChucVu;
        this->thuong = thuong;
    }
    void xuat() override
    {
        cout << this->ID << " nhanVien QuanLy " << this->hoTen << " luong CB " << this->luongCB << " so chuc vu " << this->heSoChucVu << " Thuong " << this->thuong << " luong HT " << this->luongHT << endl;
    }

    void tinhLuongHT() override
    {
        this->luongHT = this->luongCB * this->heSoChucVu + this->thuong;

    }
};
class daiLy
{
private:
    std::string ten;
    int ID;
    std::vector <nhanVien*> dsNhanVien;
    int soNhanVien;
public:
    daiLy(int ID, std::string ten)
    {
        this->ID = ID;
        this->ten = ten;

    }
    void taoDL() //cau 1
    {
        nhanVienVanPhong* NV0 = new nhanVienVanPhong(101, "Nguyen A", 4500000, 200, 0);
        nhanVienVanPhong* NV1 = new nhanVienVanPhong(102, "Nguyen B", 5600000, 100, 0);
        nhanVienVanPhong* NV2 = new nhanVienVanPhong(103, "Nguyen C", 8900000, 90, 0);

        nhanVienSanXuat* NV3 = new nhanVienSanXuat(201, "Nguyen D", 7800000, 250, 0);
        nhanVienSanXuat* NV4 = new nhanVienSanXuat(202, "Nguyen E", 4500000, 110, 0);
        nhanVienSanXuat* NV5 = new nhanVienSanXuat(203, "Nguyen F", 6600000, 360, 0);

        nhanVienQuanLy* NV6 = new nhanVienQuanLy(301, "Nguyen G", 8500000, 1.3, 19500000, 0);
        nhanVienQuanLy* NV7 = new nhanVienQuanLy(302, "Nguyen H", 7600000, 1.2, 18600000, 0);
        dsNhanVien.push_back(NV0);
        dsNhanVien.push_back(NV1);
        dsNhanVien.push_back(NV2);
        dsNhanVien.push_back(NV3);
        dsNhanVien.push_back(NV4);
        dsNhanVien.push_back(NV5);
        dsNhanVien.push_back(NV6);
        dsNhanVien.push_back(NV7);
        soNhanVien = dsNhanVien.size();
    }
    void xuat() //cau 2
    {
        for (int i = 0; i < soNhanVien; i++)
        {
            dsNhanVien[i]->xuat();
        }
    }
    /* cau 3
    Input dsNhanVien
    Output kham chieuy luong nhanVien vao ds */
    void tinhLuongHT() 
    {
        for (int i = 0; i < soNhanVien; i++)
        {
            dsNhanVien[i]->tinhLuongHT();
        }
        return;

    }

    /* cau 4 tim nv
   Input dsNhanVien
   Output return Nhanvien qua con tro */
    nhanVien* timNV(int ID)
    {
        for (int i = 0; i < soNhanVien; i++)
        {
            if (dsNhanVien[i]->getID() == ID)
            {
                return dsNhanVien[i];
            }
        }
    }

    /* cau 5 tim trung binh
Input dsNhanVien
Output return average can phai tra */
    double trungBinh()
    {
        double index = 0 ;
        for (int i = 0; i < soNhanVien; i++)
        {
            index = index + dsNhanVien[i]->getLuongHT();
        }
        return index / double(soNhanVien);
    }

    /* cau 6  cap nhat luong
Input dsNhanVien
Output kham chieu luong qua ds */
    void capNhat(int ID, double luong)
    {
        for (int i = 0; i < soNhanVien; i++)
        {
            if (dsNhanVien[i]->getID() == ID)
            {
                dsNhanVien[i]->setLuongCB(luong);
                return;
            }
        }
    }

    /* cau 4  tim nv max luong cb
Input dsNhanVien
Output return Nhanvien qua con tro */
    nhanVien* timNVMax()
    {
        double MAX = 0;
        int index = 0;
            for (int i = 0; i < soNhanVien; i++)
            {
                if (dsNhanVien[i]->getLuongCB() > MAX)
                {
                    MAX = dsNhanVien[i]->getLuongCB();
                    index = i;
                }
            }
        return dsNhanVien[index];
    }

    /* cau 7 tim nvsx luonght min
Input dsNhanVien
Output return Nhanvien qua con tro */
    nhanVien* timNVSXMin()
    {
        double Min = dsNhanVien[3]->getLuongHT();
        int index = 3;
        for (int i = 0; i < soNhanVien; i++)
        {
            if (dsNhanVien[i]->getID() > 200 && dsNhanVien[i]->getID() < 300)
            {
                if (dsNhanVien[i]->getLuongHT() < Min)
                {
                    Min = dsNhanVien[i]->getLuongHT();
                    index = i;
                }
            }
        }
        return dsNhanVien[index];
    }

    /* cau 4 tim nv cb
Input dsNhanVien
Output return std::vector<Nhanvien*>  ds nhan vien luong min */
    std::vector<nhanVien*> timMin()
    {
        std::vector<nhanVien*> dsMin;
        double Min = dsNhanVien[0]->getLuongCB();
        for (int i = 0; i < soNhanVien; i++)
        {
            if (dsNhanVien[i]->getLuongCB() < Min)
            {
                Min = dsNhanVien[i]->getLuongCB();
                
            }
        }

        for (int i = 0; i < soNhanVien; i++)
        {

            if (dsNhanVien[i]->getLuongCB() == Min)
            {
                dsMin.push_back(dsNhanVien[i]);

            }
        }
        return dsMin;

    }




};
int main()
{
    daiLy A(100, "UIT");
    A.taoDL(); //cau 1
    A.tinhLuongHT(); //cau 3
    A.xuat(); //cau 2
    cout << endl << endl;
    cout << endl << endl;
    nhanVien* index1 = A.timNV(201); //cau 4
    index1->xuat();
    cout << endl << endl;

    std::cout << A.trungBinh(); //cau 5
    cout << endl << endl;

    nhanVien* index2 = A.timNVMax(); //cau 7
    index2->xuat();
    cout << endl << endl;

    A.capNhat(202, 30002340);
    nhanVien* index112 = A.timNV(202); //cau 6
    index112->xuat();
    cout << endl << endl;

    nhanVien* index3 = A.timNVSXMin(); //cau 8
    index3->xuat();
    cout << endl << endl;

    std::vector <nhanVien*> index4;
    index4 = A.timMin();
    for (int i = 0; i < index4.size(); i++) //cau 9
    {
        index4[i]->xuat();
    }
}

Editor is loading...