# include <iostream>
# include <fstream>
# include <iomanip>
using namespace std;
class NHANSU
{
protected:
char mans[10];
char hoten[25];
int tuoi;
public:
void NHAP();
};
class BIENCHE : public NHANSU
{
protected:
int nambc;
float heso;
public:
void NHAP_BC();
void INRA_BC();
void SUA_BC();
};
class HOPDONG : public NHANSU
{
protected:
int namhd;
float luong;
public:
void NHAP_HD();
void INRA_HD();
void SUA_HD();
private:
};
void NHANSU::NHAP()
{
cout << "Ma Nhan Su : "; cin.getline(mans, 10);
cout << "Ho va Ten: "; cin.getline(hoten, 25);
cout << "Tuoi : "; cin >> tuoi; cin.ignore();
}
void BIENCHE::NHAP_BC()
{
BIENCHE bc;
fstream FW;
char ok;
FW.open("BIENCHE.DAT", ios::out);
cout << "\n Nhap nhan su bien che: \n";
while (1)
{
bc.NHAP();
cout << "Nam vao BC : "; cin >> bc.nambc; cin.ignore();
cout << "He so luong: "; cin >> bc.heso; cin.ignore();
FW.write((char*)&bc, sizeof(bc));
cout << "\n Tiep tuc (C/K) ?"; cin >> ok; cin.ignore();
if (ok == 'k' || ok == 'K') break;
}
FW.close();
}
void BIENCHE::INRA_BC()
{
BIENCHE bc;
fstream FR;
FR.open("BIENCHE.DAT", ios::in);
if (FR.fail()) { cout << "\n Loi mo tep tin"; return; }
cout << "\n Danh sach nhan su Bien Che \n";
int TT = 1;
while (FR.read((char*)&bc, sizeof(bc)))
{
cout << "\n" << setw(3) << TT << " ";
cout << setw(10) << bc.mans << setw(25) << bc.hoten << setw(8) << bc.nambc
<< setw(7) << bc.heso;
TT = TT + 1;
}
FR.close();
}
void BIENCHE::SUA_BC()
{
BIENCHE bc;
fstream FW;
int n; char ok;
cout << "\n Nhap ban ghi can sua:";
cin >> n; cin.ignore();
FW.open("BIENCHE.DAT", ios::in | ios::out);
if (FW.fail()) { cout << " \n Loi mo tep "; return; }
cout << "\n nhap du lieu sua lai:\n ";
cout << "Ma nhan su: "; cin.getline(bc.mans, 10);
cout << "Ho va ten : "; cin.getline(bc.hoten, 25);
cout << "Tuoi:"; cin>>bc.tuoi; cin.ignore();
cout << "Nam vao BC:"; cin >> bc.nambc; cin.ignore();
cout << "He so luong: "; cin >> bc.heso; cin.ignore();
cout << "\nNhap nua khong (C/K) ? ";
cin >> ok; cin.ignore();
FW.seekp((n - 1) * sizeof(bc)); //chuyen con tron den ban ghi thu n
if (ok == 'c' || ok == 'C') FW.write((char*)&bc, sizeof(bc)); //ghi lai ban ghi
FW.close();
}
void HOPDONG::NHAP_HD()
{
HOPDONG hd;
fstream FW;
char ok;
FW.open("HOPDONG.DAT", ios::out);
cout << "\nNhap nhan su hop dong\n ";
while (1)
{
hd.NHAP();
cout << "Nam vao hop dong: "; cin >> hd.namhd; cin.ignore();
cout << "Luong : "; cin >> hd.luong; cin.ignore();
FW.write((char*)&hd, sizeof(hd));
cout << "\nTiep tuc (C/K) ? ";
cin >> ok; cin.ignore();
if (ok == 'k' || ok == 'K') break;
}
FW.close();
}
void HOPDONG::INRA_HD()
{
HOPDONG hd;
fstream FR;
FR.open("HOPDONG.DAT", ios::in);
if (FR.fail()) { cout << "\n Loi mo tep tin"; return; }
cout << "\n\t\tDANH SACH NHAN SU HOP DONG\n";
int TT = 1;
while (FR.read((char*)&hd, sizeof(hd)))
{
cout << "\n" << setw(3) << TT << " ";
cout << setw(10) << hd.mans << setw(25) << hd.hoten
<< setw(5) << hd.tuoi << setw(8) << hd.namhd
<< setw(15) << hd.luong;
TT = TT + 1;
}
FR.close();
}
void HOPDONG::SUA_HD()
{
HOPDONG hd;
fstream FW;
int n; char ok;
cout << "\nNhap so ban ghi can sua: ";
cin >> n; cin.ignore();
FW.open("HOPDONG.DAT", ios::in | ios::out);
if (FW.fail()) { cout << "\nLoi mo tep"; return; }
cout << "\nNhap du lieu sua lai:\n";
cout << "\nMa nhan su: "; cin.getline(hd.mans, 10);
cout << "Ho va ten : "; cin.getline(hd.hoten, 25);
cout << "Tuoi : "; cin >> hd.tuoi; cin.ignore();
cout << "Nam vao HD : "; cin >> hd.namhd; cin.ignore();
cout << "Luong : "; cin >> hd.luong; cin.ignore();
cout << "\nCo ghi lai khong ? (C/K) ";
cin >> ok; cin.ignore();
FW.seekg((n - 1) * sizeof(hd));
if (ok == 'c' || ok == 'C')
FW.write((char*)&hd, sizeof(hd));
FW.close();
}
int main()
{
BIENCHE bc;
bc.NHAP_BC();
bc.INRA_BC();
bc.SUA_BC();
bc.INRA_BC();
HOPDONG hd;
hd.NHAP_HD();
hd.INRA_HD();
hd.SUA_HD();
hd.INRA_HD();
cin.ignore();
}