#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;
class NHANVIEN
{
private:
string ma;
string hoTen;
int tuoi;
string sdt;
string email;
float luongCoBan;
public:
NHANVIEN();
float GetLuongCoBan();
virtual void Nhap();
virtual void Xuat();
virtual int GetLoai()=0;
virtual float TinhLuong()=0;
virtual ~NHANVIEN();
};
NHANVIEN::NHANVIEN()
{
ma="";
hoTen="";
tuoi=0;
sdt="";
email="";
luongCoBan=0;
}
void NHANVIEN::Nhap()
{
cout<<"nhap ma nhan vien: ";
fflush(stdin);
getline(cin, ma);
cout<<"nhap ho va ten nhan vien: ";
fflush(stdin);
getline(cin,hoTen);
cout<<"nhap tuoi: ";
cin>>tuoi;
cout<<"nhap so die thoai: ";
fflush(stdin);
cin>>sdt;
cout<<"nhap email: ";
fflush(stdin);
getline(cin, email);
cout<<"nha luong co ban: ";
cin>>luongCoBan;
}
void NHANVIEN::Xuat()
{
cout<<"ma nhan vien: "<<ma<<endl;
cout<<"ho ten: "<<hoTen<<endl;
cout<<"tuoi: "<<tuoi<<endl;
cout<<"so dien thoai: "<<sdt<<endl;
cout<<"email: "<<email<<endl;
cout<<"luong co ban: "<<fixed<<setprecision(0)<<luongCoBan<<endl;
}
float NHANVIEN::GetLuongCoBan()
{
return luongCoBan;
}
NHANVIEN::~NHANVIEN() {
}
class DEV :public NHANVIEN
{
private:
int soGioOT;
public:
DEV();
void Nhap();
void Xuat();
int GetLoai();
float TinhLuong();
~DEV();
};
DEV::DEV()
{
soGioOT=0;
}
void DEV::Nhap()
{
NHANVIEN::Nhap();
cout<<"nhap so gio overtimme: ";
cin>>soGioOT;
}
void DEV::Xuat()
{
NHANVIEN::Xuat();
cout<<"so gio OT: "<<soGioOT<<endl;
}
int DEV::GetLoai()
{
return 1;
}
float DEV::TinhLuong()
{
return GetLuongCoBan() + soGioOT*200000;
}
DEV::~DEV(){
}
class TESTER:public NHANVIEN
{
private:
int soError;
public:
TESTER();
void Nhap();
void Xuat();
int GetLoai();
float TinhLuong();
~TESTER();
};
TESTER::TESTER()
{
soError=0;
}
void TESTER::Nhap()
{
NHANVIEN::Nhap();
cout<<"nhap so loi phat hien duoc: ";
cin>>soError;
}
void TESTER::Xuat()
{
NHANVIEN::Xuat();
cout<<"so loi phat hien duoc: "<<soError<<endl;
}
int TESTER::GetLoai()
{
return 2;
}
float TESTER::TinhLuong()
{
return GetLuongCoBan() + soError*5000;
}
TESTER::~TESTER() {
}
class COMPANY
{
private:
vector<NHANVIEN*>dS;
public:
void NhapDS();
void XuatDS();
float TinhLuongTrungBinh();
void LietKeNVThapHonLuongTB();
~COMPANY();
};
void COMPANY::NhapDS()
{
int soNV;
cout<<"nhap so luong nhan vien can them: ";
cin>>soNV;
for(int i=0;i<soNV;i++)
{
NHANVIEN*t=NULL;
int loaiNV;
do
{
cout<<"nhap loai nhan vien can them(1:DEV/2:tester): ";
cin>>loaiNV;
}while(cin.fail()||(loaiNV<1||loaiNV>2));
}
}
void COMPANY::XuatDS()
{
for(unsigned int i=0;i<dS.size();i++)
{
if(dS[i]->GetLoai()==1)
cout<<"DEVELOPER"<<endl;
else
cout<<"TESTER"<<endl;
dS[i]->Xuat();
}
cout<<endl;
}
float COMPANY::TinhLuongTrungBinh()
{
float tongLuong=0;
for(unsigned int i=0;i<dS.size();i++)
tongLuong= tongLuong+dS[i]->TinhLuong();
return 1.0*tongLuong / dS.size();
}
void COMPANY::LietKeNVThapHonLuongTB()
{
for(unsigned int i=0;i<dS.size();i++)
{
if(dS[i]->TinhLuong()<TinhLuongTrungBinh())
{
dS[i]->Xuat();
cout<<endl;
}
}
}
COMPANY::~COMPANY()
{
for(unsigned int i=0;i<dS.size();i++)
{
delete dS[i];
}
dS.clear();
}
int main()
{
COMPANY cty;
cout<<"nhap danh sach nhan vien: "<<endl;
cty.NhapDS();
cout<<"danh sach nhan vien la: "<<endl;
cty.XuatDS();
cout<<"danh sach nhan vien co muc luong thap hon muc trung binh la: "<<endl;
cty.LietKeNVThapHonLuongTB();
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.