You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

456 lines
12 KiB

#include "workermanager.h"
WorkerManager::WorkerManager() {
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// 1<><31><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ifstream ifs;
ifs.open(FILENAME, ios::in); // <20><><EFBFBD>ļ<EFBFBD>
if (!ifs.is_open()) {
cout << "<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD>ó<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>Ϊ0
this->m_EmpNum = 0;
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
this->m_EmpArray = NULL;
// <20><>ʼ<EFBFBD><CABC><EFBFBD>ļ<EFBFBD><C4BC>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA>
this->m_FileIsEmpty = true;
ifs.close();
return;
}
// 2<><32><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
char ch;
ifs >> ch;
if (ifs.eof()) {
// <20>ļ<EFBFBD>Ϊ<EFBFBD><CEAA>
cout << "<EFBFBD>ļ<EFBFBD>Ϊ<EFBFBD><EFBFBD>!" << endl;
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD>ó<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>Ϊ0
this->m_EmpNum = 0;
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
this->m_EmpArray = NULL;
// <20><>ʼ<EFBFBD><CABC><EFBFBD>ļ<EFBFBD><C4BC>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA>
this->m_FileIsEmpty = true;
ifs.close(); // <20>ر<EFBFBD><D8B1>ļ<EFBFBD>
return;
}
// 3<><33><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD>Ҽ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>
int num = this->get_EmpNum();
cout << "ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>" << num << endl;
this->m_EmpNum = num;
// <20><><EFBFBD>ٿռ<D9BF>
this->m_EmpArray = new worker*[this->m_EmpNum];
// <20><><EFBFBD>ļ<EFBFBD><C4BC>е<EFBFBD><D0B5><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
this->init_Emp();
// <20><><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
/*
for (int i = 0; i < this->m_EmpNum; i++)
{
cout << "ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>" << this->m_EmpArray[i]->m_Id
<< "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << this->m_EmpArray[i]->m_Name
<< "ְλ<EFBFBD><EFBFBD>" << this->m_EmpArray[i]->m_DeptId;
}
*/
}
// չʾ<D5B9>˵<EFBFBD>
void WorkerManager::Show_Menu() {
cout << "*********ְ<><D6B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ****************" << endl;
cout << "0<EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ" << endl;
cout << "2<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾԱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ" << endl;
cout << "3<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְԱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ" << endl;
cout << "4<EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ" << endl;
cout << "5<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ" << endl;
cout << "6<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ձ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "7<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>" << endl;
cout << "*************************************" << endl;
cout << endl;
}
// 0------------------<2D>˳<EFBFBD>ϵͳ
void WorkerManager::ExitSystem() {
cout << "<EFBFBD><EFBFBD>ӭ<EFBFBD>´<EFBFBD>ʹ<EFBFBD><EFBFBD>" << endl;
system("pause");
exit(0); // <20>˳<EFBFBD>
}
// 1------------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
void WorkerManager::Add_Emp() {
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
int addNum = 0; // <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cin >> addNum; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (addNum > 0) {
// <20><><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¿ռ<C2BF><D5BC><EFBFBD>С
int newSize =
this->m_EmpNum + addNum; // <20>¿ռ<C2BF><D5BC><EFBFBD><EFBFBD><EFBFBD><><D4AD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD>¿ռ<C2BF>
worker** newspace = new worker*[newSize];
// <20><>ԭ<EFBFBD><D4AD><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¿ռ<C2BF><D5BC><EFBFBD>
if (this->m_EmpArray != NULL) {
for (int i = 0; i < this->m_EmpNum; i++) {
newspace[i] = this->m_EmpArray[i];
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0; i < addNum; i++) {
int id; // ְ<><D6B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
string name; // ְ<><D6B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int dselect; // <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << i + 1 << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>" << endl;
cin >> id;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << i + 1 << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cin >> name;
cout << "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD>ְλ<EFBFBD><EFBFBD>" << endl;
cout << "1-<2D><>ͨԱ<CDA8><D4B1>" << endl;
cout << "2-<2D><><EFBFBD><EFBFBD>" << endl;
cout << "3-<2D>ϰ<EFBFBD>" << endl;
cin >> dselect;
worker* worker = NULL;
switch (dselect) // <20><><EFBFBD>ݲ<EFBFBD>ͬ<EFBFBD><CDAC>ְλ<D6B0><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>ְ<EFBFBD><D6B0>
{
case 1:
worker = new Employee(id, name, 1);
break;
case 2:
worker = new Manager(id, name, 2);
break;
case 3:
worker = new Boss(id, name, 3);
break;
default:
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
break;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><D6B0>ְ<EFBFBD>𣬱<EFBFBD><F0A3ACB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
newspace[this->m_EmpNum + i] = worker;
}
// <20>ͷ<EFBFBD>ԭ<EFBFBD>пռ<D0BF>
delete[] this->m_EmpArray;
// <20><><EFBFBD><EFBFBD><EFBFBD>¿ռ<C2BF><D5BC><EFBFBD>ָ<EFBFBD><D6B8>
this->m_EmpArray = newspace;
// <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
this->m_EmpNum = newSize;
// <20><><EFBFBD><EFBFBD>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD>Ϊ<EFBFBD>ձ<EFBFBD>־
this->m_FileIsEmpty = false;
// <20><>ʾ<EFBFBD><CABE><EFBFBD>ӳɹ<D3B3>
cout << "<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << addNum << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD>" << endl;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5>ļ<EFBFBD><C4BC><EFBFBD>
this->save();
} else {
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD>һ<EFBFBD><D2BB>Ŀ¼
system("pause");
system("cls");
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
void WorkerManager::save() {
ofstream ofs; // ͨ<><CDA8><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>ofs<66><73><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
ofs.open(FILENAME, ios::out); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>---д<>ļ<EFBFBD>
for (int i = 0; i < this->m_EmpNum; i++) // <20><>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
{
ofs << this->m_EmpArray[i]->m_Id << " " << this->m_EmpArray[i]->m_Name
<< " " << this->m_EmpArray[i]->m_DeptId << endl;
}
ofs.close(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󣬹ر<F3A3ACB9><D8B1>ļ<EFBFBD>
}
// 3<><33><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD>Ҽ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4>
int WorkerManager::get_EmpNum() {
ifstream ifs;
ifs.open(FILENAME, ios::in); // <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
int id;
string name;
int dId;
int num = 0;
while (ifs >> id && ifs >> name && ifs >> dId) {
// <20><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>
num++;
}
ifs.close();
return num;
}
// <20><>ʼ<EFBFBD><CABC>Ա<EFBFBD><D4B1>
void WorkerManager::init_Emp() {
ifstream ifs;
ifs.open(FILENAME, ios::in);
int id;
string name;
int dId;
int index = 0; // <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
while (ifs >> id && ifs >> name && ifs >> dId) // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
{
worker* worker = NULL;
// <20><><EFBFBD>ݲ<EFBFBD>ͬ<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>id<69><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>
if (dId == 1) // 1<><31>ְͨ<CDA8><D6B0>
{
worker = new Employee(id, name, dId);
} else if (dId == 2) // 2<><32><EFBFBD><EFBFBD>
{
worker = new Manager(id, name, dId);
} else // 3<>ϰ<EFBFBD>
{
worker = new Boss(id, name, dId);
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
this->m_EmpArray[index] = worker;
index++;
}
// <20>ر<EFBFBD><D8B1>ļ<EFBFBD>
ifs.close();
}
// 2------------------<2D><>ʾְ<CABE><D6B0>
void WorkerManager::Show_Emp() {
// <20>ж<EFBFBD><D0B6>ļ<EFBFBD><C4BC>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA>
if (this->m_FileIsEmpty) {
cout << "<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><EFBFBD><EFBFBD>¼Ϊ<EFBFBD>գ<EFBFBD>" << endl;
} else {
for (int i = 0; i < m_EmpNum; i++) {
// <20><><EFBFBD>ö<EFBFBD>̬<EFBFBD><CCAC><EFBFBD>ýӿ<C3BD>
this->m_EmpArray[i]->showInfo();
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
system("pause");
system("cls");
}
// 3------------------ɾ<><C9BE>ְ<EFBFBD><D6B0>
void WorkerManager::Del_Emp() {
if (this->m_FileIsEmpty) // Ϊ<><CEAA>
{
cout << "<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><EFBFBD>߼<EFBFBD>¼Ϊ<EFBFBD>գ<EFBFBD>" << endl;
} else {
// <20><><EFBFBD><EFBFBD>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>" << endl;
int id = 0;
cin >> id;
int index = this->IsExist(id); // <20><><EFBFBD>ܷ<EFBFBD><DCB7><EFBFBD>ֵ
if (index != -1) // ˵<><CBB5>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD>indexλ<78><CEBB><EFBFBD>ϵ<EFBFBD>ְ<EFBFBD><D6B0>
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>Ԫ<EFBFBD><D4AA>
for (int i = index; i < this->m_EmpNum - 1; i++) {
this->m_EmpArray[i] = this->m_EmpArray[i + 1]; // <20><>ֵ
}
this->m_EmpNum--; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD>¼<EFBFBD><C2BC>Ա
this->save(); // <20><>Ҫ<EFBFBD><EFBFBD><E3A3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
cout << "ɾ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>" << endl;
} else {
cout << "ɾ<EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>δ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD>" << endl;
}
// <20><><EFBFBD><EFBFBD>
system("pause");
system("cls");
}
}
// <20>ж<EFBFBD>ְ<EFBFBD><D6B0><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>λ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>-1
int WorkerManager::IsExist(int id) {
int index = -1;
for (int i = 0; i < this->m_EmpNum; i++) {
if (this->m_EmpArray[i]->m_Id == id) {
// <20>ҵ<EFBFBD>ְ<EFBFBD><D6B0>
index = i;
break;
}
}
return index; // <20><><EFBFBD><EFBFBD>ֵ
}
// 4------------------<2D>޸<EFBFBD>ְ<EFBFBD><D6B0>
void WorkerManager::Mod_Emp() {
if (this->m_FileIsEmpty) // <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
cout << "<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><EFBFBD>߼<EFBFBD>¼Ϊ<EFBFBD>գ<EFBFBD>" << endl;
} else // <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
{
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD>ţ<EFBFBD>" << endl;
int id;
cin >> id;
int ret = this->IsExist(id); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (ret != -1) {
// <20><><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD>ŵ<EFBFBD>ְ<EFBFBD><D6B0>
delete this->m_EmpArray[ret]; // <20>ͷ<EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int newId = 0; // <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD>Ϣ
string newName = "";
int dSelect = 0;
cout << "<EFBFBD><EFBFBD><EFBFBD>" << id << "<EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>" << endl;
cin >> newId;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cin >> newName;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>" << endl;
cout << "1-<2D><>ͨԱ<CDA8><D4B1>" << endl;
cout << "2-<2D><><EFBFBD><EFBFBD>" << endl;
cout << "3-<2D>ϰ<EFBFBD>" << endl;
cin >> dSelect;
worker* worker = NULL;
switch (dSelect) // <20><><EFBFBD>÷<EFBFBD>֧<EFBFBD><EFBFBD><E1B9B9>ʵ<EFBFBD><CAB5><EFBFBD>޸ĵĹ<C4B5><C4B9><EFBFBD>
{
case 1: // <20><>ͨԱ<CDA8><D4B1>
worker = new Employee(newId, newName, dSelect);
break;
case 2: // <20><><EFBFBD><EFBFBD>
worker = new Manager(newId, newName, dSelect);
break;
case 3: // <20>ϰ<EFBFBD>
worker = new Boss(newId, newName, dSelect);
break;
default:
break;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
this->m_EmpArray[ret] = worker;
cout << "<EFBFBD>޸ijɹ<EFBFBD><EFBFBD><EFBFBD>" << endl;
// <20><><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
this->save();
} else {
cout << "<EFBFBD>޸<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>޴<EFBFBD><EFBFBD>ˣ<EFBFBD>" << endl;
}
}
system("pause");
system("cls");
}
// 5------------------<2D><><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1>
void WorkerManager ::Find_Emp() {
if (this->m_FileIsEmpty) {
cout << "<EFBFBD>ļ<EFBFBD>Ϊ<EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>" << endl;
} else {
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҷ<EFBFBD>ʽ<EFBFBD><EFBFBD>" << endl;
cout << "1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
int select = 0;
cin >> select;
if (select == 1) // <20><>ְ<EFBFBD><D6B0><EFBFBD>Ų<EFBFBD><C5B2><EFBFBD>
{
int id;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>" << endl;
cin >> id;
int ret = IsExist(id);
if (ret != -1) {
cout << "<EFBFBD><EFBFBD><EFBFBD>ҳɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>" << endl;
this->m_EmpArray[ret]->showInfo(); // <20><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>֮ǰд<C7B0>ĺ<EFBFBD><C4BA><EFBFBD>
} else {
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>޴<EFBFBD><EFBFBD><EFBFBD>" << endl;
}
} else if (select == 2) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
string name; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cin >> name;
bool flag = false; // <20><><EFBFBD>ҵ<EFBFBD><D2B5>ı<EFBFBD>־<EFBFBD><D6BE>Ĭ<EFBFBD><C4AC>û<EFBFBD><C3BB><EFBFBD>ҵ<EFBFBD>ְ<EFBFBD><D6B0>
for (int i = 0; i < m_EmpNum; i++) {
if (m_EmpArray[i]->m_Name == name) {
if (m_EmpArray[i]->m_Name == name) {
cout << "<EFBFBD><EFBFBD><EFBFBD>ҳɹ<EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>" << m_EmpArray[i]->m_Id
<< "<EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>" << endl;
flag = true; // <20>ҵ<EFBFBD>Ϊture
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>Ϣ<EFBFBD>ӿ<EFBFBD>
this->m_EmpArray[i]->showInfo();
}
}
if (flag == false) {
// <20><><EFBFBD>޴<EFBFBD><DEB4><EFBFBD>
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>޴<EFBFBD><EFBFBD>ˣ<EFBFBD>" << endl;
}
}
} else {
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
}
}
system("pause");
system("cls");
}
// 6------------------<2D><><EFBFBD>ձ<EFBFBD><D5B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void WorkerManager::Sort_Emp() {
if (this->m_FileIsEmpty) {
cout << "<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><EFBFBD><EFBFBD>¼Ϊ<EFBFBD>գ<EFBFBD>" << endl;
system("pause");
system("cls");
} else {
cout << "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>" << endl;
cout << "1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ձ<EFBFBD><EFBFBD>Ž<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ձ<EFBFBD><EFBFBD>Ž<EFBFBD><EFBFBD>н<EFBFBD><EFBFBD><EFBFBD>" << endl;
int select = 0;
cin >> select;
for (int i = 0; i < m_EmpNum; i++) {
int minOrMax = i; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сֵ<D0A1><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>±<EFBFBD>
for (int j = i + 1; j < this->m_EmpNum; j++) // <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
{
if (select == 1) // <20><><EFBFBD><EFBFBD>
{
if (this->m_EmpArray[minOrMax]->m_Id > this->m_EmpArray[j]->m_Id) {
minOrMax = j; // <20><><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>
}
} else // <20><><EFBFBD><EFBFBD>
{
if (this->m_EmpArray[minOrMax]->m_Id < this->m_EmpArray[j]->m_Id) {
minOrMax = j;
}
}
}
// <20>ж<EFBFBD>һ<EFBFBD><D2BB>ʼ<EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сֵ<D0A1>Dz<EFBFBD><C7B2>Ǽ<EFBFBD><C7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сֵ<D0A1><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǽ<EFBFBD><C7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (i != minOrMax) {
// <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA>
worker* temp = this->m_EmpArray[i];
m_EmpArray[i] = this->m_EmpArray[minOrMax];
m_EmpArray[minOrMax] = temp;
}
}
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>" << endl;
this->save(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
this->Show_Emp(); // չʾ<D5B9><CABE><EFBFBD>е<EFBFBD>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Show_Emp<6D><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB2BB>Ҫ<EFBFBD><D2AA>д
}
}
// 7------------------<2D><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
void WorkerManager::Clean_File() {
cout << "ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>գ<EFBFBD>" << endl;
cout << "1-<2D><>" << endl;
cout << "2-<2D><>" << endl;
int select = 0;
cin >> select;
if (select == 1) {
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
ofstream ofs(
FILENAME,
ios::trunc); // <20><><EFBFBD><EFBFBD>ģʽios::trunc,<2C><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><><C9BE><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD>
ofs.close();
if (this->m_EmpArray != NULL) {
// ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0; i < this->m_EmpNum; i++) // <20>ͷŶ<CDB7><C5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
this->m_EmpArray[i] == NULL;
delete this->m_EmpArray[i];
}
// ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
this->m_EmpNum = 0;
delete[] this->m_EmpArray;
this->m_EmpArray = NULL;
this->m_FileIsEmpty = true;
}
cout << "<EFBFBD><EFBFBD><EFBFBD>ճɹ<EFBFBD><EFBFBD><EFBFBD>" << endl;
}
system("pause");
system("cls");
}
WorkerManager::
~WorkerManager() // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷŶ<CDB7><C5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>Բ<EFBFBD>д<EFBFBD>ȳ<EFBFBD><C8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>
{
if (this->m_EmpArray !=
NULL) // <20><><EFBFBD>ڲ<EFBFBD>ά<EFBFBD><CEAC><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD>ͷţ<CDB7><C5A3>ٰѶ<D9B0><D1B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>
{
for (int i = 0; i < this->m_EmpNum; i++) {
if (this->m_EmpArray[i] != NULL) {
delete this->m_EmpArray;
}
}
delete[] this->m_EmpArray;
this->m_EmpArray = NULL;
}
}