2、职工信息管理系统
代码在文末自取!!!
一、课程设计题目:C语言课程设计
二、课程设计任务:
学生可从以下项目中任选一个为题,单独完成程序的编写工作,并经调试后能正常运行方可参加结题答辩。
1、学生通讯录管理系统设计
设计一个学生通信录,学生通迅录数据信息构成内容可自行设计(如:学号、姓名、电话号码、所在班级、寝室地址等),通信录数据类型定义为结构体类型。
主要实现功能包括:
(1)创建学生通讯录
(2)修改学生通讯录
(3)增删学生通讯录
2、职工信息管理系统
职工数据由职工编号、姓名、部门、职称、基本工资、加班工资、奖金和总工资构成。
实现功能包括:
(1)添加职工的记录
(2)查询职工(分别按职工编号和姓名)
(3)对职工数据排序(分别按总工资和基本工资的降序)
(4)删除职工记录
(5)修改职工记录
(6)部门职工分析(平均工资、各种职称所占的百分比)
(7)输出职工信息表
3、机房预约系统
根据学校机房的要求,管理师生使用机房的信息管理,包括预约、登记、删除、输出。
三、课程设计要求:
1.基本要求
⑴教师会跟踪学生进度,学生不得以自己有私人电脑为借口而不来上机。
⑵每个人必须独立认真完成课设工作,且必须有程序运行结果。具体要求如下:
①程序结构合理
②界面比较美观
③提倡使用链表
④输入时有提示,输出时美观整齐
⑶每个人必须按时提交《C语言课程设计报告》和设计程序清单(纸质版、电子版)。
⑷课程设计任务必须由个人独立完成,禁止相互抄袭,如有发现,严肃处理。
2.考核评分标准
⑴根据平时上机考勤情况给出平时上机成绩。
⑵根据程序的编译,连接,运行结果。
⑶根据《C语言课程设计报告》,学生能对自己的程序面对教师提问并能熟练地解释清楚,以上三项缺一不可。
⑷由于课程设计各题目的难度不一,所以成绩的评定将根据各人完成题目的难度和完成情况的不同,分别评定成绩,如未能完成任何题目,则以不及格计算。
四、课程设计资料:
提交材料:
(1)纸质文档:C语言课程设计报告
(2)电子版文档:C语言课程设计报告、源程序
电子版文档命名格式为:20级计科+班号+学号后3位+姓名。
例如:20级计科1班001张三
(3)刻光盘:以班级为单位将全班同学的课程报告电子版刻于一张光盘
五、代码原码
1、学生通讯录管理系统设计
#include<iostream>
using namespace std;
#include<string>
#define MAX 1000 //最大人数
struct person
{
string name;
long long number;
};
void showMenu()
{
cout << "****************************" << endl;
cout << "***** 1、添加联系人 *****" << endl;
cout << "***** 2、显示联系人 *****" << endl;
cout << "***** 3、删除联系人 *****" << endl;
cout << "***** 4、查找联系人 *****" << endl;
cout << "***** 5、修改联系人 *****" << endl;
cout << "***** 6、清空联系人 *****" << endl;
cout << "***** 0、退出通讯录 *****" << endl;
cout << "****************************" << endl;
}
void cls() //清屏
{
system("pause");
system("cls");
showMenu();
}
void creatPer(person per[], int* j)
{
cout << "请输入姓名:";
cin >> per[*j].name;
cout << "请输入电话号码:";
cin >> per[*j].number;
*j += 1;
cout << "添加成功!" << endl;
cls();
}
void printPer(person per[], int j)
{
int i;
if (j != 0)
for (i = 0; i < j; i++)
cout << "姓名:" << per[i].name << " 电话:" << per[i].number << endl;
else
cout << "无联系人" << endl;
cls();
}
void delPer(person per[], int* j)
{
int i, k = 0;
string delname;
cout << "请输入您要删除的联系人:";
cin >> delname;
for (i = 0; i < *j; i++)
if (per[i].name == delname)
{
k++;
break;
}
if (k != 0)
{
for (; i < *j; i++)
per[i] = per[i + 1];
*j -= 1;
cout << "删除成功!" << endl;
}
else
cout << "查无此人!" << endl;
cls();
}
void findPer(person per[], int j)
{
int i, k = 0;
string cname;
cout << "输入您要查找的联系人:";
cin >> cname;
for (i = 0; i < j; i++)
if (cname == per[i].name)
{
cout << "姓名:" << per[i].name << " 电话:" << per[i].number << endl;
k++;
}
if (k == 0)
cout << "查无此人!" << endl;
cls();
}
void modifyPer(person per[], int j)
{
int i, k = 0;
string cname;
cout << "选择您要修改的联系人:";
cin >> cname;
for (i = 0; i < j; i++)
if (per[i].name == cname)
{
cout << "输入您要修改的姓名:";
cin >> per[i].name;
cout << "输入您要修改的电话:";
cin >> per[i].number;
k++;
cout << "修改成功!" << endl;
}
if (k == 0)
cout << "查无此人!" << endl;
cls();
}
void clearPer(person per[], int* j)
{
*j = 0;
cout << "已清空!" << endl;
cls();
}
int main()
{
int j, a;
j = 0; //通讯录人数
a = 1; //进入功能选择
person per[MAX]; //联系人数组
showMenu(); //显示菜单
while (a != 0) {
cout << "请选择功能:";
cin >> a;
if (a == 0)
{
cout << "欢迎下次使用!";
return 0;
}
else if (a == 1)
if (j < MAX)
creatPer(per, &j); //添加联系人函数
else
{
cout << "联系人已满!" << endl;
}
else if (a == 2)
printPer(per, j); //显示联系人函数
else if (a == 3)
delPer(per, &j); //删除联系人函数
else if (a == 4)
findPer(per, j); //查找联系人
else if (a == 5)
modifyPer(per, j); //修改联系人
else if (a == 6)
clearPer(per, &j); //清空联系人函数
}
}
2、职工信息管理系统
#include"workerManager.h"
#include<fstream>
WorkerManager::WorkerManager(){
//文件判断
ifstream ifs;
ifs.open("test.txt", ios::in);
if (!ifs.is_open())
{
this->n = 0;
this->perArray = NULL;
this->txtIsnull = true;
ifs.close();
return;
}
char ch;
ifs >> ch;
if (ifs.eof())
{
this->n = 0;
this->perArray = NULL;
this->txtIsnull = true;
ifs.close();
return;
}
//统计职工人数
this->n = this->txtNotnull();
//初始化职工数组
this->perArray = new workers * [this->n];
this->resetArr();
this->txtIsnull = false;
}
void WorkerManager::showMenu()
{
cout << "*********************************" << endl;
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;
cout << "*********************************" << endl;
}
void WorkerManager::add_per()
{
cout << "请输入增加职工数量:" << endl;
int j;
cin >> j;
if (j > 0)
{
int newN = this->n + j;
workers** newPer = new workers * [newN];
if (this->perArray != NULL)
{
for (int i = 0; i < this->n; i++)
{
newPer[i] = this->perArray[i];
}
}
for (int i = 0; i < j; i++)
{
int id;
string name;
int did;
cout << "请输入第 " << i + 1 << " 个新职工编号" << endl;
cin >> id;
cout << "请输入第 " << i + 1 << " 个新职工姓名" << endl;
cin >> name;
cout << "请选择该职工岗位:" << endl;
cout << "1、普通职工" << endl;
cout << "2、经理" << endl;
cout << "3、老板" << endl;
cin >> did;
workers* worker = NULL;
if (did == 1)
worker = new person(id, name, did);
if (did == 2)
worker = new person(id, name, did);
if (did == 3)
worker = new person(id, name, did);
newPer[this->n + i] = worker;
}
delete[] this->perArray;
this->perArray = newPer;
this->n = newN;
ofstream ofs;
ofs.open("test.txt", ios::out);
for (int i = 0;i < this->n; i++)
{
ofs << this->perArray[i]->id << " " << this->perArray[i]->name << " " << this->perArray[i]->did << endl;
}
ofs.close();
cout << "成功添加 " << j << " 名新职工!" << endl;
}
else
{
cout << "输入有误" << endl;
}
if (this->n != 0)
this->txtIsnull = false;
system("pause");
system("cls");
}
int WorkerManager::txtNotnull()
{
int id,did,num = 0;
string name;
ifstream ifs;
ifs.open("test.txt", ios::in);
while (ifs >> id && ifs >> name && ifs >> did)
{
num++;
}
ifs.close();
return num;
}
void WorkerManager::resetArr()
{
int id, did, num = 0;
string name;
ifstream ifs;
ifs.open("test.txt", ios::in);
while (ifs >> id && ifs >> name && ifs >> did)
{
workers* wk = NULL;
if (did == 1)
wk = new person(id, name, did);
if (did == 2)
wk = new manager(id, name, did);
if (did == 3)
wk = new boss(id, name, did);
this->perArray[num] = wk;
num++;
}
ifs.close();
}
void WorkerManager::showWorkers()
{
if (this->txtIsnull)
{
cout << "职工数据为空!" << endl;
system("pause");
system("cls");
return;
}
for (int i = 0; i < n; i++)
{
this->perArray[i]->sayWork();
}
system("pause");
system("cls");
}
void WorkerManager::delworker()
{
if (this->txtIsnull)
{
cout << "职工数据为空!" << endl;
system("pause");
system("cls");
return;
}
int id,i;
cout << "输入您要删除的职工编号:" << endl;
cin >> id;
for (i = 0; i < this->n; i++)
if (this->perArray[i]->id == id)
break;
if (i == this->n)
{
cout << "无此员工编号!" << endl;
system("pause");
system("cls");
return;
}
for (; i < n; i++)
this->perArray[i] = this->perArray[i + 1];
this->n -= 1;
ofstream ofs;
ofs.open("test.txt", ios::out);
for (i = 0; i < this->n; i++)
{
ofs << this->perArray[i]->id << " " << this->perArray[i]->name << " " << this->perArray[i]->did << endl;
}
ofs.close();
cout << "删除成功" << endl;
if (this->n == 0)
this->txtIsnull = true;
system("pause");
system("cls");
}
void WorkerManager::modifyWorker()
{
if (this->txtIsnull)
{
cout << "职工数据为空!" << endl;
system("pause");
system("cls");
return;
}
int id,i;
cout << "输入修改的职工编号:" << endl;
cin >> id;
for ( i = 0; i < this->n; i++)
{
if (this->perArray[i]->id == id)
{
cout << "已查到 " << this->perArray[i]->id << " 号职工,请输入新职工号" << endl;
cin >> this->perArray[i]->id;
cout << "请输入新姓名:" << endl;
cin >> this->perArray[i]->name;
cout << "请输入新岗位:" << endl;
cout << "1、普通职工" << endl;
cout << "2、经理" << endl;
cout << "3、老板" << endl;
cin >> this->perArray[i]->did;
ofstream ofs;
ofs.open("test.txt", ios::out);
for (i = 0; i < this->n; i++)
{
ofs << this->perArray[i]->id << " " << this->perArray[i]->name << " " << this->perArray[i]->did << endl;
}
ofs.close();
system("pause");
system("cls");
return;
}
}
if (i == this->n)
{
cout << "无此员工编号!" << endl;
system("pause");
system("cls");
}
}
void WorkerManager::selectWorker()
{
if (this->txtIsnull)
{
cout << "职工数据为空!" << endl;
system("pause");
system("cls");
return;
}
int id, opt, i;
string name;
cout << "请选择查找的方式:" << endl;
cout << "1、按职工编号查找" << endl;
cout << "2、按姓名查找" << endl;
cin >> opt;
if (opt == 1)
{
cout << "请输入查找的职工编号:" << endl;
cin >> id;
for(i = 0;i<this->n;i++)
if (this->perArray[i]->id == id)
{
cout << "查找成功!该职工信息如下:" << endl;
this->perArray[i]->sayWork();
system("pause");
system("cls");
return;
}
if (i == this->n)
{
cout << "无此员工编号!" << endl;
system("pause");
system("cls");
return;
}
}
if (opt == 2)
{
cout << "请输入查找的姓名:" << endl;
cin >> name;
for (i = 0; i < this->n; i++)
if (this->perArray[i]->name == name)
{
cout << "查找成功!该职工信息如下:" << endl;
this->perArray[i]->sayWork();
system("pause");
system("cls");
return;
}
if (i == this->n)
{
cout << "无此员工姓名!" << endl;
system("pause");
system("cls");
return;
}
}
else
{
cout << "输入有误!" << endl;
system("pause");
system("cls");
}
}
void WorkerManager::sortArray()
{
if (this->txtIsnull)
{
cout << "职工数据为空!" << endl;
system("pause");
system("cls");
return;
}
int max_id, j, opt;
workers* wk = NULL;
cout << "请选择排序类型:" << endl;
cout << "1、按职工编号升序" << endl;
cout << "2、按职工编号降序" << endl;
cin >> opt;
if (opt == 1)
{
for (int i = 0; i < (this->n) - 1; i++)
{
max_id = this->perArray[i]->id;
for (int k = i; k < this->n; k++)
{
if (this->perArray[k]->id <= max_id)
{
max_id = this->perArray[k]->id;
j = k;
}
}
wk = this->perArray[j];
this->perArray[j] = this->perArray[i];
this->perArray[i] = wk;
}
cout << "排序成功!排序结果为:" << endl;
this->showWorkers();
}
if (opt == 2)
{
for (int i = 0; i < (this->n) - 1; i++)
{
max_id = this->perArray[i]->id;
for (int k = i; k < this->n; k++)
{
if (this->perArray[k]->id >= max_id)
{
max_id = this->perArray[k]->id;
j = k;
}
}
wk = this->perArray[j];
this->perArray[j] = this->perArray[i];
this->perArray[i] = wk;
}
this->showWorkers();
}
}
void WorkerManager::clearWorker()
{
int opt;
cout << "确认清空?" << endl;
cout << "1、确认" << endl;
cout << "2、返回" << endl;
cin >> opt;
if (opt == 2)
{
system("pause");
system("cls");
return;
}
ofstream ofs;
//打开模式 ios::trunc 如果存在删除文件并重新创建
ofs.open("test.txt", ios::trunc);
ofs.close();
if (this->perArray != NULL)
{
for (int i = 0; i < this->n; i++)
{
//删除堆区的每个职工对象
if (this->perArray[i] != NULL)
delete this->perArray[i];
}
//删除堆区数组指针
this->n = 0;
delete[] this->perArray;
this->perArray = NULL;
this->txtIsnull = true;
cout << "清空成功" << endl;
system("pause");
system("cls");
return;
}
cout << "清空成功" << endl;
system("pause");
system("cls");
return;
}
WorkerManager::~WorkerManager(){}
3、机房预约系统
#include"ManagerClass.h"
//构造函数初始化管理员信息
Manager::Manager(){
this->select = 0;
ifstream ifs("admin.txt", ios::in);
while (ifs >> this->name && ifs >> this->passwordl)
{
}
ifs.close();
ifstream sfs("stu_vec.txt", ios::in);
char sch;
sfs >> sch;
if (sfs.eof())
{
this->stu_file = true;
sfs.putback(sch);
sfs.close();
}
else
{
sfs.putback(sch);
this->stu_file = false;
Student s;
while (sfs >> s.id&& sfs >> s.name&& sfs >> s.password)
{
this->stu_vec.push_back(s);
}
sfs.close();
}
ifstream tfs("tea_vec.txt", ios::in);
char tch;
tfs >> tch;
if (tfs.eof())
{
this->tea_file = true;
tfs.putback(tch);
tfs.close();
}
else
{
tfs.putback(tch);
this->tea_file = false;
Teacher t;
while (tfs >> t.id&& tfs >> t.name&& tfs >> t.password)
{
this->tea_vec.push_back(t);
}
tfs.close();
}
ifstream rfs("computerRoom.txt", ios::in);
int a, b;
while (rfs >> a && rfs >> b)
{
this->cr.insert(make_pair(a, b));
}
rfs.close();
for (int i = 1; i < 6; i++)
{
vector<int> v1;
v1.push_back(this->cr[1]);
v1.push_back(this->cr[2]);
v1.push_back(this->cr[3]);
v1.push_back(this->cr[1]);
v1.push_back(this->cr[2]);
v1.push_back(this->cr[3]);
this->cr_state.insert(make_pair(i, v1));
}
ifstream cfs("stu_state.txt", ios::in);
char cch;
cfs >> cch;
if (cfs.eof())
{
this->stu_state_file = true;
cfs.putback(cch);
cfs.close();
}
else
{
cfs.putback(cch);
this->stu_state_file = false;
int id, c, d;
while (cfs >> id && cfs >> a && cfs >> b && cfs >> c && cfs >> d)
{
vector<int> v;
v.push_back(a);
v.push_back(b);
v.push_back(c);
v.push_back(d);
this->stu_state.insert(make_pair(id, v));
}
cfs.close();
for (map<int, vector<int>>::iterator it = this->stu_state.begin(); it != this->stu_state.end(); it++)
{
if ((*it).second[3] == 2)
{
//this->cr[(*it).second[2]] -= 1;
this->judge((*it).first);
}
}
}
}
void Manager::ma_Menu()
{
cout << "欢迎管理员:" << this->name << " 登录" << endl;
cout << " -----------------------" << endl;
cout << " | 1、添加账号 |" << endl;
cout << " | 2、查看账号 |" << endl;
cout << " | 3、查看机房 |" << endl;
cout << " | 4、清空预约 |" << endl;
cout << " | 0、注销登录 |" << endl;
cout << " -----------------------" << endl;
}
void Manager::showMenu()
{
cout << "====================欢迎来到 Verification 机房预约系统====================" << endl;
cout << "请输入您的身份:" << endl;
cout << " -----------------------" << endl;
cout << " | 1、学生代表 |" << endl;
cout << " | 2、老 师 |" << endl;
cout << " | 3、管 理 员 |" << endl;
cout << " | 0、退 出 |" << endl;
cout << " -----------------------" << endl;
}
void Manager::ma_1()
{
int type_sel = 0;
cout << "请输入添加账号的类型:" << endl;
cout << "1、学生" << endl;
cout << "2、老师" << endl;
//判断选择类型
cin >> type_sel;
if (type_sel == 1)
{
Student s;
cout << "请输入学号:" << endl;
cin >> s.id;
if (this->stu_file){}
else
{
for (vector<Student>::iterator it = this->stu_vec.begin(); it != this->stu_vec.end(); it++)
{
if (s.id == (*it).id)
{
cout << "学生已存在!" << endl;
return;
}
}
}
cout << "请输入姓名:" << endl;
cin >> s.name;
cout << "请输入密码:" << endl;
cin >> s.password;
cout << "添加成功!" << endl;
this->stu_file = false;
this->stu_vec.push_back(s);
ofstream ofs("stu_vec.txt", ios::out | ios::app);
ofs << s.id << " " << s.name << " " << s.password << endl;
ofs.close();
}
else if(type_sel == 2)
{
Teacher t;
cout << "请输入职工号:" << endl;
cin >> t.id;
if (this->tea_file) {}
else
{
for (vector<Teacher>::iterator it = this->tea_vec.begin(); it != this->tea_vec.end(); it++)
{
if (t.id == (*it).id)
{
cout << "职工已存在!" << endl;
return;
}
}
}
cout << "请输入姓名:" << endl;
cin >> t.name;
cout << "请输入密码:" << endl;
cin >> t.password;
cout << "添加成功!" << endl;
this->tea_file = false;
this->tea_vec.push_back(t);
ofstream ofs("tea_vec.txt", ios::out | ios::app);
ofs << t.id << " " << t.name << " " << t.password << endl;
ofs.close();
}
}
void Manager::ma_2()
{
int select = 0;
cout << "请选择查看内容:" << endl;
cout << "1、查看所有学生" << endl;
cout << "2、查看所有老师" << endl;
cin >> select;
if (select == 1)
{
if (this->stu_file)
{
cout << "文档为空" << endl;
return;
}
cout << "所有学生信息如下:" << endl;
for (vector<Student>::iterator it = this->stu_vec.begin(); it != this->stu_vec.end(); it++)
{
cout << "学号:" << (*it).id << " 姓名:" << (*it).name << " 密码:" << (*it).password << endl;
}
}
else if(select == 2)
{
if (this->tea_file)
{
cout << "文档为空" << endl;
return;
}
cout << "所有老师信息如下:" << endl;
for (vector<Teacher>::iterator it = this->tea_vec.begin(); it != this->tea_vec.end(); it++)
{
cout << "职工编号:" << (*it).id << " 姓名:" << (*it).name << " 密码:" << (*it).password << endl;
}
}
}
void Manager::ma_3()
{
cout << "机房信息如下:" << endl;
for (map<int, int>::iterator it = this->cr.begin(); it != this->cr.end(); it++)
{
cout << "机房编号:" << (*it).first <<" 机房最大容量:"<<(*it).second<< endl;
}
}
void Manager::ma_4()
{
this->stu_state_file = true;
this->stu_state.erase(stu_state.begin(), stu_state.end());
ofstream ofs("stu_state.txt", ios::trunc);
ofs.close();
cout << "清空成功!" << endl;
}
Manager::~Manager(){}
六、说点东西。
我用的编程工具是vs2013,无论在学校还是外面的培训机构里学习C语言和C++普遍都是使用这个软件,以下是百度复制简单的简介:
-
Microsoft Visual Studio(简称VS)是美国微软公司的开发工具包系列产品。
-
VS是一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具、代码管控工具、集成开发环境(IDE)等等。所写的目标代码适用于微软支持的所有平台,包括Microsoft Windows、Windows Mobile、Windows CE、.NET Framework、.NET Compact Framework和Microsoft Silverlight 及Windows Phone。
-
Visual Studio是目前最流行的Windows平台应用程序的集成开发环境。
创作不易,如果觉得有用的话,麻烦抬下贵手留下评论和赞,有什么问题也可以交流