数据结构与算法课程设计——C语言《职员薪资查询系统》

温馨提示:课设要自己去操作,自己写代码,可以借鉴他人代码,学习思路和一些操作,切不可完全抄袭!!!

总体说明:设计一个职员薪资查询系统,要求能录入各职员自身及其工资情况,能读取文件信息、数据的输入、显示、排序、增删查改。
主要功能说明
1 职员信息的录入功能:添加职员信息到链表中然后再保存到文件;
2 职员查询功能:从键盘中输入一个等级/职务/姓名,在已生成的单链表中查询等级为该等级的职员信息,并将其职员信息输出;
3 职员薪资排序功能:将职员的薪资按高到低进行排序并输出;
4 职员信息输出功能;对职员信息进行输出,将其显示在屏幕上;
5 职员信息修改功能:对职员信息进行修改和删除,然后保存到文件中;

职员信息的录入功能
添加职员信息

workList headLinkInsert(workList head)//添加数据到表头
{workNode *p,*s;p=head->next;s=(workList)malloc(sizeof(workNode));s->data=inputOneRecord();s->next=p;head->next=s;return head;
}
void addData(workList head)//添加数据
{int n,i;printf("Please input the number that you want to add:\n");scanf("%d",&n);//添加数据的个数for(i=0; i<n; i++){head=headLinkInsert(head);}
}

录入界面:

void inputMune()//录入界面
{printf("|********************************************|\n");printf("|     1.添加职员信息      2.返回主界面       |\n");printf("|********************************************|\n");
}
void inputData(workList head)//1录入职员信息
{system("cls");inputMune();int option;while(1){printf("Please input you prtion:\n");scanf("%d",&option);switch(option){case 1:addData(head);head=writeInformation(head);//每队链表进行增删改操作时就保存一次break;case 2:muneOperation(head);return;}}
}

职员信息查询功能
在该系统中查询又分为职员等级查询,职员职务查询,职员姓名查询。

等级查询

workList queryPostion(workList head,char str[])//等级(职位)查找
{workNode *p,*q;p=head->next;q=NULL;while(p!=NULL){if(strcmp(p->data.postion,str)==0){q=p;}p=p->next;}return q;
}
void queryPostionData(workList head)//查询等级(职位)
{char str[20];workNode *p;printf("Please input the postion that you want to query:\n");scanf("%s",str);p=queryPostion(head,str);if(p!=NULL){printHeader();outputOneRecord(p->data);}if(p==NULL){printf("The postion is error OR There is not the postion\n");}
}

职务查询

workList queryPost(workList head,char str[])//职务查找
{workNode *p,*q;p=head->next;q=NULL;while(p!=NULL){if(strcmp(p->data.post,str)==0){q=p;}p=p->next;}return q;
}
void queryPostData(workList head)//查询职务
{char str[20];workNode *p;printf("Please input the post that you want to query:\n");scanf("%s",str);p=queryPost(head,str);if(p!=NULL){printHeader();outputOneRecord(p->data);}if(p==NULL){printf("The post is error OR There is not the post\n");}
}

名字查询

workList queryName(workList head,char str[])//名字查找
{workNode *p,*q;p=head->next;q=NULL;while(p!=NULL){if(strcmp(p->data.name,str)==0){q=p;}p=p->next;}return q;
}
void queryNameData(workList head)//查询名字
{char str[20];workNode *p;printf("Please input the name that you want to query:\n");scanf("%s",str);p=queryName(head,str);if(p!=NULL){printHeader();outputOneRecord(p->data);}if(p==NULL){printf("The name is error OR There is not the mane\n");}
}

查询功能界面

void queryMune()//查询界面
{printf("|********************************************|\n");printf("|     1.职员等级查询      2.职员职务查询     |\n");printf("|     3.职员姓名查询      4.返回主界面       |\n");printf("|********************************************|\n");
}
void queryData(workList head)//2查询职员信息
{system("cls");queryMune();int option;while(1){printf("Please input you prtion:\n");scanf("%d",&option);switch(option){case 1:queryPostionData(head);break;case 2:queryPostData(head);break;case 3:queryNameData(head);break;case 4:muneOperation(head);return;}}
}

职员信息修改功能
该功能分为两小功能:1是修改职员信息,2是删除职员信息
1修改职员信息

void reviseOneData(workList head)//修改某个职员的数据,输入需要修改的职员的名字
{char str[20];workNode *p;printf("Please input the name that you want to revise:\n");scanf("%s",str);p=queryName(head,str);if(p!=NULL){p->data=inputOneRecord();printf("已修改!\n");}if(p==NULL){printf("The name is error OR There is not the mane\n");}
}

2删除职员信息

void deleteOneData(workList head)//删除某个职员的信息,输入需要修改的职员的名字
{workNode *p,*q;char str[20];printf("Please input the name that you want to delete:\n");scanf("%s",str);p=head;while(p->next!=NULL){if(strcmp(p->next->data.name,str)==0){q=p->next;p->next=p->next->next;free(q);}p=p->next;}printf("已删除!\n");
}

修改界面:

void reviseMune()//修改界面
{printf("|********************************************|\n");printf("|     1.修改职员信息      2.删除职员信息     |\n");printf("|              3.返回主界面                  |\n");printf("|********************************************|\n");
}
void reviseData(workList head)//5.修改职员信息
{system("cls");reviseMune();int option;while(1){printf("Please input you prtion:\n");scanf("%d",&option);switch(option){case 1:reviseOneData(head);head=writeInformation(head);break;case 2:deleteOneData(head);head=writeInformation(head);break;case 3:muneOperation(head);return;}}
}

职员薪资排序功能
薪资排序功能:

workList salarySort(workList head)//排序
{workNode *q,*p,*tail;tail=NULL;q=head;while((head->next->next)!=tail){p=head->next;q=head;while(p->next!=tail){if(p->data.totalWages < p->next->data.totalWages){q->next=p->next; //交换节点p->next=p->next->next;q->next->next=p;p=q->next;//回退,因为节点的next值已经改变}p=p->next;  //再前进一个节点q=q->next;}tail=p;//记录最后的结点}return head;
}

薪资排序界面:

void sortMune()//薪资排序界面
{printf("|********************************************|\n");printf("|     1.职员薪资排序      2.返回主界面         |\n");printf("|********************************************|\n");
}
void sortData(workList head)//3.职员薪资排序
{system("cls");sortMune();int option;while(1){printf("Please input you prtion:\n");scanf("%d",&option);switch(option){case 1:salaryDataSort(head);break;case 2:muneOperation(head);return;}}
}

职员信息输出功能
输出界面:

void outputMune()//输出界面
{printf("|********************************************|\n");printf("|     1.输出职员信息      2.返回主界面       |\n");printf("|********************************************|\n");
}
void outputData(workList head)//4.输出职员信息
{system("cls");outputMune();int option;while(1){printf("Please input you prtion:\n");scanf("%d",&option);switch(option){case 1:showAllData(head);break;case 2:muneOperation(head);return;}}
}

完整代码

#include<stdio.h>
#include<stdlib.h>
#include<string.h>#define LINE    "|------------|----------------|----------------|-------------|---------|----------------|\n"
#define KEYWORD "|    name    |      post      |     postion    |   basePay   |   day   |   totalWages   |\n"
#define FORMAT "| %8s   |%-15s |%-15s |     %8.2f|      %3d|        %8.2f|\n"
#define DATA data.name,data.post,data.postion,data.basePay,data.day,data.totalWages//单链表  数据域和指针域分开
struct worker//数据域
{char name[20];//名字char post[20];//职务char postion[20] ;//等级(职位)float basePay;//基本工资int day;//出勤(天数)float totalWages;//总工资=基本工资+出勤天数*50+奖金
};
typedef struct workerNode//指针域
{struct worker data;struct workerNode *next;
} workNode,*workList;void muneOperation(workList head);//主界面
void mune();float countToalWage(float basePay,int day)//计算总工资
{float num;float bonus;//奖金为基本工资的30%bonus=basePay*0.3;num=basePay+day*50+bonus;return num;
}struct worker inputOneRecord()//输入职工信息
{struct worker s;printf("Please input the name:\n");//输入名字scanf("%s",s.name);getchar();printf("Please input the post:\n");//输入职务scanf("%s",s.post);getchar();printf("Please input the postion:\n");//输入等级(职位)scanf("%s",s.postion);getchar();printf("Please input the basePay:\n");//输入基本工资scanf("%f",&s.basePay);getchar();printf("Please input the day:\n");//输入出勤天数scanf("%d",&s.day);getchar();s.totalWages=countToalWage(s.basePay,s.day);//计算总工资return s;
}void outputOneRecord(struct worker data)//输出数据
{printf(FORMAT,DATA);printf(LINE);
}
void printHeader()//输出表头
{printf(LINE);printf(KEYWORD);printf(LINE);
}
void exportData(workList head)//遍历
{workNode *p;p= head->next;while(p){outputOneRecord(p->data);p=p->next;}
}
void showAllData(workList head)//输出所有数据
{printHeader();exportData(head);
}
workList readInformation(workList head)//从文件中读取数据并建立链表
{FILE *fp;struct worker temp;//定义一个临时变量用来存储从文件中读取的数据fp=fopen("c:\\课程设计\\职员薪资查询系统.txt","rb");//二进制读取文件rewind(fp);//将文件内部的位置指针重新指向文件的开头if(fp==NULL){printf("Error:can't open the file!\n");exit(0);}workNode *p,*q;head=NULL;head=(workNode *)malloc(sizeof(workNode));q=head;while(fread(&temp,sizeof(struct worker),1,fp))//尾插法建立链表并从文件中读取数据{p=(workNode *)malloc(sizeof(workNode));p->data=temp;p->next=NULL;q->next=p;q=p;}rewind(fp);fclose(fp);return head;
}
workList writeInformation(workList head)//保存文件
{FILE *fp;fp=fopen("c:\\课程设计\\职员薪资查询系统.txt","wb");if(fp==NULL){printf("Error:can't open the file!\n");exit(0);}workList p;p=head->next;while(p!=NULL)//将链表中的数据一个一个存到文件中{fwrite(&(p->data),sizeof(struct worker),1,fp);p=p->next;}return head;
}void inputMune()//录入界面
{printf("|********************************************|\n");printf("|     1.添加职员信息      2.返回主界面       |\n");printf("|********************************************|\n");
}
workList headLinkInsert(workList head)//添加数据到表头
{workNode *p,*s;p=head->next;s=(workList)malloc(sizeof(workNode));s->data=inputOneRecord();s->next=p;head->next=s;return head;
}
void addData(workList head)//添加数据
{int n,i;printf("Please input the number that you want to add:\n");scanf("%d",&n);//添加数据的个数for(i=0; i<n; i++){head=headLinkInsert(head);}
}
void inputData(workList head)//1录入职员信息
{system("cls");inputMune();int option;while(1){printf("Please input you prtion:\n");scanf("%d",&option);switch(option){case 1:addData(head);head=writeInformation(head);//每队链表进行增删改操作时就保存一次break;case 2:muneOperation(head);return;}}
}
void queryMune()//查询界面
{printf("|********************************************|\n");printf("|     1.职员等级查询      2.职员职务查询     |\n");printf("|     3.职员姓名查询      4.返回主界面       |\n");printf("|********************************************|\n");
}
workList queryPostion(workList head,char str[])//等级(职位)查找
{workNode *p,*q;p=head->next;q=NULL;while(p!=NULL){if(strcmp(p->data.postion,str)==0){q=p;}p=p->next;}return q;
}
void queryPostionData(workList head)//查询等级(职位)
{char str[20];workNode *p;printf("Please input the postion that you want to query:\n");scanf("%s",str);p=queryPostion(head,str);if(p!=NULL){printHeader();outputOneRecord(p->data);}if(p==NULL){printf("The postion is error OR There is not the postion\n");}
}
workList queryPost(workList head,char str[])//职务查找
{workNode *p,*q;p=head->next;q=NULL;while(p!=NULL){if(strcmp(p->data.post,str)==0){q=p;}p=p->next;}return q;
}
void queryPostData(workList head)//查询等级(职位)
{char str[20];workNode *p;printf("Please input the post that you want to query:\n");scanf("%s",str);p=queryPost(head,str);if(p!=NULL){printHeader();outputOneRecord(p->data);}if(p==NULL){printf("The post is error OR There is not the post\n");}
}
workList queryName(workList head,char str[])//名字查找
{workNode *p,*q;p=head->next;q=NULL;while(p!=NULL){if(strcmp(p->data.name,str)==0){q=p;}p=p->next;}return q;
}
void queryNameData(workList head)//查询名字
{char str[20];workNode *p;printf("Please input the name that you want to query:\n");scanf("%s",str);p=queryName(head,str);if(p!=NULL){printHeader();outputOneRecord(p->data);}if(p==NULL){printf("The name is error OR There is not the mane\n");}
}
void queryData(workList head)//2查询职员信息
{system("cls");queryMune();int option;while(1){printf("Please input you prtion:\n");scanf("%d",&option);switch(option){case 1:queryPostionData(head);break;case 2:queryPostData(head);break;case 3:queryNameData(head);break;case 4:muneOperation(head);return;}}
}void sortMune()//薪资排序界面
{printf("|********************************************|\n");printf("|     1.职员薪资排序      2.返回主界面       |\n");printf("|********************************************|\n");
}
workList salarySort(workList head)//排序
{workNode *q,*p,*tail;tail=NULL;//tail指向链表的最后节点q=head;while((head->next->next)!=tail)//控制循环次数{p=head->next;q=head;while(p->next!=tail){if(p->data.totalWages < p->next->data.totalWages){q->next=p->next; //交换节点p->next=p->next->next;q->next->next=p;p=q->next;//回退,因为节点的next值已经改变}p=p->next;q=q->next;}tail=p;//记录最后的结点}return head;
}
void salaryDataSort(workList head)
{head=salarySort(head);showAllData(head);
}
void sortData(workList head)//3.职员薪资排序
{system("cls");sortMune();int option;while(1){printf("Please input you prtion:\n");scanf("%d",&option);switch(option){case 1:salaryDataSort(head);break;case 2:muneOperation(head);return;}}
}
void outputMune()//输出界面
{printf("|********************************************|\n");printf("|     1.输出职员信息      2.返回主界面       |\n");printf("|********************************************|\n");
}
void outputData(workList head)//4.输出职员信息
{system("cls");outputMune();int option;while(1){printf("Please input you prtion:\n");scanf("%d",&option);switch(option){case 1:showAllData(head);break;case 2:muneOperation(head);return;}}
}void reviseMune()//修改界面
{printf("|********************************************|\n");printf("|     1.修改职员信息      2.删除职员信息     |\n");printf("|              3.返回主界面                  |\n");printf("|********************************************|\n");
}
void reviseOneData(workList head)//修改某个职员的数据,输入需要修改的职员的名字
{char str[20];workNode *p;printf("Please input the name that you want to revise:\n");scanf("%s",str);p=queryName(head,str);if(p!=NULL){p->data=inputOneRecord();printf("已修改!\n");}if(p==NULL){printf("The name is error OR There is not the mane\n");}
}
void deleteOneData(workList head)//删除某个职员的信息,输入需要修改的职员的名字
{workNode *p,*q;char str[20];printf("Please input the name that you want to delete:\n");scanf("%s",str);p=head;while(p->next!=NULL){if(strcmp(p->next->data.name,str)==0){q=p->next;p->next=p->next->next;free(q);}p=p->next;}printf("已删除!\n");
}
void reviseData(workList head)//5.修改职员信息
{system("cls");reviseMune();int option;while(1){printf("Please input you prtion:\n");scanf("%d",&option);switch(option){case 1:reviseOneData(head);head=writeInformation(head);break;case 2:deleteOneData(head);head=writeInformation(head);break;case 3:muneOperation(head);return;}}
}void mune()
{printf("|********************************************|\n");printf("|     1.录入职员信息      2.查询职员信息     |\n");printf("|     3.职员薪资排序      4.输出职员信息     |\n");printf("|     5.修改职员信息      6.退出查询系统     |\n");printf("|********************************************|\n");
}void muneOperation(workList head)//主界面
{int option;system("cls");mune();printf("Please input you option:\n");scanf("%d",&option);switch(option){case 1:inputData(head);break;case 2:queryData(head);break;case 3:sortData(head);break;case 4:outputData(head);break;case 5:reviseData(head);break;case 6:return;}
}int main()
{workList head;head=readInformation(head);muneOperation(head);return 0;
}

数据结构与算法课程设计——C语言《职员薪资查询系统》相关推荐

  1. 数据结构与算法课程设计C语言之体育器材管理系统

    #include <stdio.h> #include <stdlib.h> #include <string.h>//单链表数据类型/ typedef struc ...

  2. 数据结构c语言程序设计报告,数据结构与算法课程设计报告模版.doc

    数据结构与算法课程设计报告模版.doc 数据结构与算法课程设计报告题 目本科生导师制问题与家族关系查询系统院 (系) 信息科学与工程 专业班级 计算机应用技术1301班 学生姓名 顾 泉 学 号 20 ...

  3. 数据结构与算法课程设计之五子棋(人机)

    数据结构与算法课程设计之五子棋(人机) 五子棋是全国智力运动会竞技项目之一,是一种两人对弈的纯策略型棋类游戏.通常双方分别使用黑白两色的棋子,下在棋盘直线与横线的交叉点上,先形成五子连线者获胜. 这是 ...

  4. 数据结构与算法课程设计大作业

    考   核   要  求 课程编号:400802010    课程名称:数据结构与算法课程设计考试形式:大作业 大作业1-9见我的下载 里面包含多个版本的设计 文件有cpp文件设计文档总结等 一.设计 ...

  5. 数据结构计算机专业教学计划编制,数据结构与算法课程设计报告--教学计划编制...

    数据结构与算法课程设计报告--教学计划编制 数据结构与算法课程设计报告题目教学计划编制目录一.需求分析311系统概述3111研究背景3112研究意义及目的312具体分析4121功能需求分析4122运行 ...

  6. 数据结构与算法课程设计

     基于c语言的数据结构课程设计 选题:二手车信息管理系统 课程设计要求如下: 1.每人选择一个题目,独立完成(可以自拟,题目不得重复) 2.课程设计要求必须用到数据结构,即线性存储或非线性存储.必须用 ...

  7. 【无标题】数据结构与算法课程设计公园导游图

    目    录                          1 需求分析........................................................ 1 1.1 ...

  8. 银行家算法课程设计java语言_Java语言的银行家算法

    <Java语言的银行家算法>由会员分享,可在线阅读,更多相关<Java语言的银行家算法(12页珍藏版)>请在人人文库网上搜索. 1.湖北中医学院信息技术系 操作系统课程设计操作 ...

  9. 数据结构与算法 课程设计报告——学生信息管理系统

    一.概述 1.开发背景 使用计算机对学生信息进行管理,拥有手工管理所无法比拟的优点.例如:检索迅速.查找方便.可靠性高.存储量大.成本低等.这些优点能够极大地提高学生信息的效率,也是管理科学化.正规化 ...

最新文章

  1. python算法集合_python – 一个集合联合查找算法
  2. 一步一步教你启用WP2.6 Turbo功能
  3. 通信系统之信道(一)
  4. zend framework2 入门实例代码album模型
  5. 新年来了,上海求职,路过看看
  6. python 第13天作业
  7. 云计算学习(5-1)云平台产品介绍-华为的FusionCloud产品
  8. Live Performer for Mac(音频演奏录制软件)v1.0.1
  9. python段落注释的语法格式是_Python 基础语法
  10. 黑马程序员 HTML基础
  11. 数据挖掘之数据仓库详述
  12. 小米便签源码分析——tool包
  13. dw中html5快捷键,Adobe Dreamweaver(dw)常用快捷键--系统之家
  14. 90后程序英雄季逸超
  15. python excel截图保存_如何用Python读取Excel中图片?又如何用Python往Excel中写入图片?...
  16. 针对Windows10下EPLAN2.7频繁重启的解决办法
  17. route add命令详解
  18. 使用nginx配置一个ip对应多个域名
  19. 他律是为了更好的自律
  20. 10分钟掌握2000年历史,秦朝到清朝皇帝世系表,一目了然

热门文章

  1. 期货价格怎么算出来的?
  2. matlab怎么画两个自变量的图_关系图怎么画?一款实用的绘制关系图设计软件
  3. 修复Cena万能头文件无法评测的问题
  4. 级数的定义及敛散性的证明
  5. 1179:最小公倍数和最大公约数
  6. CF-1143D. The Beatles
  7. 鲁棒优化入门(三)——鲁棒优化工具箱RSOME快速上手与应用实例
  8. CDR-jetson-docker镜像使用及测试教程
  9. 虚拟机不能识别本地镜像
  10. 解决百度地图多个标注覆盖不能响应点击的问题