职工信息管理系统
每个学生在教师提供的课程设计题目中任意选择一题,独立完成,题目选定后不可更换。
职工信息管理系统设计
职工信息包括职工号、姓名、性别、出生年月、学历、职务、工资、住址、电话等(职工号不重复)。试设计一职工信息管理系统,使之能提供以下功能:
职工信息录入功能(职工信息用文件保存)--输入
职工信息浏览功能 --输出
查询或排序功能:(至少一种查询方式) --算法
●按工资查询 ●按学历查询等
职工信息删除、修改功能(任选项)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct workers
{
char jobno[15]; //职工号
char name[15];
char sex[15];
char birthday[15];
char degree[15];//学历
char zhiwu[15];
char gongzi[15];
char addr[15];
char tel[15];
};
typedef struct node
{
struct workers data;
struct node *next;
}
Node;
//
void A(Node *worker)
{
Node *p,*q;
char n[10];
q=worker;
while(q->next!=NULL)
{
q=q->next;
}
while(1)
{
printf("提示:输入0返回主菜单!\n");
printf("请输入职工号:");
scanf("%s",n);
if(strcmp(n,"0")==0)
{
break;
}
p=(Node *)malloc(sizeof(Node));
strcpy(p->data.jobno,n);
printf("请输入姓名:");
scanf("%s",p->data.name);
printf("请输入性别:");
scanf("%s",p->data.sex);
printf("请输入年月日:");
scanf("%s",p->data.birthday);
printf("请输入学历:");
scanf("%s",p->data.degree);
printf("请输入职务:");
scanf("%s",p->data.zhiwu);
printf("请输入工资:");
scanf("%s",p->data.gongzi);
printf("请输入住址:");
scanf("%s",p->data.addr);
printf("请输入电话:");
scanf("%s",p->data.tel);
printf("您已完成第一条信息的添加!");
p->next=NULL;
q->next=p;
q=p;
}
}
//修改职工信息函数
int B(Node *worker)
{
Node *p;
char find[20];
p=worker->next;
if(p==NULL)
{
printf("\n提示:没有质料可以修改!/n");
return 0;
}
printf("请输入要修改的职工号:");
scanf("%s",find);
while(p!=NULL)
{
if(strcmp(p->data.jobno,find)==0)
{
break;
}
p=p->next;
}
if(p!=NULL)
{
int x;
while(1)
{
printf("请完成修改请输入0,否则输入非0数字进行修改!");
scanf("%d",&x);
if(x==0)
{
break;
}
printf("请输入新职工号:");
scanf("%s",p->data.jobno);
printf("请输入新姓名:");
scanf("%s",p->data.name);
printf("请输入新性别:");
scanf("%s",p->data.sex);
printf("请输入新年月日:");
scanf("%s",p->data.birthday);
printf("请输入新学历:");
scanf("%s",p->data.degree);
printf("请输入新职务:");
scanf("%s",p->data.zhiwu);
printf("请输入新工资:");
scanf("%s",p->data.gongzi);
printf("请输入新住址:");
scanf("%s",p->data.addr);
printf("请输入新电话:");
scanf("%s",p->data.tel);
printf("\n 提示:该员工质料已经修改!\n");
}
}
else
printf("\n提示:没有你要修改的质料!");
}
//输出职工信息函数
int C(Node *worker)
{
Node *p;
p=worker->next;
if(p==NULL)
{
printf("\n提示:没有信息可以显示!\n");
return 0;
}
printf("\t\t\t\t显示结果!\n");
printf("\n 职工号 姓名 性别 出生年月日 学历 职务 工资 住址 电话 \n");
while(p!=NULL)
{
printf("\n %s\t %s\t %s\t %s\t %s\t %s\t %s\t% s\t %s\t\n",
p->data.jobno,
p->data.name,
p->data.sex,
p->data.birthday,
p->data.degree,
p->data.zhiwu,
p->data.gongzi,
p->data.addr,
p->data.tel
);
p=p->next;
}
}
//查询
int D(Node *worker)
{
Node *p;
int sel;
char find[20];
p=worker->next;
if(p==NULL)
{
printf("提示:没有质料可以查询!\n");
return 0;
}
printf("\n提示:\n输入0----退出\t 输入 1------安学历查询\t 输入2------按职工工资查询\t");
printf("请选择:");
scanf("%d",&sel);
if(sel ==1)
{
printf("\n请输入你要查询的分类的学历:");
scanf("%s",find);
while(p!=NULL)
{
if(strcmp(p->data.degree,find)==0)
{
printf("\n 职工号 姓名 性别 出生年月日 学历 职务 工资 住址 电话 \n");
printf("\n %s\t %s\t %s\t %s\t %s\t %s\t %s\t% s\t %s\t\n",
p->data.jobno,
p->data.name,
p->data.sex,
p->data.birthday,
p->data.degree,
p->data.zhiwu,
p->data.gongzi,
p->data.addr,
p->data.tel
);
}
p=p->next;
}
}
else if (sel == 2)
{
printf(" \n输入你要查询分类的职工姓名:");
scanf("%s", find);
while (p!=NULL)
{
if (strcmp(p->data.degree, find) == 0)
{
printf(" 职工号 姓名 性别 出生年月 学历 职务 工资 住址 电话 \n ");
printf(" \n %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t \n ", p->data.jobno,
p->data.name,
p->data.sex,
p->data.birthday,
p->data.degree,
p->data.zhiwu,
p->data.gongzi,
p->data.addr,
p->data.tel);
}
p = p->next;
}
}
else if (sel == 0)
return 0;
}
//删除职工信息函数
int E(Node *worker)
{
Node *p, *r;
char find[10];
p = worker->next;
if (p == NULL)
{
printf("提示:没有职工信息可以删除!\n ");
return 0;
}
printf(" \n提示:请输入你要删除的职工号!\n ");
scanf("%s", find);
while (p != NULL)
{
if (strcmp(p->data.jobno, find) == 0)
{
break;
}
p = p->next;
}
if (p!=NULL)
{
r = worker;
while (r->next != p)
{
r = r->next;
}
r->next = r->next->next;
}
}
//将职工信息保存到文件中
void G(Node *worker)
{
int n;
Node *p = NULL;
FILE *fp;
printf("是否保存到文件?( 1-----保存!,0-----不保存! )");
scanf("%d", &n);
if (n == 1)
{
if (worker->next == NULL)
{
printf(" 没有记录!");
}
else
{
p = worker->next;
}
if ((fp = fopen(" 职工信息管理系统.txt ", " wb ")) == NULL)
{
printf(" 文件不能打开!\n");
}
while (p != NULL)
{
fprintf(fp, " %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t ", p->data.jobno,
p->data.name,
p->data.sex,
p->data.birthday,
p->data.degree,
p->data.zhiwu,
p->data.gongzi,
p->data.addr,
p->data.tel);
p = p->next;
}
fclose(fp);
}
}
//读取职工信息
void F(Node *worker)
{
Node *p;
FILE *fp;
if ((fp = fopen("职工信息管理系统.txt", "rb")) == NULL)
{
printf("文件不能打开!\n ");
}
p = worker->next;
while (p!=NULL)
{
fscanf(fp, " %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t ",
p->data.jobno,
p->data.name,
p->data.sex,
p->data.birthday,
p->data.degree,
p->data.zhiwu,
p->data.gongzi,
p->data.addr,
p->data.tel);
p=p->next;
}
fclose(fp);
}
//主函数实现
int main()
{
Node *worker;
int flag;
worker = (Node*)malloc(sizeof(Node));
worker->next = NULL;
while(1)
{
printf(" 计科一班 朱博 2067111119\n");
printf("\t职 工 信 息 管 理 系 统\n");
printf("***************菜 单******************\n ");
printf("1.输入职工信息\n ");
printf("2.修改职工信息\n ");
printf("3.浏览职工信息\n ");
printf("4.查询职工信息\n ");
printf("5.删除职工信息\n ");
printf("6.读取职工信息\n ");
printf("0.退出\n ");
printf("************谢谢使用*******************\n");
printf("输入你选择的序号:");
scanf("%d", &flag);
switch (flag)
{
case 0: printf(" \n提示:退出系统!\n ");
break;
case 1: A(worker); G(worker);
break; //添加职工信息,保存到文件中
case 2: B(worker);
break; //修改职工信息
case 3: C(worker);
break; //显示职工信息
case 4: D(worker);
break; //查询职工信息
case 5: E(worker);
break; //删除职工信息
case 6: F(worker);
break; //读取职工信息
default: printf("提示:输入错误!\n ");
}
}
}