欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于C++實(shí)現(xiàn)職工管理系統(tǒng)

 更新時(shí)間:2022年06月05日 09:31:21   作者:鎃龘?  
這篇文章主要為大家詳細(xì)介紹了基于C++實(shí)現(xiàn)職工管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C++實(shí)現(xiàn)職工管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

1、管理系統(tǒng)需求

職工管理系統(tǒng)可以用來(lái)管理公司內(nèi)所有員工的信息

利用C++來(lái)實(shí)現(xiàn)一個(gè)基于多態(tài)的職工管理系統(tǒng)

公司中職工分為三類:普通員工、經(jīng)理、老板,顯示信息時(shí),需要顯示職工編號(hào)、職工姓名、職工崗位、以及職責(zé)

普通員工職責(zé):完成經(jīng)理交給的任務(wù)

經(jīng)理職責(zé):完成老板交給的任務(wù),并下發(fā)任務(wù)給員工

老板職責(zé):管理公司所有事務(wù)

管理系統(tǒng)中需要實(shí)現(xiàn)的功能如下:

  • 退出管理程序:退出當(dāng)前管理系統(tǒng)
  • 增加職工信息:實(shí)現(xiàn)批量添加職工功能,將信息錄入到文件中,職工信息為:職工編號(hào)、姓名、部門編號(hào)
  • 顯示職工信息:顯示公司內(nèi)部所有職工的信息
  • 刪除離職職工:按照編號(hào)刪除指定的職工
  • 修改職工信息:按照編號(hào)修改職工個(gè)人信息
  • 查找職工信息:按照職工的編號(hào)或者職工的姓名進(jìn)行查找相關(guān)的人員信息
  • 按照編號(hào)排序:按照職工編號(hào),進(jìn)行排序,排序規(guī)則由用戶指定
  • 清空所有文檔:清空文件中記錄的所有職工信息 (清空前需要再次確認(rèn),防止誤刪)

我們創(chuàng)建以下多個(gè)頭文件和與其對(duì)應(yīng)的 .cpp文件:

boss.h頭文件

#pragma once
#include <iostream>
using namespace std;
#include <string>
#include "Worker.h"

//老板類
class Boss :public Worker
{
public:

?? ?Boss(int id, string name, int post);

?? ?//顯示個(gè)人信息
?? ?virtual void ShowInfo();

?? ?//獲取崗位名稱
?? ?virtual string getPost();

};

manager.h 頭文件

class Manager :public Worker
{
public:

?? ?Manager(int id, string name, int post);

?? ?//顯示個(gè)人信息
?? ?virtual void ShowInfo();

?? ?//獲取崗位名稱
?? ?virtual string getPost();

};

employee.h頭文件

class Employee:public Worker
{
public:

?? ?Employee(int id,string name,int post);

?? ?//顯示個(gè)人信息
?? ?virtual void ShowInfo();

?? ?//獲取崗位名稱
?? ?virtual string getPost();

};

worker.h頭文件

//職工抽象類
class Worker
{
public:
?? ?//顯示個(gè)人信息
?? ?virtual void ShowInfo() = 0;

?? ?//獲取崗位名稱
?? ?virtual string getPost() = 0;

?? ?//職員編號(hào)
?? ?int m_Id;
?? ?//職工姓名
?? ?string m_Name;
?? ?//部門編號(hào)
?? ?int m_Post;
};

worker_Manager.h頭文件

#pragma once
#include <iostream>
using namespace std;
#include "boss.h"
#include "manager.h"
#include "Worker.h"
#include "employee.h"
#include <fstream>
#define TXT "empfine.txt"

//各程序執(zhí)行的類
class Worker_Manager
{
public:
?? ?Worker_Manager();

?? ?//顯示菜單
?? ?void ShowMenu();

?? ?//記錄職工人數(shù)
?? ?int m_EmpNum;

?? ?//職工指針數(shù)組
?? ?Worker** m_EmpArray;

?? ?//添加職工
?? ?void Add_Emp();

?? ?//保存文件
?? ?void save();

?? ?//判斷文件是否為空
?? ?bool m_File;

?? ?//統(tǒng)計(jì)文件中的人數(shù)
?? ?int get_EmpNum();

?? ?//初始化員工
?? ?void In_Emp();

?? ?//顯示員工
?? ?void Show_Emp();

?? ?//判斷職工是否存在
?? ?int Ison_Emp(int id);

?? ?//刪除員工
?? ?void Del_Emp();

?? ?//修改員工
?? ?void Mod_Emp();

?? ?//查找員工
?? ?void Find_Emp();

?? ?//排序
?? ?void Sort_Emp();

?? ?//清空文件
?? ?void Clean_File();


?? ?~Worker_Manager();

};

boss.cpp文件

#include "boss.h"

Boss::Boss(int id, string name, int post)
{
?? ?this->m_Id = id;
?? ?this->m_Name = name;
?? ?this->m_Post = post;
}

//顯示個(gè)人信息
void Boss::ShowInfo()
{
?? ?cout << "職工編號(hào):" << this->m_Id
?? ??? ?<< "\t職工姓名:" << this->m_Name
?? ??? ?<< "\t職工部門:" << this->getPost()
?? ??? ?<< "\t崗位職責(zé):管理公司所有事務(wù)" << endl;
}

//獲取崗位名稱
string Boss::getPost()
{
?? ?return string("老板");
}

manager.cpp文件

#include "manager.h"

Manager::Manager(int id, string name, int post)
{
?? ?this->m_Id = id;
?? ?this->m_Name = name;
?? ?this->m_Post = post;
}

//顯示個(gè)人信息
void Manager::ShowInfo()
{
?? ?cout << "職工編號(hào):" << this->m_Id
?? ??? ?<< "\t職工姓名:" << this->m_Name
?? ??? ?<< "\t職工部門:" << this->getPost()
?? ??? ?<< "\t崗位職責(zé):完成老板布置的任務(wù),并下發(fā)任務(wù)給員工" << endl;
}

//獲取崗位名稱
string Manager::getPost()
{
?? ?return string("經(jīng)理");
}

employee.cpp文件

#include "employee.h"

Employee::Employee(int id, string name, int post)
{
?? ?this->m_Id = id;
?? ?this->m_Name = name;
?? ?this->m_Post = post;
}

//顯示個(gè)人信息
void Employee::ShowInfo()
{
?? ?cout << "職工編號(hào):" << this->m_Id
?? ??? ?<< "\t職工姓名:" << this->m_Name
?? ??? ?<< "\t職工部門:" << this->getPost()
?? ??? ?<< "\t崗位職責(zé):完成經(jīng)理布置的任務(wù)" << endl;
}

//獲取崗位名稱
string Employee::getPost()
{
?? ?return string("員工");
}

worker_Manager.cpp文件

#include "worker_Manager.h"

Worker_Manager::Worker_Manager()
{
?? ?//1、文件不存在
?? ?ifstream ifs;
?? ?ifs.open(TXT, ios::in);
?? ?if (!ifs.is_open())
?? ?{
?? ??? ?//cout << "文件不存在" << endl;
?? ??? ?//初始化屬性
?? ??? ?//初始化記錄人數(shù)
?? ??? ?this->m_EmpNum = 0;
?? ??? ?//初始化指針數(shù)組
?? ??? ?this->m_EmpArray = NULL;
?? ??? ?//初始化文件是否為空
?? ??? ?this->m_File = true;
?? ??? ?ifs.close();
?? ??? ?return;
?? ?}
?? ?
?? ?//2、文件存在,但為空
?? ?char ch;
?? ?ifs >> ch;
?? ?if (ifs.eof())
?? ?{
?? ??? ?//cout << "文件為空" << endl;
?? ??? ?//初始化屬性
?? ??? ?//初始化記錄人數(shù)
?? ??? ?this->m_EmpNum = 0;
?? ??? ?//初始化指針數(shù)組
?? ??? ?this->m_EmpArray = NULL;
?? ??? ?//初始化文件是否為空
?? ??? ?this->m_File = true;
?? ??? ?ifs.close();
?? ??? ?return;
?? ?}

?? ?//3.文件存在且數(shù)據(jù)不為空
?? ?int num = this->get_EmpNum();
?? ?this->m_EmpNum = num;

?? ?//開辟空間
?? ?this->m_EmpArray = new Worker * [this->m_EmpNum];
?? ?//將文件中的數(shù)據(jù),存到數(shù)組中
?? ?this->In_Emp();
}

void Worker_Manager::ShowMenu()
{
?? ?cout << "****************************************" << endl;
?? ?cout << "******* 歡迎來(lái)到職工管理系統(tǒng)!******" << endl;
?? ?cout << "********* 0.退出管理程序 **********" << endl;
?? ?cout << "********* 1.增加職工信息 **********" << endl;
?? ?cout << "********* 2.顯示職工信息 **********" << endl;
?? ?cout << "********* 3.刪除職工信息 **********" << endl;
?? ?cout << "********* 4.修改職工信息 **********" << endl;
?? ?cout << "********* 5.查找職工信息 **********" << endl;
?? ?cout << "********* 6.職工編號(hào)排序 **********" << endl;
?? ?cout << "********* 7.清空所有文檔 **********" << endl;
}


void Worker_Manager::Add_Emp()
{
?? ?cout << "請(qǐng)輸入要添加職工數(shù)量:" << endl;

?? ?//保存用戶的輸入數(shù)量
?? ?int addNum = 0;
?? ?cin >> addNum;

?? ?if (addNum > 0)
?? ?{
?? ??? ?//計(jì)算添加新空間的大小
?? ??? ?int newSize = this->m_EmpNum + addNum;//新空間人數(shù)=原來(lái)的人數(shù)+新增加的人數(shù)

?? ??? ?//開辟新空間
?? ??? ?Worker** newSpace= new Worker * [newSize];

?? ??? ?//將原來(lái)的數(shù)據(jù)拷貝到新空間去

?? ??? ?if (this->m_EmpArray != NULL)
?? ??? ?{
?? ??? ??? ?for (int i = 0; i < this->m_EmpNum; i++)
?? ??? ??? ?{
?? ??? ??? ??? ?newSpace[i] = this->m_EmpArray[i];
?? ??? ??? ?}
?? ??? ?}

?? ??? ?//添加新數(shù)據(jù)
?? ??? ?for (int i = 0; i < addNum; i++)
?? ??? ?{
?? ??? ??? ?int id;
?? ??? ??? ?string name;
?? ??? ??? ?int post;
?? ??? ??? ?cout << "請(qǐng)輸入第 " << i + 1 << "個(gè)新職工的編號(hào): " << endl;
?? ??? ??? ?cin >> id;

?? ??? ??? ?cout << "請(qǐng)輸入第 " << i + 1 << "個(gè)新職工的姓名: " << endl;
?? ??? ??? ?cin >> name;

?? ??? ??? ?cout << "請(qǐng)選擇職工崗位: " << endl;
?? ??? ??? ?cout << "1、普通員工" << endl;
?? ??? ??? ?cout << "2、經(jīng)理" << endl;
?? ??? ??? ?cout << "3、老板" << endl;
?? ??? ??? ?cin >> post;

?? ??? ??? ?Worker* worker = NULL;
?? ??? ??? ?switch (post)
?? ??? ??? ?{
?? ??? ??? ?case 1:
?? ??? ??? ??? ?worker = new Employee(id, name, post);
?? ??? ??? ??? ?break;
?? ??? ??? ?case 2:
?? ??? ??? ??? ?worker = new Manager(id, name, post);
?? ??? ??? ??? ?break;
?? ??? ??? ?case 3:
?? ??? ??? ??? ?worker = new Boss(id, name, post);
?? ??? ??? ??? ?break;
?? ??? ??? ?default:
?? ??? ??? ??? ?cout << "錯(cuò)誤輸入" << endl;
?? ??? ??? ??? ?break;
?? ??? ??? ?}
?? ??? ??? ?//將創(chuàng)建的職工指針,保存到數(shù)組中
?? ??? ??? ?newSpace[this->m_EmpNum + i] = worker;
?? ??? ?}
?? ??? ?//釋放原指針
?? ??? ?delete[] this->m_EmpArray;

?? ??? ?//更改新空間的指向
?? ??? ?this->m_EmpArray = newSpace;

?? ??? ?//更新職工人數(shù)
?? ??? ?this->m_EmpNum = newSize;

?? ??? ?cout << "成功添加" << addNum << "名新職工" << endl;

?? ??? ?this->m_File = false;

?? ??? ?//保存數(shù)據(jù)到文件中
?? ??? ?this->save();
?? ?}
?? ?else
?? ?{
?? ??? ?cout << "輸入有誤" << endl;
?? ?}
?? ?system("pause");
?? ?system("cls");
}

void Worker_Manager::save()
{
?? ?ofstream ofs;
?? ?ofs.open(TXT, ios::out);
?? ?for (int i = 0; i < this->m_EmpNum; i++)
?? ?{
?? ??? ?ofs << this->m_EmpArray[i]->m_Id<<" "
?? ??? ??? ?<< this->m_EmpArray[i]->m_Name<<" "
?? ??? ??? ?<< this->m_EmpArray[i]->m_Post<<" "
?? ??? ??? ?<< endl;
?? ?}
?? ?ofs.close();
}


int Worker_Manager::get_EmpNum()
{
?? ?ifstream ifs;
?? ?ifs.open(TXT, ios::in);
?? ?int id;
?? ?string name;
?? ?int post;

?? ?int num = 0;
?? ?while (ifs >> id && ifs >> name && ifs >> post)
?? ?{
?? ??? ?num++;
?? ?}
?? ?return num;
}

void Worker_Manager::In_Emp()
{
?? ?ifstream ifs;
?? ?ifs.open(TXT, ios::in);

?? ?int id;
?? ?string name;
?? ?int post;

?? ?int index = 0;
?? ?while (ifs>>id && ifs>>name && ifs>>post)
?? ?{
?? ??? ?Worker* worker = NULL;
?? ??? ?if (post == 1)
?? ??? ?{
?? ??? ??? ?worker = new Employee(id, name, post);//普通員工
?? ??? ?}
?? ??? ?else if (post == 2)
?? ??? ?{
?? ??? ??? ?worker = new Manager(id, name, post);//經(jīng)理
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?worker = new Boss(id, name, post);//老板
?? ??? ?}
?? ??? ?this->m_EmpArray[index] = worker;
?? ??? ?index++;
?? ?}
?? ?ifs.close();
}

void Worker_Manager::Show_Emp()
{
?? ?if (this->m_File)
?? ?{
?? ??? ?cout << "該文件不存在或?yàn)榭? << endl;
?? ?}
?? ?else
?? ?{
?? ??? ?for (int i = 0; i < this->m_EmpNum; i++)
?? ??? ?{
?? ??? ??? ?//利用多態(tài)調(diào)用
?? ??? ??? ?this->m_EmpArray[i]->ShowInfo();
?? ??? ?}
?? ?}
?? ?//清屏
?? ?system("pause");
?? ?system("cls");
}

int Worker_Manager::Ison_Emp(int id)
{
?? ?int index = -1;
?? ?for (int i = 0; i < this->m_EmpNum; i++)
?? ?{
?? ??? ?if (this->m_EmpArray[i]->m_Id == id)
?? ??? ?{
?? ??? ??? ?index = i;
?? ??? ??? ?break;
?? ??? ?}
?? ?}
?? ?return index;
}

void Worker_Manager::Del_Emp()
{
?? ?if (this->m_File)
?? ?{
?? ??? ?cout << "該文件不存在或?yàn)榭? << endl;
?? ?}
?? ?else
?? ?{
?? ??? ?cout << "請(qǐng)輸入你要?jiǎng)h除員工的編號(hào):" << endl;
?? ??? ?int id;
?? ??? ?cin >> id;
?? ??? ?int ret = this->Ison_Emp(id);
?? ??? ?//職工存在,且在index位置上
?? ??? ?if (ret != -1)
?? ??? ?{
?? ??? ??? ?for (int i = ret; i < this->m_EmpNum - 1; i++)
?? ??? ??? ?{
?? ??? ??? ??? ?//數(shù)據(jù)前移
?? ??? ??? ??? ?this->m_EmpArray[i] = this->m_EmpArray[i + 1];
?? ??? ??? ?}
?? ??? ??? ?//更新人數(shù)
?? ??? ??? ?this->m_EmpNum--;
?? ??? ??? ?cout << "刪除成功" << endl;

?? ??? ??? ?//同步到文件中
?? ??? ??? ?this->save();
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?cout << "刪除失敗" << endl;
?? ??? ?}
?? ?}
?? ?
?? ?system("pause");
?? ?system("cls");
}

void Worker_Manager::Mod_Emp()
{
?? ?if (this->m_File)
?? ?{
?? ??? ?cout << "該文件不存在或?yàn)榭? << endl;
?? ?}
?? ?else
?? ?{
?? ??? ?int id = 0;
?? ??? ?cout << "輸入你要修改的員工編號(hào):" << endl;
?? ??? ?cin >> id;
?? ??? ?int ret = this->Ison_Emp(id);
?? ??? ?if (ret != -1)
?? ??? ?{
?? ??? ??? ?delete this->m_EmpArray[ret];
?? ??? ??? ?int Newid = 0;
?? ??? ??? ?string name="";
?? ??? ??? ?int post = 0;
?? ??? ??? ?cout << "查到: " << id << "號(hào)員工,請(qǐng)輸入新的員工編號(hào): " << endl;
?? ??? ??? ?cin >> Newid;

?? ??? ??? ?cout << "查到: " << id << "號(hào)員工,請(qǐng)輸入新的員工姓名: " << endl;
?? ??? ??? ?cin >> name;

?? ??? ??? ?cout << "請(qǐng)輸入新崗位" << endl;
?? ??? ??? ?cout << "1、普通員工" << endl;
?? ??? ??? ?cout << "2、經(jīng)理" << endl;
?? ??? ??? ?cout << "3、老板" << endl;
?? ??? ??? ?cin >> post;

?? ??? ??? ?Worker* worker = NULL;
?? ??? ??? ?switch (post)
?? ??? ??? ?{
?? ??? ??? ?case 1:
?? ??? ??? ??? ?worker = new Employee(Newid, name, post);
?? ??? ??? ??? ?break;
?? ??? ??? ?case 2:
?? ??? ??? ??? ?worker = new Manager(Newid, name, post);
?? ??? ??? ??? ?break;
?? ??? ??? ?case 3:
?? ??? ??? ??? ?worker = new Boss(Newid, name, post);
?? ??? ??? ??? ?break;
?? ??? ??? ?default:
?? ??? ??? ??? ?break;
?? ??? ??? ?}
?? ??? ??? ?//將修改的數(shù)據(jù)放回原來(lái)位置
?? ??? ??? ?this->m_EmpArray[ret] = worker;
?? ??? ??? ?cout << "修改成功" << endl;

?? ??? ??? ?this->save();

?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?cout << "修改失敗" << endl;
?? ??? ?}
?? ?}

?? ?system("pause");
?? ?system("cls");
}


void Worker_Manager::Find_Emp()
{
?? ?if (this->m_File)
?? ?{
?? ??? ?cout << "該文件不存在或?yàn)榭? << endl;
?? ?}
?? ?else
?? ?{
?? ??? ?cout << "請(qǐng)選擇查找的方式" << endl;
?? ??? ?cout << "1、按編號(hào)查找" << endl;
?? ??? ?cout << "2、按姓名查找" << endl;
?? ??? ?int input = 0;
?? ??? ?cin >> input;
?? ??? ?if (input == 1)
?? ??? ?{
?? ??? ??? ?//按編號(hào)查找
?? ??? ??? ?int id = 0;
?? ??? ??? ?cout << "請(qǐng)輸入你要查找的編號(hào)為:" << endl;
?? ??? ??? ?cin >> id;
?? ??? ??? ?int ret = this->Ison_Emp(id);
?? ??? ??? ?if (ret != -1)
?? ??? ??? ?{
?? ??? ??? ??? ?cout << "查找到此人信息 ?如下:" << endl;
?? ??? ??? ??? ?this->m_EmpArray[ret]->ShowInfo();
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ?{
?? ??? ??? ??? ?cout << "查無(wú)此人" << endl;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?else if(input==2)
?? ??? ?{
?? ??? ??? ?//按姓名查找
?? ??? ??? ?string name;
?? ??? ??? ?cout << "請(qǐng)輸入你要查找人的姓名: " << endl;
?? ??? ??? ?cin >> name;

?? ??? ??? ?bool flag = false;
?? ??? ??? ?for (int i = 0; i < this->m_EmpNum; i++)
?? ??? ??? ?{
?? ??? ??? ??? ?if (this->m_EmpArray[i]->m_Name == name)
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?cout << "成功找到員工,員工編號(hào)為:" << this->m_EmpArray[i]->m_Id
?? ??? ??? ??? ??? ??? ?<< "此員工信息如下" << endl;
?? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ?this->m_EmpArray[i]->ShowInfo();
?? ??? ??? ??? ??? ?flag = true;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?if (flag == false)
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?cout << "查無(wú)此人" << endl;
?? ??? ??? ??? ?}
?? ??? ??? ?}?
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?cout << "輸入選項(xiàng)有誤" << endl;
?? ??? ?}
?? ?}
?? ?system("pause");
?? ?system("cls");
}

void Worker_Manager::Sort_Emp()
{
?? ?if (this->m_File)
?? ?{
?? ??? ?cout << "該文件不存在或?yàn)榭? << endl;
?? ??? ?system("pause");
?? ??? ?system("cls");
?? ?}
?? ?else
?? ?{
?? ??? ?cout << "請(qǐng)選擇排序方式" << endl;
?? ??? ?cout << "1、按職工號(hào)升序" << endl;
?? ??? ?cout << "2、按職工號(hào)降序" << endl;
?? ??? ?int input = 0;
?? ??? ?cin >> input;
?? ??? ?for (int i = 0; i < this->m_EmpNum; i++)
?? ??? ?{
?? ??? ??? ?int minOrmax = i;
?? ??? ??? ?for (int j = i + 1; j < this->m_EmpNum; j++)
?? ??? ??? ?{
?? ??? ??? ??? ?if (input == 1)
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?if (this->m_EmpArray[minOrmax]->m_Id > this->m_EmpArray[j]->m_Id)
?? ??? ??? ??? ??? ?{
?? ??? ??? ??? ??? ??? ?minOrmax = j;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?if (this->m_EmpArray[minOrmax]->m_Id < this->m_EmpArray[j]->m_Id)
?? ??? ??? ??? ??? ?{
?? ??? ??? ??? ??? ??? ?minOrmax = j;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?if (minOrmax != i)
?? ??? ??? ?{
?? ??? ??? ??? ?Worker* temp = this->m_EmpArray[i];
?? ??? ??? ??? ?this->m_EmpArray[i] = this->m_EmpArray[minOrmax];
?? ??? ??? ??? ?this->m_EmpArray[minOrmax] = temp;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?cout << "排序成功,排序結(jié)果為:" << endl;
?? ??? ?this->save();
?? ??? ?this->Show_Emp();
?? ?}
}

void Worker_Manager::Clean_File()
{
?? ?cout << "確定清空?" << endl;
?? ?cout << "1、確定" << endl;
?? ?cout << "2、取消" << endl;

?? ?int input = 0;
?? ?cout << "請(qǐng)輸入: " << endl;
?? ?cin >> input;

?? ?if (input == 1)
?? ?{
?? ??? ?ofstream ofs;
?? ??? ?ofs.open(TXT, ios::trunc);
?? ??? ?ofs.close();

?? ??? ?if (this->m_EmpArray != NULL)
?? ??? ?{
?? ??? ??? ?//刪除堆區(qū)所有職工對(duì)象
?? ??? ??? ?for (int i = 0; i < this->m_EmpNum; i++)
?? ??? ??? ?{
?? ??? ??? ??? ?delete this->m_EmpArray[i];
?? ??? ??? ??? ?this->m_EmpArray[i] = NULL;
?? ??? ??? ?}
?? ??? ??? ?//刪除堆區(qū)指針
?? ??? ??? ?delete[] this->m_EmpArray;
?? ??? ??? ?this->m_EmpArray = NULL;
?? ??? ??? ?this->m_File = true;
?? ??? ??? ?this->m_EmpNum = 0;
?? ??? ?}
?? ??? ?cout << "清空成功" << endl;
?? ?}
?? ?system("pause");
?? ?system("cls");
}


Worker_Manager::~Worker_Manager()
{
?? ?if (this->m_EmpArray != NULL)
?? ?{
?? ??? ?for (int i = 0; i < this->m_EmpNum; i++)
?? ??? ?{
?? ??? ??? ?if (this->m_EmpArray[i] != NULL)
?? ??? ??? ?{
?? ??? ??? ??? ?delete this->m_EmpArray[i];
?? ??? ??? ?}
?? ??? ?}
?? ??? ?delete[]this->m_EmpArray;
?? ??? ?this->m_EmpArray = NULL;
?? ?}
}

職工管理系統(tǒng).cpp文件

#include <iostream>
using namespace std;
#include <string>
#include "worker_Manager.h"
#include "Worker.h"
#include "employee.h"
#include "boss.h"
#include "manager.h"

int main()
{
?? ?//測(cè)試代碼
?? ?//Worker* worker = NULL;
?? ?//worker = new Employee(1, "張三", 1);
?? ?//worker->ShowInfo();
?? ?//delete worker;

?? ?// worker = new Manager(2, "張三", 2);
?? ?//worker->ShowInfo();
?? ?//delete worker;

?? ?//worker = new Boss(3, "張三", 3);
?? ?//worker->ShowInfo();
?? ?//delete worker;

?? ?//實(shí)例化對(duì)象
?? ?Worker_Manager wm;
?? ?
?? ?int input = 0;
?? ?do
?? ?{
?? ??? ?wm.ShowMenu();
?? ??? ?cout << "請(qǐng)輸入你的選擇:" << endl;
?? ??? ?cin >> input;
?? ??? ?switch (input)
?? ??? ?{
?? ??? ?case 0:
?? ??? ??? ?cout << "歡迎下次使用!" << endl;
?? ??? ??? ?break;
?? ??? ?case 1: ?//增加職工
?? ??? ??? ?wm.Add_Emp();
?? ??? ??? ?break;
?? ??? ?case 2: ?//顯示職工
?? ??? ??? ?wm.Show_Emp();
?? ??? ??? ?break;
?? ??? ?case 3: ?//刪除職工
?? ??? ??? ?wm.Del_Emp();
?? ??? ??? ?break;
?? ??? ?case 4: ?//修改職工
?? ??? ??? ?wm.Mod_Emp();
?? ??? ??? ?break;
?? ??? ?case 5: ?//查找職工
?? ??? ??? ?wm.Find_Emp();
?? ??? ??? ?break;
?? ??? ?case 6: ?//排序職工
?? ??? ??? ?wm.Sort_Emp();
?? ??? ??? ?break;
?? ??? ?case 7: ?//清空文檔
?? ??? ??? ? wm.Clean_File();
?? ??? ??? ?break;
?? ??? ?default:
?? ??? ??? ?system("cls"); //清屏
?? ??? ??? ?break;
?? ??? ?}

?? ?} while (input);

?? ?system("pause");

?? ?return 0;
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C語(yǔ)言安全編碼之?dāng)?shù)組索引位的合法范圍

    C語(yǔ)言安全編碼之?dāng)?shù)組索引位的合法范圍

    這篇文章主要介紹了C語(yǔ)言安全編碼的數(shù)組索引位合法范圍剖析,對(duì)于編碼安全非常重要!需要的朋友可以參考下
    2014-07-07
  • C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)易的掃雷小游戲

    C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)易的掃雷小游戲

    這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)易的掃雷小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • C++ 中的Swap函數(shù)寫法匯總

    C++ 中的Swap函數(shù)寫法匯總

    這篇文章主要介紹了C++ 中的Swap函數(shù)寫法匯總,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • C++ opencv圖像處理實(shí)現(xiàn)圖片幾何變換示例

    C++ opencv圖像處理實(shí)現(xiàn)圖片幾何變換示例

    這篇文章主要為大家介紹了C++ opencv圖像處理實(shí)現(xiàn)圖片幾何變換示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • C/C++中時(shí)間庫(kù)函數(shù)的使用詳解

    C/C++中時(shí)間庫(kù)函數(shù)的使用詳解

    這篇文章主要為大家詳細(xì)介紹了C/C++中的時(shí)間相關(guān)知識(shí)總結(jié),例如時(shí)間庫(kù)函數(shù)的使用以及獲取本地時(shí)間的不同方法,文中的示例代碼講解詳細(xì),需要的可以參考一下
    2022-11-11
  • C++之IO類,文件輸入輸出,string流練習(xí)題

    C++之IO類,文件輸入輸出,string流練習(xí)題

    這篇文章主要介紹了C++實(shí)現(xiàn)IO類的幾道數(shù)組練習(xí)題,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • VScode platformio使用的詳細(xì)步驟

    VScode platformio使用的詳細(xì)步驟

    使用VSCode作為編輯器,同時(shí)借助PlatformIO插件,可以幫助開發(fā)者更加高效地進(jìn)行嵌入式開發(fā),本文主要介紹了VScode platformio使用的詳細(xì)步驟,感興趣的可以了解一下
    2023-10-10
  • Qt開發(fā)實(shí)現(xiàn)跨窗口信號(hào)槽通信

    Qt開發(fā)實(shí)現(xiàn)跨窗口信號(hào)槽通信

    這篇文章主要為大家詳細(xì)介紹了Qt開發(fā)實(shí)現(xiàn)跨窗口信號(hào)槽通信,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • C語(yǔ)言超全面講解函數(shù)的使用方法下

    C語(yǔ)言超全面講解函數(shù)的使用方法下

    函數(shù)是一組一起執(zhí)行一個(gè)任務(wù)的語(yǔ)句。每個(gè)?C?程序都至少有一個(gè)函數(shù),即主函數(shù)?main()?,所有簡(jiǎn)單的程序都可以定義其他額外的函數(shù),由于篇幅過大,分為兩篇講解,下面開始下篇
    2022-04-04
  • c語(yǔ)言實(shí)現(xiàn)基數(shù)排序解析及代碼示例

    c語(yǔ)言實(shí)現(xiàn)基數(shù)排序解析及代碼示例

    這篇文章主要介紹了c語(yǔ)言實(shí)現(xiàn)基數(shù)排序解析及代碼示例,具有一定借鑒價(jià)值,需要的朋友可以參考下。
    2017-12-12

最新評(píng)論