c语言人事管理系统

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

一、内容(标题:宋体,粗体,四号字)
本程序主要实现了对高校人事的管理。

其不仅可以对人员的新建、添加、删除的基本操作,还可以进行查询编辑、以不同的方式排序等操作。

进行操作时,只要输入相对应的数字或信息即可。

二、上机环境
操作系统:win 7\.windows Xp
开发工具:VC6.0
三、函数调用关系图
四、各函数功能说明
1. void add(); 新建\添加
2. void del(); 删除
3. void sear_edit(); 查询编辑
4. void scan(); 浏览
5. void order(); 排序
6. void old_order(); 年龄排序
7. void comingtime_order(); 来院时间排序
8. void main() 主函数
五、算法描述或流程图
0.main ( )函数
1.add ( )函数
2.del ()函数
3.sear_edit( )函数
4.scan ()函数
5.order ( )函数
6.exit ()函数
六、程序运行效果图
0.main ()函数
1.添加函数exit ()exit ()退出
2.浏览
3.查询编辑
4.删除
5.排序
6.删后浏览
七、总结
一星期的C语言课程设计结束了,在这八天的时间里,我自己独立完成了一个程序从构思结构,到编写代码,然后上机调试运行的过程,感觉自己收获很大。

通过解决一个又一个的问题,熟悉了C语言的应用,对计算机语言应用的理解又深了一层,在老师的指导下,学会了模块设计的方法,用流程图表示算法,掌握了用C语言进行程序设计的能力。

在设计过程中,我理解了对于一个较大的程序,不可能一次编写出一个较大的系统,通常要采取自顶向下的设计思想,先设计主函数,再通过完善一个个的功能模块来完成程序的设计过程,在设计过程中要充分理解整个程序的设计思路,采用逐步细化的方式来完成整个程序。

使各个模块能够很好地兼容在一起,并进行运行测试,程序能够无错误的运行。

之后,优化界面和显示,使人能够轻松愉悦地操作。

在在运行调试过程中,当删除或更改了信息后可进行查询操作但就不能进行浏览,可是,在文本文件中删除最后一个空格,程序就能正确无误地运行。

在这问题中,我用过在文件尾加\b等的方法,还是解决不了,最后,我想到在文件写入时先\n,再写入,这样一来,文件末的空格就不存在了,经运行测试证明,问题就此解决。

这次课程设计给我最大的启示就是解决问题要多看多思考,同时,设计并完善这个简单的程序竟然花了我这么长时间,也说明平时用功还不够,以后得加倍努力!
八、参考文献
李春葆.C语言程序设计教程(第2版).清华大学出版社,2011
九、程序清单
#include<stdio.h> #include<stdlib.h> #define M 2000 #define N 20
void add(); void del();
void sear_edit(); void scan(); void order(); void old_order();
void comingtime_order();
void main()
{
int n;
system("cls");
printf("\n\n\t\t***********************高校人事管理*************************\n\n\n");
printf("\t\t\t1\t 添加\n\n");
printf("\t\t\t2\t 删除\n\n");
printf("\t\t\t3\t 查询与编辑\n\n");
printf("\t\t\t4\t 浏览\n\n");
printf("\t\t\t5\t 排序\n\n");
printf("\t\t\t6\t 退出\n\n");
printf("\t\t******************************* ******************************\n");
printf("选择您要的服务: [ ]\b\b");
scanf("%d",&n);
if(n<1||n>6)
{
do
{
printf("\n对不起,您输入错误,请重新输入:[ ]\b\b");
scanf("%d",&n);
}while(n<1||n>6);
//确保输入正确数字。

}
switch(n)
{
case 1:add();break;
case 2:del();break;
case 3:sear_edit();break;
case 4:scan();break;
case 5:order();break;
case 6:exit(0);
}
}
struct worker
{
int num;
char name[20];
char sex[10];
int old;
char zhicheng[20];
char zhiwei[20];
char mianmao[20];
char xueli[20];
int come_time;
int work_time;
int leibie;
}wor[N];
//添加模块
void add()
{
FILE *fp;
int i,number,n;
struct worker wor_t[N];
system("cls");
printf("\n\n\t\t***************添加人员的信息****************\n\n\n");
printf("您要添加的人的人数:[ ]\b\b\b");
scanf("%d",&number);
printf("输入添加人的信息:\n");
for(i=0;i<number;i++)
{
printf("\n\t\t\t第%d个\t\t\t\n",i+1);
printf("编号:\n");
scanf("%d",&wor_t[i].num);
printf("姓名:\n");
scanf("%s",wor_t[i].name);
printf("性别:\n");
scanf("%s",wor_t[i].sex);
printf("年龄:\n");
scanf("%d",&wor_t[i].old);
printf("职称:\n");
scanf("%s",wor_t[i].zhicheng);
printf("职位:\n");
scanf("%s",wor_t[i].zhiwei);
printf("政治面貌:\n");
scanf("%s",wor_t[i].mianmao);
printf("学历:\n");
scanf("%s",wor_t[i].xueli);
printf("来院时间:\n");
scanf("%d",&wor_t[i].come_time);
printf("在院工作时间:\n");
scanf("%d",&wor_t[i].work_time);
printf("在职与否:\t\t1\t 在\t\t2\t 不在\n");
scanf("%d",&wor_t[i].leibie);
printf("您刚才输入的人的信息\n");
printf("%d %s %s %d %s %s %s %s %d %d %d \n",wor_t[i].num,wor_t[i].name,
wor_t[i].sex,wor_t[i].old,wor_t[i].zhicheng,wor_t [i].zhiwei,wor_t[i].mianmao,
wor_t[i].xueli,wor_t[i].come_time,wor_t[i].work _time,wor_t[i].leibie);
}
if((fp=fopen("worker.txt","a"))==NULL)
//以追加方式新建或追加信息
{
printf("\nCannot open file\n"); exit(0);
}
for(i=0;i<number;i++)
{
fprintf(fp,"\n%d %s %s %d %s %s %s %s %d % d %d",wor_t[i].num,wor_t[i].name,wor_t[i].sex,wor_t[i ].old,
wor_t[i].zhicheng,wor_t[i].zhiwei,wor_t[i].mian mao,wor_t[i].xueli,wor_t[i].come_time,wor_t[i].work_ time,wor_t[i].leibie);
}
fclose(fp);
printf("您要:\n\t\t1\t 继续添加\n\t\t2\t 返回\n\t\t3\t 退出\n请选择:[ ]\b\b"); //添加结束后,选择操作。

scanf("%d",&n);
if(n<1||n>3)
{
do
{
printf("输入错误!请重新输入:[ ]\b\b");
scanf("%d",&n);
}
while(n<1||n>3); //确保输入的数字正确。

}
switch(n)
{
case 1:add();break;
case 2:main();break;
case 3:exit(0);
}
}
//删除模块
void del()
{
FILE *fp,*fp1;
int i,number,k,j,m,n;
struct worker worker1[M],worker2[M];
int a[N];
system("cls");
printf("\t\t***************删除人员的信息****************\n\n\n\n\n");
printf("您要删除的人的人数:\n");
scanf("%d",&number);
for(i=0;i<number;i++)
{
printf("\n\t\t\t第%d个\t\t\t\n",i+1);
printf("输入要删除的编号:\n");
scanf("%d",&a[i]);
printf("您刚才输入的人的信息的编号:\n");
printf("%d\n",a[i]);
}
if((fp=fopen("worker.txt","r"))==NULL) {
printf("\nCannot open file\n");
getchar();
exit(0);
}
printf("输出公司更改前所有人员的信息:\n编号姓名性别年龄职称职位面貌学历来院时间工作时间在职与否\n\n");
for(i=0;!feof(fp);i++)
//把worker.txt的内容写入worker2
fscanf(fp,"%d %s %s %d %s %s %s %s %d %d %d",&worker2[i].num,worker2[i].name,worker2[i].sex ,&worker2[i].old,
worker2[i].zhicheng,worker2[i].zhiwei,worker2[i ].mianmao,worker2[i].xueli,&worker2[i].come_time,& worker2[i].work_time,&worker2[i].leibie);
k=i;
fclose(fp);
m=0;
for(i=0;i<k;i++)
{
for(j=0;j<number;j++)
{
if(worker2[i].num!=a[j])
{
worker1[m]=worker2[i];
m++;
}
}
printf(" %d %s %s %d %s % s %s %s %d %d %d\n",worker2[i].num ,worker2[i].name,worker2[i].sex,worker2[i].old,
worker2[i].zhicheng,worker2[i].zhiwei,worker2[i ].mianmao,worker2[i].xueli,worker2[i].come_time,wor ker2[i].work_time,worker2[i].leibie);
if(k==m)
{
printf("\n这个人不存在!!!");main(); //检查,不存在则返回主界面
}
}
printf("输出公司更改后所有人员的信息:\n编号姓名性别年龄职称职位面貌学历来院时间工作时间在职与否\n");
if((fp1=fopen("worker.txt","w+"))==NULL)
{
printf("\nCannot open file\n");
getchar();
exit(0);
}
for(i=0;i<m;i++)
{
printf(" %d %s %s %d %s %s %s %s %d %d %d\n",worker1[i].num,wor ker1[i].name,worker1[i].sex,worker1[i].old,
worker1[i].zhicheng,worker1[i].zhiwei,worker1[i ].mianmao,worker1[i].xueli,worker1[i].come_time,wor ker1[i].work_time,worker1[i].leibie);
fprintf(fp1,"\n%d %s %s %d %s %s %s %s %d %d %d",worker1[i].num,worker1[i].name,worker1 [i].sex,worker1[i].old,
worker1[i].zhicheng,worker1[i].zhiwei,worker1[i ].mianmao,worker1[i].xueli,worker1[i].come_time,wor ker1[i].work_time,worker1[i].leibie);
}
//fprintf(fp1,"\");
fclose(fp1);
getchar();
printf("\n您要:\n\t\t1\t 返回\n\n\t\t2\t 退出\n 请选择:[ ]\b\b");
scanf("%d",&n);
if(n<1||n>2)
{
do
{
printf("\n对不起,您输入错误,请重新输入:[ ]\b\b"); //确保输入正确数字
scanf("%d",&n);
}while(n<1||n>2);
}
switch(n)
{
case 1:main();break;
case 2:exit(0);
}
}
//排序模块
void order()
{
int n, w;
do
{
system("cls");
printf("\t\t*******************排序**********************\n\n\n");
printf("\t\t\t1\t 按年龄排序\n\n");
printf("\t\t\t2\t 按来院时间排序\n\n");
printf("\t\t\t3\t 返回\n\n");
printf("\n\n\t\t**************************** ******************\n\n");
printf("\n请选择您想要的排序方式: [ ]\b\b");
scanf("%d",&n);
if(n<1||n>3)
{
w=1;
getchar();
//确保输入的数字正确。

}
else w=0;
}
while(w==1);
switch(n)
{
case 1:old_order();break;
case 2:comingtime_order();break;
case 3:main();break;
}
}
//年龄排序
void old_order()
{
FILE *fp,*fp1;
struct worker wor_people ,worker1[M];
int i,j,k,n;
if((fp=fopen("worker.txt","r"))==NULL)
{
printf("\nCannot open file\n");
exit(0);
}
for(i=0;!feof(fp);i++)
fscanf(fp,"%d %s %s %d %s %s %s %s %d %d %d",&worker1[i].num,worker1[i].name,worker1[i].sex ,&worker1[i].old,
worker1[i].zhicheng,worker1[i].zhiwei,worker1[i ].mianmao,worker1[i].xueli,&worker1[i].come_time,& worker1[i].work_time,&worker1[i].leibie);
k=i;
for(i=0;i<k;i++)
{
for(j=i+1;j<k;j++)
{
if(worker1[i].old>worker1[j].old)
{
wor_people=worker1[i];worker1[i]=worker1[j];w orker1[j]=wor_people; //由小到大的方式对年龄排序
}
}
}
if((fp1=fopen("old_order.txt","w"))==NULL)
{
printf("\nCannot open file\n");
}
for(i=0;i<k;i++)
{
printf("%d %s %s %d %s %s %s %s %d %d %d\ n",worker1[i].num,worker1[i].name,worker1[i].sex,wo rker1[i].old,
worker1[i].zhicheng,worker1[i].zhiwei,worker1[i ].mianmao,worker1[i].xueli,worker1[i].come_time,wor ker1[i].work_time,worker1[i].leibie);
fprintf(fp1,"%d %s %s %d %s %s %s %s %d %d %d\n ",worker1[i].num,worker1[i].name,worker1[i].sex,wor ker1[i].old,worker1[i].zhicheng,
worker1[i].zhiwei,worker1[i].mianmao,worker1[i ].xueli,worker1[i].come_time,worker1[i].work_time,w orker1[i].leibie);
}
fclose(fp1);
printf("\n您要:\n\t\t1\t 返回\n\n\t\t2\t 退出\n 请选择:[ ]\b\b");
scanf("%d",&n);
if(n<1||n>2)
{
do
{
printf("\n对不起,您输入错误,请重新输入:[ ]\b\b");
scanf("%d",&n);
}while(n<1||n>2);
}
switch(n)
{
case 1:order();break;
case 2:exit(0);
}
}
//来院时间排序
void comingtime_order()
{
FILE *fp,*fp1;
struct worker wor_people ,worker1[M];
int i,j,k,n;
if((fp=fopen("worker.txt","r"))==NULL)
{
printf("\nCannot open file\n");
exit(0);
}
for(i=0;!feof(fp);i++)
fscanf(fp,"%d %s %s %d %s %s %s %s %d %d %d",&worker1[i].num,worker1[i].name,worker1[i].sex ,&worker1[i].old,
worker1[i].zhicheng,worker1[i].zhiwei,worker1[i ].mianmao,worker1[i].xueli,&worker1[i].come_time,& worker1[i].work_time,&worker1[i].leibie);
k=i;
for(i=0;i<k;i++)
{
for(j=i+1;j<k;j++)
{
if(worker1[i].come_time>worker1[j].come_time)
{
wor_people=worker1[i];worker1[i]=worker1[j];w orker1[j]=wor_people; //由先到后对人员排序
}
}
}
if((fp1=fopen("comingtime_order.txt","w"))==N ULL)
{
printf("\nCannot open file\n");
}
for(i=0;i<k;i++)
{
printf("%d %s %s %d %s %s %s %s %d %d %d\ n",worker1[i].num,worker1[i].name,worker1[i].sex,wo rker1[i].old,
worker1[i].zhicheng,worker1[i].zhiwei,worker1[i ].mianmao,worker1[i].xueli,worker1[i].come_time,wor ker1[i].work_time,worker1[i].leibie);
fprintf(fp1,"%d %s %s %d %s %s %s %s %d %d %d\n ",worker1[i].num,worker1[i].name,worker1[i].sex,wor ker1[i].old,worker1[i].zhicheng,
worker1[i].zhiwei,worker1[i].mianmao,worker1[i ].xueli,worker1[i].come_time,worker1[i].work_time,w orker1[i].leibie);
}
fclose(fp1);
printf("\n您要:\n\t\t1\t 返回\n\n\t\t2\t 退出\n 请选择:[ ]\b\b");
scanf("%d",&n);
if(n<1||n>2)
{
do
{
printf("\n对不起,您输入错误,请重新输入:[ ]\b\b");
scanf("%d",&n);
}while(n<1||n>2);
}
switch(n)
{
case 1:order();break;
case 2:exit(0);
}
}
//查询编辑模块
void sear_edit()
{
FILE *fp,*fp1;
struct worker wor_people ,worker1[M];
int i,k,m,n,p;
system("cls");
printf("\t\t************查询编辑*****************\n\n");
printf("输入你想查询的人的编号\n");
scanf("%d",&wor_people.num);
if((fp=fopen("worker.txt","r"))==NULL)
{
printf("\nCannot open file\n");
getchar();
exit(0);
}
for(i=0;!feof(fp);i++)
for(i=0;!feof(fp);i++)
fscanf(fp,"%d %s %s %d %s %s %s %s %d %d %d",&worker1[i].num,worker1[i].name,worker1[i].sex ,&worker1[i].old,
worker1[i].zhicheng,worker1[i].zhiwei,worker1[i ].mianmao,worker1[i].xueli,&worker1[i].come_time,& worker1[i].work_time,&worker1[i].leibie);
k=i;m=-1;
for(i=0;i<k;i++)
{
if(wor_people.num==worker1[i].num)
{
printf("%d %s %s %d %s %s %s %s %d %d %d" ,worker1[i].num,worker1[i].name,worker1[i].sex,work er1[i].old,
worker1[i].zhicheng,worker1[i].zhiwei,worker1[i ].mianmao,worker1[i].xueli,worker1[i].come_time,wor ker1[i].work_time,worker1[i].leibie);
m=i;
}
}
fclose(fp);
if(m==-1)
{
do
{
printf("\n这个人不存在\n\t\t1\t 返回\n请选择[ ]\b\b");
scanf("%d",&p);
}while(p!=1);
sear_edit(0);
}
printf("\n你想重新编辑这个人的信息吗?\n\t\t1\t 想\n\n\t\t2\t不想\n[ ]\b\b");
scanf("%d",&n);
if(n<1||n>2)
{
do
{
printf("输入错误!请重新输入[ ]\b\b");
scanf("%d",&n);
}while(n<1||n>2);
}
if(n==1)
{
{
printf("这个人的初始信息:\n");
printf("\n%d %s %s %d %s %s %s %s %d %d % d\n",worker1[m].num,worker1[m].name,worker1[m].se x,worker1[m].old,
worker1[m].zhicheng,worker1[m].zhiwei,worker 1[m].mianmao,worker1[m].xueli,worker1[m].come_ti me,worker1[m].work_time,worker1[m].leibie);
printf(" 输入新的信息\n");
printf("编号:\n");
scanf("%d",&worker1[m].num);
printf("姓名:\n");
scanf("%s",worker1[m].name);
printf("性别:\n");
scanf("%s",worker1[m].sex);
printf("年龄:\n");
scanf("%d",&worker1[m].old);
printf("职称:\n");
scanf("%s",worker1[m].zhicheng);
printf("职位:\n");
scanf("%s",worker1[m].zhiwei);
printf("政治面貌:\n");
scanf("%s",worker1[m].mianmao);
printf("学历:\n");
scanf("%s",worker1[m].xueli);
printf("来院时间:\n");
scanf("%d",&worker1[m].come_time);
printf("在院工作时间:\n");
scanf("%d",&worker1[m].work_time);
printf("在职与否:\t\t1\t 在\t\t2\t 不在\n");
scanf("%d",&worker1[i].leibie);
printf("您刚才输入的人的信息\n");
printf("\n%d %s %s %d %s %s %s %s %d %d % d\n",worker1[m].num,worker1[m].name,worker1[m].se x,worker1[m].old,
worker1[m].zhicheng,worker1[m].zhiwei,worker 1[m].mianmao,worker1[m].xueli,worker1[m].come_ti me,worker1[m].work_time,worker1[m].leibie);
}
if((fp1=fopen("worker.txt","w"))==NULL)
{
printf("\nCannot open file\n");
exit(0);
}
for(i=0;i<k-1;i++)
fprintf(fp1,"\n%d %s %s %d %s %s %s %s %d %d %d",worker1[i].num,worker1[i].name,worker1[i].s ex,worker1[i].old,
worker1[i].zhicheng,worker1[i].zhiwei,worker1[i ].mianmao,worker1[i].xueli,worker1[i].come_time,wor ker1[i].work_time,worker1[i].leibie);
fclose(fp1);
}
if(n=2)
{
printf("\n你想继续查询吗?\n\t\t1\t 继续\n\n\t\t2\t 返回\n[ ]\b\b");
scanf("%d",&p);
switch(p)
{
case 1:sear_edit();break;
case 2:main();break;
}
}
}
void scan()
{
FILE *fp;
struct worker worker1[M];
int i,k,n;
system("cls");
printf("\t\t\t所有记录如下:\n编号姓名性别年龄职称职位面貌学历来院时间工作时间在职与否\n\n");
if((fp=fopen("worker.txt","r"))==NULL)
{
printf("\nCannot open file\n");
exit(0);
}
for(i=0;!feof(fp);i++)
fscanf(fp,"%d %s %s %d %s %s %s %s %d %d %d",&worker1[i].num,worker1[i].name,worker1[i].sex ,&worker1[i].old,
worker1[i].zhicheng,worker1[i].zhiwei,worker1[i ].mianmao,worker1[i].xueli,&worker1[i].come_time,& worker1[i].work_time,&worker1[i].leibie);
k=i;
for(i=0;i<k;i++)
{
printf("%2d %s %s %4d %s %s
%s %s %d %d %3d\n",worker1[i].num, worker1[i].name,worker1[i].sex,worker1[i].old,
worker1[i].zhicheng,worker1[i].zhiwei,worker1[i ].mianmao,worker1[i].xueli,worker1[i].come_time,wor
ker1[i].work_time,worker1[i].leibie);
fprintf(fp,"%2d %s %s %4d %s %s
%s %s %d %d %3d\n",worker1[i].num,wo rker1[i].name,worker1[i].sex,worker1[i].old,worker1[i]
.zhicheng,
worker1[i].zhiwei,worker1[i].mianmao,worker1[i ].xueli,worker1[i].come_time,worker1[i].work_time,w orker1[i].leibie);
}
fclose(fp);
printf("\n您要:\n\t\t1\t 返回\n\n\t\t2\t 退出\n
请选择:[ ]\b\b");
scanf("%d",&n);
if(n<1||n>2)
{
do
{
printf("\n对不起,您输入错误,请
重新输入:[ ]\b\b");
scanf("%d",&n);
}while(n<1||n>2);
}
switch(n)
{
case 1:main();break;
case 2:exit(0);
}
}
21。

相关文档
最新文档