IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> 职工管理系统C++ -> 正文阅读

[C++知识库]职工管理系统C++

boss.h

#pragma once
#include<iostream>
using namespace std;
#include<string>
class Worker
{
public:
	virtual void showinfo() = 0;
	virtual string depetname() = 0;
	int m_id;
	string m_name;
	int m_depetid;
};

employee.h

#pragma once
#include"Worker.h"
using namespace std;
class Employee : public Worker
{
public:
	Employee(int id, string name, int did);
	virtual void showinfo();
	virtual string depetname();
};

manager.h

#pragma once
#include"Worker.h"
using namespace std;
#include<string>
class Manager : public Worker
{
public:
	Manager(int id,string name ,int did);
	virtual void showinfo();
	virtual string depetname();
};

Worker.h

#pragma once
#include<iostream>
using namespace std;
#include<string>
class Worker
{
public:
	virtual void showinfo() = 0;
	virtual string depetname() = 0;
	int m_id;
	string m_name;
	int m_depetid;
};

workerManager.h

#pragma once
#include<iostream>
using namespace std;
#include"Worker.h"
#include"employee.h"
#include"manager.h"
#include"boss.h"
#include<fstream>
#define FILENAME "EmpFile"
class WorkerManager
{
public:
	WorkerManager();
	void show_Menu();
	int m_EmpNum;
	Worker** m_EmpArray;
	void AddEmpNum();
	void SaveEmpFile();
	bool m_FileIsEmpty;
	int get_EmpNum();
	void init_Emp();
	void show_Emp();
	int isExist1(int id);
	int isExist2(string name);
	int isExist3(int did);
	void edit_Emp();
	void delet_Emp();
	void find_Emp();
	void sort_Emp();
	~WorkerManager();
};

boss.cpp

#include"boss.h"
Boss::Boss(int id, string name, int did)
{
	this->m_id = id;
	this->m_name = name;
	this->m_depetid = did;
}
void Boss::showinfo()
{
	cout << "boss id is:" << this->m_id
		<< "\tboss name is:" << this->m_name
		<< "\tboss post is:" << this->depetname() << endl;
	cout << "Command the entire company  " << endl;
	cout << "_____________________________________________" << endl;
}
string Boss::depetname()
{
	return string("boos");
}

employee.cpp

#include"employee.h"
#include"Worker.h"
Employee::Employee(int id, string name, int did)
{
	this->m_id = id;
	this->m_name = name;
	this->m_depetid = did;
}
void Employee::showinfo()
{
	cout << "employee id is:" << this->m_id
		<< "\temployee name is:" << this->m_name
		<< "\temployee post is:" << this->depetname() << endl;
		cout<< "Complete the tasks assigned by the manager " << endl;
		cout << "_____________________________________________" << endl;
}
string Employee::depetname()
{
	return string("Ordinary employee");
}

manager.cpp

#include"manager.h"
#include"manager.h"
#include<string>
Manager::Manager(int id, string name, int did)
{
	this->m_id = id;
	this->m_name = name;
	this->m_depetid = did;
}
 void Manager::showinfo()
{
	 cout << "manager id is:" << this->m_id
		 << "\tmanager name is:" << this->m_name
		 << "\tmanager post is:" << this->depetname() << endl;
	 cout << "Complete the tasks assigned by the boss and deploy the work of the employees  " << endl;
	 cout << "_____________________________________________" << endl;
}
 string Manager:: depetname()
{
	 return string("manager");
}

WorkerManager.cpp

#include"workerManager.h"
WorkerManager::WorkerManager()
{
	ifstream ifs;
	ifs.open(FILENAME, ios::in);
	if (!ifs.is_open())
	{
		cout << "file is does not exist " << endl;
		cout << "-------------------------------" << endl;
		this->m_EmpNum = 0;
		this->m_FileIsEmpty = true;
		this->m_EmpArray = NULL;
		ifs.close();
		return;
	}
	char ch;
	ifs >> ch;
	if (ifs.eof())
	{
		cout << "file is empty" << endl;
		cout << "--------------------" << endl;
		this->m_EmpNum = 0;
		this->m_FileIsEmpty = true;
		this->m_EmpArray = NULL;
		ifs.close();
		return;
	}
	int num = this->get_EmpNum();
	cout << "employ's number is: " <<num<< endl;
	this->m_EmpNum = num;
	this->m_EmpArray = new Worker * [this->m_EmpNum];
	this->init_Emp();
	for (int i = 0; i < this->m_EmpNum; i++)
	{
		cout << "employee number is : " << this->m_EmpArray[i]->m_id
			<< "    employee name is:" << this->m_EmpArray[i]->m_name
			<< "    empployee post is:" << this->m_EmpArray[i]->m_depetid << endl;
	}
}
void WorkerManager::show_Menu()
{
	cout << "welcome to Staff Management System " << endl;
	cout << "1:Increase employee information***" << endl;
	cout << "2:Show employee information*******" << endl;
	cout << "3:delet employee informantion******" << endl;
	cout << "4:edit employee information******" << endl;
	cout << "5:find employee information*******" << endl;
	cout << "6:Sort by employee number*********" << endl;
	cout << "7:clear eventhing's file**********" << endl;
	cout << "0:eixt the system*****************" << endl;
}
void WorkerManager::SaveEmpFile()
{
	ofstream ofs;
	ofs.open(FILENAME, 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_depetid << endl;
	}
	ofs.close();
}
void WorkerManager::init_Emp()
{
	ifstream ifs;
	ifs.open(FILENAME, ios::in);
	int id;
	string name;
	int did;
	int index = 0;
	while (ifs >> id && ifs >> name && ifs >> did)
	{
		Worker* worker = NULL;
		switch (did)
		{
		case 1:
			worker = new Employee(id, name, did);
			break;
		case 2:
			worker = new Manager(id, name, did);
			break;
		case 3:
			worker = new Boss(id, name, did);
			break;
		}	
		this->m_EmpArray[index] = worker;
		index++;
	}
	ifs.close();
}
void WorkerManager::AddEmpNum()
{
	cout << "please you need to add to employee's numbers" << endl;
	int AddNum = 0;
	cin >> AddNum;
	if (AddNum > 0)
	{
		int NewSize = this->m_EmpNum + AddNum;
		Worker ** NewSpace = new Worker* [NewSize];
		if (this->m_EmpNum != NULL)
		{
			for (int i = 0; i < this->m_EmpNum; i++)
			{
				NewSpace[i] = this->m_EmpArray[i];
			}
		}
		for (int i = 0; i < AddNum; i++)
		{
			int id;
			cout << "Please enter the number of the "<< i + 1<< "  employee "<< endl;
			cin >> id;
			string name;
			cout << "Please enter the name of the " << i + 1 << "employee " << endl;
			cin >> name;
			int deptid;
			cout << "1:employee" << endl;
			cout << "2:manager" << endl;
			cout << "3:boss" << endl;
			A : cin >> deptid;
			Worker* worker = NULL;
			switch (deptid)
			{
			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 << "Without this option ,please input again" << endl;
				goto  A;
			}
			NewSpace[this->m_EmpNum + i] = worker;
		}
		delete[] this->m_EmpArray;
		this->m_EmpArray = NewSpace;	
		this->m_EmpNum = NewSize;
		this->m_FileIsEmpty = false;
		cout << "add to employ is sucess" << endl;
		this->SaveEmpFile();
	}
	else
	{
		cout << "you input is error" << endl;
	}
	system("pause");
	system("cls");
}
int WorkerManager::get_EmpNum()
{
	ifstream ifs;
	ifs.open(FILENAME, ios::in);
	int id;
	string name;
	int did;
	int num = 0;
	while (ifs >> id && ifs >> name && ifs >> did)
	{
		num++;
	}
	ifs.close();
	return num;
}
void WorkerManager::show_Emp()
{
	if (this->m_FileIsEmpty)
	{
		cout << "file does not exist or file is empty" << endl;
	}
	else
	{
		for (int i = 0; i < this->m_EmpNum; i++)
		{
			this->m_EmpArray[i]->showinfo();
		}
	}
	system("pause");
	system("cls");
}
int WorkerManager::isExist1(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;
}
int WorkerManager::isExist2(string name)
{
	int index = -1;
	for (int i = 0; i < this->m_EmpNum; i++)
	{
		if (this->m_EmpArray[i]->m_name == name)
		{
			index = i;
			break;
		}
	}
	return index;
}
int WorkerManager::isExist3(int did)
{
	int index = -1;
	for (int i = 0; i < this->m_EmpNum; i++)
	{
		if (this->m_EmpArray[i]->m_depetid == did)
		{
			index = i;
			break;
		}
	}
	return index;
}
void WorkerManager::delet_Emp()
{
	if (this->m_FileIsEmpty)
	{
		cout << "file does not exist or file is empty" << endl;
    }
	else
	{
		int ret = 0;
		A:cout << "1:Delete according to the employee number " << endl;
		cout << "2:Delete according to the employee's name " << endl;
		int choice;
		cin >> choice;
		switch (choice)
		{
		case 1:
		{
			int id;
			cout << "please input you need to delet's id" << endl;
			cin >> id;
			ret = this->isExist1(id);
			if (ret != -1)
			{
				for (int i = ret; i < this->m_EmpNum - 1; i++)
				{
					this->m_EmpArray[i] = this->m_EmpArray[i + 1];
				}
				this->m_EmpNum--;
				this->SaveEmpFile();
				cout << "delet sucess" << endl;
				break;
			}
			else
			{
				cout << "No employee to be deleted was found " << endl;
			}
		}
		case 2:
		{
			string name;
			cout << "please input you need to delet's name" << endl;
			cin >> name;
			ret = this->isExist2(name);
			if (ret != -1)
			{
				for (int i = ret; i < this->m_EmpNum - 1; i++)
				{
					this->m_EmpArray[i] = this->m_EmpArray[i + 1];
				}
				this->m_EmpNum--;
				this->SaveEmpFile();
				cout << "delet sucess" << endl;
				break;
			}
			else
			{
				cout << "No employee to be deleted was found " << endl;
			}
		}
		default:
			cout << "input is error,please input again" << endl;
			goto A;
		}
	}
	system("pause");
	system("cls");
}
void WorkerManager::edit_Emp()
{
	if (this->m_FileIsEmpty)
	{
		cout << "file does not exist or file is empty" << endl;
	}
	else
	{
		cout << "what do you need to edit" << endl;
		A:cout << "1.id" << endl;
		cout << "2.name" << endl;
		cout << "3.did" << endl;
		int choice;
		cin >> choice;
		switch (choice)
		{
		case 1:
		{
			int id;
			cout << "please input you need to edit id" << endl;
			cin >> id;
			int ret = this->isExist1(id);
			if (ret != -1)
			{
				cout << "Find this person" << endl;
				this->m_EmpArray[ret]->showinfo();
				cout << "please input new_id" << endl;
				int new_id;
				cin >> new_id;
				this->m_EmpArray[ret]->m_id = new_id;
				this->SaveEmpFile();
				cout << "edit is sucess" << endl;
				break;
			}
			else
			{
				cout << "does not exist id" << endl;
			}
		}
		case 2:
		{
			string name;
			cout << "please input you need to edit name" << endl;
			cin >> name;
			int ret = this->isExist2(name);
			if (ret != -1)
			{
				cout << "Find this person" << endl;
				this->m_EmpArray[ret]->showinfo();
				cout << "please input new_name" << endl;
				string  new_name;
				cin >> new_name;
				this->m_EmpArray[ret]->m_name = new_name;
				this->SaveEmpFile();
				cout << "edit is sucess" << endl;
				break;
			}
			else
			{
				cout << "does not exist id" << endl;
			}
		}
		case 3:
		{
			int did;
			cout << "please input you need to edit did" << endl;
			cin >> did;
			int ret = this->isExist1(did);
			if (ret != -1)
			{
				cout << "Find this person" << endl;
				this->m_EmpArray[ret]->showinfo();
				cout << "please input new_did" << endl;
				int new_did;
				cin >> new_did;
				this->m_EmpArray[ret]->m_id = new_did;
				this->SaveEmpFile();
				cout << "edit is sucess" << endl;
				break;
			}
			else
			{
				cout << "does not exist id" << endl;
			}
		}
		default:
			cout << "input is error,please input again" << endl;
			goto A;
		}
	}
	system("pause");
	system("cls");
}
void WorkerManager::find_Emp()
{
	if (this->m_FileIsEmpty)
	{
		cout << "file does not exist or file is empty" << endl;
	}
	cout << "what do you find information is 1 ,2 or 3" << endl;
	A:cout << "1.find id" << endl;
	cout << "2.find name" << endl;
	cout << "3.find did" << endl;
	int choice;
	cin >> choice;
	switch (choice)
	{
	case 1:
	{
		cout << "please input id" << endl;
		int id;
		cin >> id;
		int ret = isExist1(id);
		if (ret != -1)
		{
			cout << "find the employee" << endl;
			this->m_EmpArray[ret]->showinfo();
			break;
		}
		else
		{
			cout << "no person" << endl;
		}
	}
	case 2:
	{
		cout << "please input name" << endl;
		string name;
		cin >> name;
		int ret = isExist2(name);
		if (ret != -1)
		{
			cout << "find the employee" << endl;
			this->m_EmpArray[ret]->showinfo();
			break;
		}
		else
		{
			cout << "no person" << endl;
		}
	}
	case 3:
	{
		cout << "please input did" << endl;
		int did;
		cin >> did;
		int ret = isExist1(did);
		if (ret != -1)
		{
			cout << "find the employee" << endl;
			this->m_EmpArray[ret]->showinfo();
			break;
		}
		else
		{
			cout << "no person" << endl;
		}
	}
	default:
		cout << "input is error,please input again" << endl;
		goto A;
	}
}
void WorkerManager::sort_Emp()
{
	if (this->m_FileIsEmpty)
	{
		cout << "file does not exist or file is empty" << endl;
	}
	else
	{
		int choice;
	A:cout << "Please select ascending↑ or descending↓ order " << endl;
		cout << "1.ascending" << endl;
		cout << "2:descending" << endl;
		cin >> choice;
		switch (choice)
		{
		case 1:
		{
			for (int i = 0; i < this->m_EmpNum; i++)
			{
				for (int j = i + 1; j < this->m_EmpNum; j++)
				{
					if (this->m_EmpArray[i]->m_id < this->m_EmpArray[j]->m_id)
					{
						Worker* worker = m_EmpArray[i];
						m_EmpArray[i] = m_EmpArray[j];
						m_EmpArray[j] = worker;
					}
				}
			}
			this->show_Emp();
			break;
		}
		case 2:
		{
			for (int i = 0; i < this->m_EmpNum; i++)
			{
				for (int j = i + 1; j < this->m_EmpNum; j++)
				{
					if (this->m_EmpArray[i]->m_id > this->m_EmpArray[j]->m_id)
					{
						Worker* worker = m_EmpArray[i];
						m_EmpArray[i] = m_EmpArray[j];
						m_EmpArray[j] = worker;
					}
				}
			}
			this->show_Emp();
			break;
		}
		default:
			cout << "input is error,please input again" << endl;
			goto A;
		}
	}
	system("pause");
	system("cls");
}
WorkerManager::~WorkerManager()
{
	if (this->m_EmpArray != NULL)
	{
		delete[]this->m_EmpArray;
		this->m_EmpArray = NULL;
	}
}

职工管理系统.cpp

#include<iostream>
#include"workerManager.h"
#include"Worker.h"
#include"employee.h"
#include"manager.h"
#include"boss.h"
using namespace std;
int main()
{
	/*Worker* worker;
	worker = new Boss(3, "wangwu", 3);
	worker->showinfo();*/
	/*worker = new Employee(1, "zhangsna", 1);
	worker->showinfo();*/
	/*worker = new Manager(2, "lisi", 2);
	worker->showinfo();*/
	WorkerManager wv;
	
	while (true)
	{
		int choice;
	A: cout << "please input your choice" << endl;
		wv.show_Menu();
		cin >> choice;
		switch (choice)
		{
		case 1:
			wv.AddEmpNum();
			break;
		case 2:
			wv.show_Emp();
			break;
		case 3:
			wv.delet_Emp();
			break;
		case 4:
			wv.edit_Emp();
			break;
		case 5:
			wv.find_Emp();
			break;
		case 6:
			wv.sort_Emp();
			break;
		case 7:
			break;
		case 0:
			cout << "Welcome to use next time  " << endl;
			exit(0);
		default:
			cout << "you choice is error,please again inputing your choice" << endl;
			system("pasue");
			system("cls");
			goto A;
		}
	}
}

  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2021-08-20 14:54:29  更:2021-08-20 14:56:44 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年12日历 -2024/12/27 5:00:14-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码
数据统计