最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于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)可以用來管理公司內(nèi)所有員工的信息

利用C++來實(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 << "******* 歡迎來到職工管理系統(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ù)=原來的人數(shù)+新增加的人數(shù)

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

?? ??? ?//將原來的數(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ù)放回原來位置
?? ??? ??? ?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 << "查無此人" << 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 << "查無此人" << 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()
{
?? ?//測試代碼
?? ?//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;
}

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

相關(guān)文章

  • C++?Boost?MultiArray簡化使用多維數(shù)組庫

    C++?Boost?MultiArray簡化使用多維數(shù)組庫

    Boost是為C++語言標(biāo)準(zhǔn)庫提供擴(kuò)展的一些C++程序庫的總稱。Boost庫是一個(gè)可移植、提供源代碼的C++庫,作為標(biāo)準(zhǔn)庫的后備,是C++標(biāo)準(zhǔn)化進(jìn)程的開發(fā)引擎之一,是為C++語言標(biāo)準(zhǔn)庫提供擴(kuò)展的一些C++程序庫的總稱
    2022-11-11
  • 編輯器寫C語言輸出中文亂碼問題及解決

    編輯器寫C語言輸出中文亂碼問題及解決

    這篇文章主要介紹了編輯器寫C語言輸出中文亂碼問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Qt中QPushButton組件的使用詳解

    Qt中QPushButton組件的使用詳解

    QPushButton是Qt庫中的一個(gè)重要組件,本文主要介紹了Qt中QPushButton組件的使用詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-07-07
  • c++圖像處理:24位真彩圖顏色變換實(shí)例

    c++圖像處理:24位真彩圖顏色變換實(shí)例

    下面小編就為大家?guī)硪黄猚++圖像處理:24位真彩圖顏色變換實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-01-01
  • VC中控制臺(tái)程序創(chuàng)建窗口的實(shí)例方法

    VC中控制臺(tái)程序創(chuàng)建窗口的實(shí)例方法

    在本篇文章里小編給大家分享的是關(guān)于VC中控制臺(tái)程序創(chuàng)建窗口的實(shí)例方法及相關(guān)代碼內(nèi)容,有需要的朋友學(xué)習(xí)下吧。
    2021-12-12
  • 如何寫好C main函數(shù)的幾個(gè)注意事項(xiàng)

    如何寫好C main函數(shù)的幾個(gè)注意事項(xiàng)

    這篇文章主要介紹了如何寫好C main函數(shù)的幾個(gè)注意事項(xiàng),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • c++只保留float型的小數(shù)點(diǎn)后兩位問題

    c++只保留float型的小數(shù)點(diǎn)后兩位問題

    這篇文章主要介紹了c++只保留float型的小數(shù)點(diǎn)后兩位問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • 從C語言過渡到C++之const

    從C語言過渡到C++之const

    C++中最早引入const是為了替代#define,后來又衍生出了其它用法。這一篇中我們來詳細(xì)介紹const的各種常見用法。希望對(duì)大家學(xué)習(xí)C++有所幫助。
    2017-07-07
  • 手把手教你實(shí)現(xiàn)一個(gè)C++單鏈表

    手把手教你實(shí)現(xiàn)一個(gè)C++單鏈表

    鏈表是一種數(shù)據(jù)結(jié)構(gòu),用于數(shù)據(jù)的存儲(chǔ)。這篇文章主要為大家介紹了如何實(shí)現(xiàn)一個(gè)C++單鏈表,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以嘗試一下
    2022-11-11
  • Qt使用事件與定時(shí)器實(shí)現(xiàn)字幕滾動(dòng)效果

    Qt使用事件與定時(shí)器實(shí)現(xiàn)字幕滾動(dòng)效果

    我們經(jīng)常能夠在外面看到那種滾動(dòng)字幕,那么本文就拿Qt來做一個(gè)吧,本文將使用事件與定時(shí)器實(shí)現(xiàn)字幕滾動(dòng)的效果,感興趣的小伙伴可以了解一下
    2023-06-06

最新評(píng)論

宁波市| 驻马店市| 乌兰浩特市| 禄劝| 卓资县| 来宾市| 云安县| 文昌市| 中山市| 塔城市| 买车| 乌恰县| 巢湖市| 杭锦旗| 克拉玛依市| 万安县| 思茅市| 漳浦县| 常德市| 通道| 合江县| 拜泉县| 萍乡市| 岚皋县| 手游| 鹿邑县| 中江县| 措美县| 都安| 阳城县| 海宁市| 阿巴嘎旗| 太康县| 邵阳县| 潢川县| 泌阳县| 望江县| 临猗县| 太谷县| 天全县| 济阳县|