Quản lý nhân viên

//
//  NhanVien.hpp
//  QLNS
//
//  Created by Toan Nguyen on 17/11/2020.
//

#ifndef NhanVien_hpp
#define NhanVien_hpp
#include <string>
using namespace std;
class NhanVien{
protected:
    string ten;
    string ngaysinh;
    long luong;
public:
    NhanVien();
    virtual void Nhap();
    virtual void Xuat() const;
    virtual void tinhluong()=0;
    virtual ~NhanVien();
};

#endif /* NhanVien_hpp */

//
//  NhanVien.cpp
//  QLNS
//
//  Created by Toan Nguyen on 17/11/2020.
//

#include "NhanVien.hpp"
#include <iostream>
using namespace std;
NhanVien::NhanVien():ten(""),ngaysinh("1/1/1950"),luong(0){
    
}
void NhanVien::Nhap(){
    cout << "Nhap ten:";
    getline(cin, this->ten);
    cout << "Nhap ngay sinh:";
    getline(cin, this->ngaysinh);
}
void NhanVien::Xuat()const{
    cout << "Ten:"<<this->ten<<"ngaysinh:"<<this->ngaysinh<<"luong:"<<this->luong<<endl;
}

NhanVien::~NhanVien(){}

//
//  NVVP.hpp
//  QLNS
//
//  Created by Toan Nguyen on 17/11/2020.
//

#ifndef NVVP_hpp
#define NVVP_hpp

#include "NhanVien.hpp"
class NVVP:public NhanVien{
protected:
    int snlv;
public:
    NVVP();
    void Nhap();
    void Xuat()const;
    void tinhluong();
};

#endif /* NVVP_hpp */

//
//  NVVP.cpp
//  QLNS
//
//  Created by Toan Nguyen on 17/11/2020.
//

#include "NVVP.hpp"
#include <iostream>
using  namespace std;

NVVP::NVVP():NhanVien(),snlv(0) {
    
}

void NVVP::Nhap() { 
    NhanVien::Nhap();
    cout << "Nhap so ngay lam viec:";
    cin >> this->snlv;
    cin.ignore();
}

void NVVP::Xuat() const { 
    NhanVien::Xuat();
    cout << "So ngay lam viec:"<< this->snlv<<endl;
}

void NVVP::tinhluong() { 
    this->luong = this->snlv*100;
}

//
//  NVSX.hpp
//  QLNS
//
//  Created by Toan Nguyen on 17/11/2020.
//

#ifndef NVSX_hpp
#define NVSX_hpp
#include "NhanVien.hpp"
class NVSX:public NhanVien{
protected:
    long luongcb;
    int ssp;
public:
    NVSX();
    void Nhap();
    void Xuat()const;
    void tinhluong();
};

#endif /* NVSX_hpp */

//
//  NVSX.cpp
//  QLNS
//
//  Created by Toan Nguyen on 17/11/2020.
//

#include "NVSX.hpp"
#include <iostream>
using namespace std;

NVSX::NVSX():NhanVien(),luongcb(0),ssp(0) {
    
}

void NVSX::Nhap() { 
    NhanVien::Nhap();
    cout << "Luong co ban:";
    cin >> this->luongcb;
    cout << "So san pham:";
    cin >> this->ssp;
    cin.ignore();
}

void NVSX::Xuat() const { 
    NhanVien::Xuat();
    cout << "Luong co ban:"<<this->luongcb << "So san pham:"<< this->ssp<<endl;
}

void NVSX::tinhluong() { 
    this->luong = luongcb + ssp*500;
}

//
//  CongTy.hpp
//  QLNS
//
//  Created by Toan Nguyen on 17/11/2020.
//

#ifndef CongTy_hpp
#define CongTy_hpp

#include "NhanVien.hpp"

class CongTy{
protected:
    NhanVien ** dsnv;
    int slnv;
public:
    CongTy();
    void NhapDS();
    void XuatDS()const;
    void TinhLuong();
    ~CongTy();
};

#endif /* CongTy_hpp */

//
//  CongTy.cpp
//  QLNS
//
//  Created by Toan Nguyen on 17/11/2020.
//

#include "CongTy.hpp"
#include "NVVP.hpp"
#include "NVSX.hpp"
#include <iostream>
using namespace  std;
CongTy::CongTy():dsnv(NULL),slnv(0) {
}

void CongTy::NhapDS() { 
    cout << "Nhap so luong nv";
    cin >> this->slnv;
    cin.ignore();
    if(this->slnv>0){
        int loai = 0;
        this->dsnv = new NhanVien*[this->slnv];
        for (int i=0; i<this->slnv; i++) {
            cout << "Chon loai nv (0-NVVP (default), 1-NVSX):";
            cin >>loai;
            cin.ignore();
            NhanVien * newNV;
            switch (loai) {
                case 0:
                    newNV = new NVVP();
                    break;
                case 1:
                    newNV = new NVSX();
                    break;
                default:
                    newNV = new NVVP();
                    break;
            }
            this->dsnv[i] = newNV;
            this->dsnv[i]->Nhap();
        }
    }else{
        cout << "Loi"<<endl;
    }
}

void CongTy::XuatDS() const { 
    for (int i=0; i < this->slnv; i++) {
        this->dsnv[i]->Xuat();
    }
}

void CongTy::TinhLuong() { 
    for (int i=0; i < this->slnv; i++) {
        this->dsnv[i]->tinhluong();
    }
}

CongTy::~CongTy() { 
    if(this->dsnv!=NULL){
        for (int i=0; i < this->slnv; i++) {
            delete this->dsnv[i];
        }
        delete [] this->dsnv;
    }
}

//
//  main.cpp
//  QLNS
//
//  Created by Toan Nguyen on 17/11/2020.
//

#include <iostream>
#include "CongTy.hpp"
int main(int argc, const char * argv[]) {
    CongTy ct;
    ct.NhapDS();
    ct.TinhLuong();
    ct.XuatDS();
    return 0;
}