📄 quanlynhanvien.cpp
字号:
#include"iostream"
#include"iomanip"
#include"string"
#include"fstream"
#include"conio.h"
using namespace std;
struct Diadiem
{
char duong[30];
char pho[40];
char tpho[50];
};
// Dinh nghia lop cong viec
class CONGVIEC
{
private:
char maviec[10];
char tenviec[60];
int sogio;
long luong;
public:
void nhap();
void hien();
void docfile(int socv);
void ghifile();
int dem();
void intt(int i);
friend class NHANVIEN;
};
// Dinh nghia lop chuc vu
class CHUCVU
{
private:
char macv[10];
char tencv[60];
char yeucau[100];
public:
void nhap();
void hien();
void docfile(int socvu);
void ghifile();
int dem();
void intt(int i);
friend class NHANVIEN;
};
// Dinh nghia lop phong
class PHONG
{
private:
char maphong[10];
char tenphong[60];
char matp[10];
Diadiem ddiem;
public:
void nhap();
void hien();
void docfile(int sop);
void ghifile();
int dem();
void intt(int i);
friend class NHANVIEN;
};
// Dinh nghia lop nhan vien
class NHANVIEN
{
private:
char manv[10];
char tennv[60];
char ngaysinh[12];
char ngayvaocty[12];
CHUCVU cvu;
CONGVIEC cviec;
PHONG phong;
Diadiem dc;
public:
void nhap();
void hien();
void docfile(int sonv);
void ghifile();
int dem();
void tim_ten();
void tim_chucvu();
void intt(int i);
void sua();
};
void NHANVIEN::nhap()
{
bool j;
char ch;
NHANVIEN t;
do
{
cout<<"\nBan hay nhap ma mot nhan vien:\n";
do
{
j=false;
cin.ignore();
cout<<"ma nhan vien:";
cin.get(manv,10);
for(int i=0;i<t.dem();i++)
{
t.docfile(i);
if(strcmp(manv,t.manv)==0)
{
cout<<"\n Ma nhan vien da ton tai, moi ban nhap lai:";
j=true;
break;
}
}
}
while(j==true);
cin.ignore();
cout<<"\n ho va ten:";
cin.getline (tennv,60);
cout<<"\n ngaysinh:";
cin.getline(ngaysinh,12);
cout<<"\n ngay vao cty:";
cin.getline(ngayvaocty,12);
cout<<"\n chuc vu la:";
cin.getline(cvu.tencv,60);
cout<<"\n phong nv nay lam viec";
cin.getline(phong.tenphong,60);
cout<<"\n cviec ma nhan vien nay lam viec:";
cin.getline(cviec.tenviec,60);
cout<<"\n nhap vao dia chi cua nhan vien:\n";
cin.getline(dc.duong,30);
cin.getline(dc.pho,40);
cin.getline(dc.tpho,50);
ghifile();
cout<<"Ban co muon nhap tiep khong?y/n:";
cin>>ch;
}
while(ch!='n');
}
void NHANVIEN::hien()
{
int i=0;
while(i<dem())
{
intt(i);
i++;
}
}
int NHANVIEN ::dem()
{
fstream g;
g.open("NHANVIEN.DAT", ios::binary|ios::in| ios::ate);
if(!g.good())
return 0;
else return (int)g.tellg()/sizeof(NHANVIEN);
}
void NHANVIEN::ghifile()
{
fstream f;
f.open("NHANVIEN.DAT",ios::binary|ios::out|ios::app|ios::in);
if (f.bad())
{
cout<<"co loi mo file";
exit(1);
}
f.write((char*)this, sizeof(*this));
f.close();
}
void NHANVIEN::docfile(int sonv)
{
fstream f;
f.open("NHANVIEN.DAT",ios::binary|ios::in|ios::app|ios::out);
if (f.bad())
{
cout<<"co loi mo file";
exit(1);
}
f.seekg(sonv*sizeof(NHANVIEN));
f.read((char*)this, sizeof(*this));
f.close();
}
void NHANVIEN::sua()
{
int i;
cout<<"Ban hay nhap vao vi tri can sua\n";
cin>>i;
docfile(i);
cout<<"sua lai la:";
cin.ignore();
cout<<"\n ho va ten:";
cin.getline (tennv,60);
cout<<"\n ngaysinh:";
cin.getline(ngaysinh,12);
cout<<"\n ngay vao cty:";
cin.getline(ngayvaocty,12);
cout<<"\n chuc vu la:";
cin.getline(cvu.tencv,60);
cout<<"\n phong nv nay lam viec";
cin.getline(phong.tenphong,60);
cout<<"\n cviec ma nhan vien nay lam viec:";
cin.getline(cviec.tenviec,60);
cout<<"\n nhap vao dia chi cua nhan vien:\n";
cin.getline(dc.duong,30);
cin.getline(dc.pho,40);
cin.getline(dc.tpho,50);
fstream f;
f.open("NHANVIEN.DAT",ios::binary|ios::out|ios::app|ios::in);
if (f.bad())
{
cout<<"co loi mo file";
exit(1);
}
f.seekg(-sizeof(NHANVIEN),ios::cur);
f.write((char*)this, sizeof(*this));
f.close();
}
void NHANVIEN::tim_ten()
{
NHANVIEN t;
char ch, ten[60];
do
{
cin.ignore();
cout<<"Hay nhap vao ten nhan vien can tim:";
cin.getline(ten,60);
for(int i=0;i<t.dem();i++)
{
t.docfile(i);
if(strcmpi(ten,t.tennv)==0)
{
t.intt(i);
}
}
cout<<"\n Ban co muon tim tiep khong?y/n:";
cin>>ch;
}
while(ch!='n');
}
void NHANVIEN::tim_chucvu()
{
NHANVIEN t;
char ch, c[60];
do
{
cin.ignore();
cout<<"Hay nhap vao chuc vu can tim:";
cin.getline(c,60);
for(int i=0;i<t.dem();i++)
{
t.docfile(i);
if(strcmpi(c,t.cvu.tencv)==0)
{
t.intt(i);
}
}
cout<<"\n Ban co muon tim tiep khong?y/n:";
cin>>ch;
}
while(ch!='n');
}
void NHANVIEN::intt(int i)
{
docfile(i);
cout<<setprecision(1)<<setiosflags(ios::showpoint);
cout<<setw(6)<<manv
<<""<<setw(20)<<tennv
<<""<<setw(12)<<ngaysinh
<<""<<setw(12)<<ngayvaocty
<<""<<setw(15)<<cvu.tencv
<<""<<setw(15)<<cviec.tenviec
<<""<<setw(25)<<phong.tenphong
<<""<<setw(20)<<dc.duong
<<""<<setw(20)<<dc.pho
<<""<<setw(20)<<dc.tpho<<" ";
cout<<endl;
}
void CONGVIEC::nhap()
{
bool j;
char ch;
CONGVIEC t;
do
{
cout<<"Ban hay nhap ma mot cong viec:";
do
{
j=0;
cin.ignore();
cout<<"\n ma cong viec:";
cin.get(maviec,20);
for(int i=0;i<t.dem();i++)
{
t.docfile(i);
if(strcmp(maviec,t.maviec)==0)
{
cout<<"\n Ma cong viec da ton tai, moi ban nhap lai:";
j=true;
break;
}
}
}
while(j==true);
cin.ignore();
cout<<"\n ten viec:";
cin.getline (tenviec,60);
cout<<"\n so gio lam:";
cin>>sogio;
cout<<"\n muc luong duoc huong:";
cin>>luong;
ghifile();
cout<<"Ban co muon nhap tiep khong?y/n:";
cin>>ch;
}
while(ch!='n');
}
void CONGVIEC::intt(int i)
{
docfile(i);
cout<<setprecision(1)<<setiosflags(ios::showpoint);
cout<<setw(4) <<maviec
<<""<<setw(20)<<tenviec
<<""<<setw(12)<<sogio
<<""<<setw(15)<<luong<<" ";
cout<<endl;
}
void CONGVIEC::hien()
{
int i=0;
while(i<dem())
{
intt(i);
i++;
}
}
int CONGVIEC::dem()
{
fstream g;
g.open("CONGVIEC.DAT",ios::binary|ios::in| ios::ate);
if(!g.good())
return 0;
else return (int)g.tellg()/sizeof(CONGVIEC);
}
void CONGVIEC::ghifile()
{
fstream f;
f.open("CONGVIEC.DAT",ios::binary|ios::out|ios::app|ios::in);
if (f.bad())
{
cout<<"co loi mo file";
exit(1);
}
f.write((char*)this, sizeof(*this));
f.close();
}
void CONGVIEC::docfile(int socv)
{
fstream f;
f.open("CONGVIEC.DAT",ios::binary|ios::in|ios::app|ios::out);
if (f.bad())
{
cout<<"co loi mo file";
exit(1);
}
f.seekg(socv*sizeof(CONGVIEC));
f.read((char*)this, sizeof(*this));
f.close();
}
void CHUCVU::nhap()
{
bool j;
char ch;
CHUCVU t;
do
{
cout<<"\n Ban hay nhap ma chuc vu:";
do
{
j=false;
cin.ignore();
cout<<"\n ma chuc vu:";
cin.get(macv,20);
for(int i=0;i<t.dem();i++)
{
t.docfile(i);
if(strcmp(macv,t.macv)==0)
{
cout<<"\n Ma chuc vu da ton tai, moi ban nhap lai:";
j=true;
break;
}
}
}
while(j==true);
cin.ignore();
cout<<"\n ten chuc vu:";
cin.getline(tencv,60);
cout<<"\n yeu cau:";
cin.getline(yeucau,100);
ghifile();
cout<<"Ban co muon nhap tiep khong?y/n:";
cin>>ch;
}
while(ch!='n');
}
void CHUCVU::intt(int i)
{
docfile(i);
cout<<setprecision(1)<<setiosflags(ios::showpoint);
cout<<setw(4) <<macv
<<setw(20)<<tencv
<<setw(30)<<yeucau<<" ";
cout<<endl;
}
void CHUCVU::hien()
{
int i=0;
while(i<dem())
{
intt(i);
i++;
}
}
int CHUCVU::dem()
{
fstream g;
g.open("CHUCVU.DAT", ios::binary| ios::in| ios::ate);
if(!g.good())
return 0;
else return (int)g.tellg()/sizeof(CHUCVU);
}
void CHUCVU::ghifile()
{
fstream f;
f.open("CHUCVU.DAT",ios::binary|ios::out|ios::app| ios::in);
if (f.bad())
{
cout<<"co loi mo file";
exit(1);
}
f.write((char*)this, sizeof(*this));
f.close();
}
void CHUCVU::docfile(int socvu)
{
fstream f;
f.open("CHUCVU.DAT",ios::binary| ios::in|ios::app|ios::out);
if (f.bad())
{
cout<<"co loi mo file";
exit(1);
}
f.seekg(socvu*sizeof(CHUCVU));
f.read((char*)this, sizeof(*this));
f.close();
}
void PHONG::nhap()
{
bool j;
char ch;
PHONG t;
do
{
cout<<"Ban hay nhap mot ma phong:";
do
{
j=false;cin.ignore();
cout<<"\n ma phong:";
cin.get(maphong,20);
for(int i=0;i<t.dem();i++)
{
t.docfile(i);
if(strcmp(maphong,t.maphong)==0)
{
cout<<"\n Ma phong da ton tai, moi ban nhap lai:";
j=true;
break;
}
}
}
while(j==true);
cin.ignore();
cout<<"\n phong ten la";
cin.getline(tenphong,60);
cout<<"\n truong phong la:";
cin.getline(matp,10);
cout<<"nhap vao dia chi cua phong:\n";
cin.getline(ddiem.duong,30);
cin.getline(ddiem.pho,40);
cin.getline(ddiem.tpho,50);
ghifile();
cout<<"Ban co muon nhap tiep khong?y/n:";
cin>>ch;
}
while(ch!='n');
}
void PHONG::intt(int i)
{
docfile(i);
cout<<setprecision(1)<<setiosflags(ios::showpoint);
cout<<setw(6)<<maphong
<<setw(20)<<tenphong
<<setw(12)<<matp
<<setw(20)<<ddiem.duong
<<setw(20)<<ddiem.pho
<<setw(20)<<ddiem.tpho<<" ";
cout<<endl;
}
void PHONG::hien()
{
int i=0;
while(i<dem())
{
intt(i);
i++;
}
}
int PHONG::dem()
{
fstream g;
g.open("PHONG.DAT", ios::binary|ios::in|ios::ate);
if(!g.good())
return 0;
else return (int)g.tellg()/sizeof(PHONG);
}
void PHONG::ghifile()
{
fstream f;
f.open("PHONG.DAT",ios::binary|ios::out|ios::app|ios::in);
if (f.bad())
{
cout<<"co loi mo file";
exit(1);
}
f.write((char*)this, sizeof(*this));
f.close();
}
void PHONG::docfile(int sop)
{
fstream f;
f.open("PHONG.DAT",ios::binary| ios::in|ios::app|ios::out);
if (f.bad())
{
cout<<"co loi mo file";
exit(1);
}
f.seekg(sop*sizeof(PHONG));
f.read((char*)this, sizeof(*this));
f.close();
}
void main()
{
NHANVIEN nv2;
CONGVIEC cv2;
CHUCVU cvu2;
PHONG p2;
int k; char ch;
do
{
cout<<"\n**********************************************";
cout<<"\n* HE THONG QUAN LY NHAN VIEN *";
cout<<"\n* 1:Nhap nhan vien moi *";
cout<<"\n* 2:In ra thong tin ve cac nhan vien *";
cout<<"\n* 3:Tim nhan vien theo ten *";
cout<<"\n* 4:Tim nhan vien theo chuc vu *";
cout<<"\n* 5:Nhap thong tin ve cong viec *";
cout<<"\n* 6:In thong tin ve cong viec *";
cout<<"\n* 7:Nhap thong tin ve chuc vu cua nhan vien *";
cout<<"\n* 8:In thong tin ve chuc vu cua nhan vien *";
cout<<"\n* 9:Nhap thong tin ve cac phong *";
cout<<"\n* 10:In thong tin ve phong *";
cout<<"\n* 11:Gioi thieu *";
cout<<"\n* 13:Thoat Khoi Chuong Trinh( An 1phin bat ki)";
cout<<"\n* 12:sua thong tin nhan vien *";
cout<<"\n***********************************************";
cout<<"\n Moi ban chon cong viec: ";
cin>>k;
switch (k)
{
case 1:
{nv2.nhap();break;}
case 2:
{nv2.hien();break;}
case 3:
{nv2.tim_ten();break;}
case 4:
{nv2.tim_chucvu();break;}
case 5:
{cv2.nhap();break;}
case 6:
{cv2.hien();break;}
case 7:
{cvu2.nhap();break;};
case 8:
{cvu2.hien();break;}
case 9:
{p2.nhap();break;}
case 10:
{p2.hien();break;}
case 11:
{
cout<<"\n TruongDai Hoc Su pham Ha Noi"
<<"\n Khoa Cong Nghe Thong Tin"
<<"\n Bai Tap Lon C++"
<<"\n Chuong trinh Quan Li Nhan vien "
<<"\n Nhom SV K56C"
<<"\n Xin Cam On";
break;
}
case 12:
{nv2.sua();break;}
default:exit(1);
};
cout<<"\n Ban Co Muon Thu Hien Chuc Nang Khac Khong?(y/n)";
ch=getch();
}
while((ch!='k')&&(ch!='n'));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -