开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 2986|回复: 11
收起左侧

[易语言纯源码] 闲来无事做了个职工管理系统,纯c++源码

[复制链接]
发表于 2022-6-7 16:41:11 | 显示全部楼层 |阅读模式   江西省景德镇市
分享源码
界面截图: -
是否带模块: 纯源码
备注说明: -
  
#include" ;work_person.h"
work::work ()
{
ifstream ifs;
ifs.open (CONS, ios::in);
if (!ifs.is_open ())
{
cout << "文件为空" << endl;
this->m_empnum = 0;
this->m_emparray = NULL;
this->fileisempty = true;
ifs.close ();
return;
}
char ch;
ifs >> ch;
if (ifs.eof ())
{
cout << "文件为空" << endl;
this->m_empnum = 0;
this->m_emparray = NULL;
this->fileisempty = true;
ifs.close ();
return;
}
int num = this->get_empnum ();
cout << "职工的人数为" <<num<< endl;
this->m_empnum = num;
this->m_emparray = new worker * [this->m_empnum];
this->init_emp ();
}
void work::show_work ()
{
cout << "************************************" << endl;
cout << "********   0.退出管理系统   ********" <<endl;
cout << "********   1.增加职工信息   ********" << endl;
cout << "********   2.显示职工信息   ********" << endl;
cout << "********   3.删除离职职工   ********" << endl;
cout << "********   4.修改职工信息   ********" << endl;
cout << "********   5.查找职工信息   ********" << endl;
cout << "********   6.按照编号排序   ********" << endl;
cout << "********   7.清空所有文档   ********" << endl;
}
void work::exit_work ()
{
cout << "欢迎下次使用" << endl;
exit (0);
}
void work::add_emp ()
{
cout << "请添加职工数量" << endl;
int addnum = 0;
cin >> addnum;
if (addnum>0)
{
int newsize = this->m_empnum + addnum;
worker ** newspce = new worker * [newsize];
if (this->m_emparray!=NULL)
{
for (int i = 0; i < this->m_empnum; i++)
{
newspce[i] = this->m_emparray[i];
}
}
for (int i = 0; i < addnum; i++)
{
int id;
string name;
int did;
cout << "请输入第" << i+1 << "个职工编号" << endl;
cin >> id;
cout << "请输入第" << i + 1 << "个职工姓名" << endl;
cin >> name;
cout << "请输入第" << i + 1 << "个职工岗位" << endl;
cout << "1、普通员工" << endl;
cout << "2、经理" << endl;
cout << "3、老板" << endl;
cin >> did;
worker* wor = NULL;
switch (did)
{
case 1:
wor = new worker_son1 (id, name, did);
break;
case 2:
wor = new worker_son2 (id, name, did);
break;
case 3:
wor = new worker_son2 (id, name, did);
break;
default:
break;
}
newspce[this->m_empnum + i] = wor;
}
delete[] this->m_emparray;
this->m_emparray = newspce;
this->m_empnum = newsize;
this->fileisempty = false;
cout << "成功添加" << addnum << "名职工" << endl;
work::save ();
}
else
{
cout << "输入有误" << endl;
}
system ("pause");
system ("cls");
}
void work::save ()
{
ofstream ofs;
ofs.open (CONS, 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_deptid << endl;
}
ofs.close ();
}
int work::get_empnum ()
{
ifstream ifs;
ifs.open (CONS,ios::in);
int id;
string name;
int did;
int num = 0;
while (ifs >> id && ifs >> name && ifs >> did)
{
num++;
}
ifs.close ();
return num;
}
void work::init_emp ()
{
ifstream ifs;
ifs.open (CONS, ios::in);
int id;
string name;
int did;
int index =0;
while (ifs >> id && ifs >> name && ifs >> did)
{
worker* wor = NULL;
if (did==1)
{
wor = new worker_son1 (id, name, did);
}
else if (did == 2)
{
wor = new worker_son2 (id, name, did);
}
else
{
wor = new worker_son3 (id, name, did);
}
this->m_emparray[index] = wor;
index++;
}
ifs.close ();
}
void work::show_emp ()
{
if (this->fileisempty)
{
cout << "还未录入职工信息" << endl;
}
else
{
for (int i = 0; i < this->m_empnum; i++)
{
this->m_emparray[i]->showinfo ();
}
}
system ("pause");
system ("cls");
}
void work::del_emp ()
{
if (this->fileisempty)
{
cout << "文件不存在或记录为空" << endl;
}
else
{
cout << "请输入要删除的职工编号" << endl;
int id;
cin >> id;
int index = isExist (id);
if (index !=-1)
{
for (int i = index; i < this->m_empnum -1; i++)
{
m_emparray[i] = m_emparray[i + 1];
}
this->m_empnum--;
this->save ();
cout << "删除成功" << endl;
}
else
{
cout << "删除失败,未找到该职工" << endl;
}
}
system ("pause");
system ("cls");
}
int work::isExist (int id)
{
int index = -1;
for (int i = 0; i < this->m_empnum; i++)
{
if (m_emparray[i]->m_id==id)
{
index = i;
break;
}
}
return index;
}
void work::mod_emp ()
{
if (this->fileisempty)
{
cout << "文件不存在或记录为空" << endl;
}
else
{
cout << "请输入要修改的职工编号" << endl;
int id;
cin >> id;
int ret = this->isExist (id);
if (ret != -1)
{
delete this->m_emparray[ret];
int new_id;
string new_name;
int new_did;
cout <<"查到:"<< id << "号职工,请输入新职工号" << endl;
cin >> new_id;
cout << "职工姓名" << endl;
cin >> new_name;
cout << "职工岗位" << endl;
cin >> new_did;
worker* wor = NULL;
switch (new_did)
{
case 1:
wor = new worker_son1 (new_id, new_name, new_did);
break;
case 2:
wor = new worker_son2 (new_id, new_name, new_did);
break;
case 3:
wor = new worker_son3 (new_id, new_name, new_did);
break;
default:
break;
}
m_emparray[ret] = wor;
cout << "修改成功" << endl;
this->save ();
}
else
{
cout << "修改失败,查无此人" << endl;
}
}
system ("pause");
system ("cls");
}
void work::find_emp ()
{
if (this->fileisempty)
{
cout << "文件不存在或记录为空" << endl;
}
else
{
cout << "1、按编号查找" << endl;
cout << "2、按姓名查找" << endl;
int id;
cin >> id;
if (id==1)
{
cout << "请输入要查找的职工编号" << endl;
int m_id;
cin >> m_id;
int ret = this->isExist (m_id);
if (ret != -1)
{
m_emparray[ret]->showinfo ();
}
else
{
cout << "查无此人" << endl;
}
}
else if (id == 2)
{
cout << "请输入要查找的职工姓名" << endl;
string name;
cin >> name;
bool flag = false;
for (int i = 0; i < this->m_empnum; i++)
{
if (m_emparray[i]->m_name==name)
{
cout << "您要找到的职工编号为:" << m_emparray[i]->m_id << "号信息如下:" << endl;
m_emparray[i]->showinfo ();
flag = true;
}
}
if (flag==false)
{
cout << "查无此人" << endl;
}
}
else
{
cout << "输入有误" << endl;
}
}
system ("pause");
system ("cls");
}
void work::sort_emp ()
{
if (this->fileisempty)
{
cout << "文件不存在或记录为空" << endl;
}
else
{
cout << "请选择排序方式" << endl;
cout << "1、升序" << endl;
cout << "2、降序" << endl;
int select;
cin >> select;
for (int i = 0; i < this->m_empnum; i++)
{
int minOrMax = i;
for (int j = i + 1; j < this->m_empnum; j++)
{
if (select == 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 (i != minOrMax)
{
worker* temp = this->m_emparray[i];
this->m_emparray[i] = this->m_emparray[minOrMax];
this->m_emparray[minOrMax] = temp;
}
}
}
cout << "排序成功,排序结果如下:" << endl;
this->save ();
this->show_emp ();
}
void work::clean_File ()
{
cout << "确定要删除文件吗?" << endl;
cout << "1、确定" << endl;
cout << "2、返回" << endl;
int select;
cin >> select;
if (select==1)
{
ofstream ofs;
ofs.open (CONS, ios::trunc);
ofs.close ();
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];
this->m_emparray[i] = NULL;
}
}
delete[]this->m_emparray;
this->m_emparray = NULL;
this->m_empnum = 0;
this->fileisempty = true;
}
cout << "清空成功" << endl;
}
else
{
cout << "返回上层目录" << endl;
}
system ("pause");
system ("cls");
}
work::~work ()
{
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];
this->m_emparray[i] = NULL;
}
}
delete[] this->m_emparray;
this->m_emparray = NULL;
}
}
worker_son1::worker_son1 (int id, string name, int did)
{
this->m_id = id;
this->m_name = name;
this->m_deptid = did;
}
void worker_son1::showinfo ()
{
cout << "职工编号:" << this->m_id <<"   "
<< "职工姓名:" << this->m_name << "   "
<< "职工岗位:" << this->getdeptname () << "   "
<< "岗位职责:完成经理交付的任务" << endl;
}
string worker_son1::getdeptname ()
{
return"员工";
}
worker_son2::worker_son2 (int id, string name, int did)
{
this->m_id = id;
this->m_name = name;
this->m_deptid = did;
}
void worker_son2::showinfo ()
{
cout << "职工编号:" << this->m_id << "   "
<< "职工姓名:" << this->m_name << "   "
<< "职工岗位:" << this->getdeptname () << "   "
<< "岗位职责:完成老板交给的任务,并下发任务给员工" << endl;
}
string worker_son2::getdeptname ()
{
return"经理";
}
worker_son3::worker_son3 (int id, string name, int did)
{
this->m_id = id;
this->m_name = name;
this->m_deptid = did;
}
void worker_son3::showinfo ()
{
cout << "职工编号:" << this->m_id << "   "
<< "职工姓名:" << this->m_name << "   "
<< "职工岗位:" << this->getdeptname () << "   "
<< "岗位职责:管理公司所有事物" << endl;
}
string worker_son3::getdeptname ()
{
return"老板";
}
</endl;
</num<

点评

你这个就是最简单的调用而已,应该看的是b站上面的视频吧,加油!努力吧!   安徽省合肥市  发表于 2022-6-7 17:29

评分

参与人数 1好评 +1 收起 理由
reveriexue + 1 支持开源~!感谢分享

查看全部评分


发表于 2022-7-31 15:30:35 | 显示全部楼层   上海市上海市
来学习了
回复 支持 反对

使用道具 举报

发表于 2022-7-30 21:45:51 | 显示全部楼层   广东省广州市
666支持开源精神
回复 支持 反对

使用道具 举报

发表于 2022-6-23 20:04:20 | 显示全部楼层   贵州省铜仁市


开源精神必须支持~
回复 支持 反对

使用道具 举报

结帖率:100% (8/8)

签到天数: 2 天

发表于 2022-6-10 20:32:10 | 显示全部楼层   山东省威海市
支持开源~!感谢分享
回复 支持 反对

使用道具 举报

发表于 2022-6-10 10:02:27 | 显示全部楼层   吉林省长春市
感谢分享,很给力!~
回复 支持 反对

使用道具 举报

结帖率:93% (14/15)

签到天数: 2 天

发表于 2022-6-8 10:30:19 | 显示全部楼层   广东省深圳市
看看是什么
回复 支持 反对

使用道具 举报

发表于 2022-6-8 08:48:15 | 显示全部楼层   河南省开封市
1111111111111111111111111111111111111
回复 支持 反对

使用道具 举报

签到天数: 20 天

发表于 2022-6-8 05:41:01 | 显示全部楼层   四川省成都市
感谢分享,很给力!~
回复 支持 反对

使用道具 举报

签到天数: 17 天

发表于 2022-6-7 22:55:46 | 显示全部楼层   山东省济南市
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 793400750,邮箱:wp@125.la
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表