Quan ly nhan su bang c++

tuyendungnvip

Thành viên
Tham gia
21/9/2016
Bài viết
3
#include<iostream>
#include<vector>
using namespace std;

class NhanVien
{
protected:
string Manv;
string HoTen;
string DiaChi;
int Tuoi;
int GioiTinh;
public:
NhanVien()
{
HoTen="";
}
virtual void NhapTT();
virtual void XuatTT();

};

class NhanVienSX:public NhanVien
{
private:
int Sosp;
public:
NhanVienSX()
{
Sosp=0;
}
void NhapTT();
void XuatTT();
int TinhLuong();
};

class NhanVienKT:public NhanVien
{
private:
int Ngaycong, Ngaynghi;
public:
NhanVienKT()
{
Ngaycong=0;
Ngaynghi=0;
}
void NhapTT();
void XuatTT();
int TinhLuong();
};

// quan ly chung
class QuanLyNhanVien
{
private:
vector<NhanVien*> dsnhanvien; //vector<kieu cha> tenvector, kieucha la kieu con tro
public:
void NhapDanhSach();
void XuatDanhSach();

};
//ham main chinh
//bool KiemTra(string masv, int &vitri); //ham kiem tra su ton tai cua sinh vien

int main()
{
QuanLyNhanVien QLNV;
int luachon;

do
{
system("cls");
cout<<"QUAN LY NHAN SU"<<endl;
cout<<"1. Nhap nhan vien"<<endl;
cout<<"2. Xuat nhan vien"<<endl;
//cout<<"3. Xoa nhan vien"<<endl;

cout<<"Hay Chon: ";
cin>>luachon;
switch (luachon)
{
case 1:
{
QLNV.NhapDanhSach();
break;
}
case 2:
{
QLNV.XuatDanhSach();
cout<<"\nXuat thanh cong! Hay nhan phim bat ky de quay lai menu";
system("pause");
break;
}
/*case 3:
{
string htsv;//khai bao bien
cout<<"\n Sua thong tin nhan vien"<<endl;
cin.ignore();
cout<<"Nhap ten nhan vien can tim: ";
getline(cin,htsv);
bool kt;
int vitri;
kt=KiemTra(htsv,vitri); //goi lai ham kiemtra
if(kt)
{
cout<<"Nhap lai thong tin"<<endl;
QLNV.NhapDanhSach();
break;
}
else
cout<<"Khong tin thay nhan vien"<<endl;
cout<<"\nHay nhan phim bat ky de quay lai menu";
system("PAUSE");

break;
}*/
}

} while (luachon !=0);
}

//dinh nghi ham thanh vien nhap/xuat class NhanVien
void NhanVien::NhapTT()
{
cin.ignore();
cout<<"Ma nhan vien: ";
getline(cin,Manv);
cout<<"Ho ten nhan vien: ";
getline(cin,HoTen);
cout<<"Dia chi nhan vien: ";
getline(cin,DiaChi);
cout<<"Tuoi nhan vien: ";
cin>>Tuoi;
cout<<"Gioi tinh nhan vien: ";
cin>>GioiTinh;
}
void NhanVien::XuatTT()
{
cout<<"\nMa nhan vien: "<<Manv<<endl;
cout<<"Ho ten: "<<HoTen<<endl;
cout<<"Dia chi: "<<DiaChi<<endl;
cout<<"Tuoi nhan vien: "<<Tuoi<<endl;
cout<<"Gioi tinh nhan vien: "<<GioiTinh<<endl;

}
// ham tp trong class NhanVienSX
void NhanVienSX::NhapTT()
{
NhanVien::NhapTT();
cout<<"So san pham: ";
cin>>Sosp;
}

void NhanVienSX::XuatTT()
{
NhanVien::XuatTT();
cout<<"So san pham: "<<Sosp<<endl;
cout<<"Luong: "<<TinhLuong()<<endl;

}
// ham tp trong class NhanVienKT
void NhanVienKT::NhapTT()
{
NhanVien::NhapTT();
cout<<"So ngay cong: ";
cin>>Ngaycong;
cout<<"So ngay nghi: ";
cin>>Ngaynghi;
}
void NhanVienKT::XuatTT()
{
NhanVien::XuatTT();
cout<<"Ngay cong: "<<Ngaycong<<endl;
cout<<"Ngay nghi: "<<Ngaynghi<<endl;
cout<<"Luong: "<<TinhLuong()<<endl;
}

//dinh nghi ham nhap.xuatdanhsach
void QuanLyNhanVien::NhapDanhSach()
{

int luachon;
NhanVien* nv; //khai bao 1 con tro kieu cha(NhanVien)
do
{
system("cls");
cout<<"1. Nhan vien san xuat"<<endl;
cout<<"2. Nhan vien ke toan"<<endl;
cout<<"3. Thoat"<<endl;
cout<<"Hay chon (1-3): ";
cin>>luachon;
switch (luachon)
{
case 1:
{
nv = new NhanVienSX(); //cap phat cho nv 1 class NhanVienSX (bien hinh sang lop nhanviensx)
nv->NhapTT(); // khi nv tro den ham nhaptt thi ham nhaptt la ham nhap tt cua lop nhanviensx va chay ham nhap cua lop nvsx
dsnhanvien.push_back(nv);//them nv vao trong vector dsnhanvien

break;

}
case 2:
{
nv = new NhanVienKT();
nv->NhapTT();
dsnhanvien.push_back(nv);

break;
}
case 3:
break;
}
} while (luachon !=3);
}

void QuanLyNhanVien::XuatDanhSach()
{
for(int i=0; i< dsnhanvien.size();i++)
{
dsnhanvien->XuatTT();
cout<<"------------------------"<<endl;
}
}

int NhanVienSX::TinhLuong()
{
int Luong=0;
Luong = Sosp*100;
return Luong;
}

int NhanVienKT::TinhLuong()
{
int Luong=0;
Luong=Ngaycong*200-(Ngaynghi*200);
return Luong;
}
//dinh nghia ham bool kiem tra nhan vien ton tai
/*bool KiemTra(string htsv, int &vitri)
{
bool kt=false; //mac dinh ban dau nhan vien ko ton tai
for(int i=0;i<data;i++)
if(htsv==SV.)
{
vitri=i; // tra vi tri xuat hien nhan vien trong data
kt=true; //nhan vien da co trong data
break;
}
return kt;
}*/

//ham tinh luong cua 2 class nhan vien
 
×
Quay lại
Top