当前位置:网站首页>How to use C language to realize simple employee information management system
How to use C language to realize simple employee information management system
2022-07-23 08:03:00 【Yisu cloud】
How to use C Language implementation of a simple staff information management system
Today, I'd like to share with you how to use C Language implementation of simple staff information management system related knowledge points , Detailed content , Clear logic , I believe most people still know too much about this knowledge , So share this article for your reference , I hope you will gain something after reading this article , Now let's take a look .
The code implementation is as follows :
#include <stdio.h>// Input 、 Output instruction #include <malloc.h>// Dynamic allocation in memory size Byte storage area #include <string.h>// String related operation instructions #include <stdlib.h>// Five types 、 Some macros and general utility functions #include<conio.h>// Corresponding operation generated by keyboard #include <MEMORY.H>// Store access header file typedef struct node{ char name[20]; int age; int worktime; char sex[20]; char marrige[20]; int grade; char tired[20]; struct node *next;}STU;void output(STU *head);STU *Create();STU *findByName(STU *head,char *name);STU *findByWorktime(STU *head,int worktime);STU *findByGrade(STU *head,int grade);void find(STU *head);STU *insert(STU *head);STU *findByNumEx(STU *head,char num[],STU **ppbefore);STU *del(STU *head);void update(STU *head);void sort(STU *head);void save_info(STU *head);void copy();STU *load_info();char *password();void main(){ char *p; int i,n=0; char a[40]; printf(" \t\t******* Welcome to the employee information management system ********\n\n"); printf(" \t\t please input password :\n"); printf(" \t\t----------:\n"); for(i=0;i<3;i++) { n=n+1; printf(" \t\t The first %d Time input :",i+1); p=password(); if(p!=NULL) { STU *head; int choice; int n; head=NULL; printf("\n \t\t You are a legal user !\n\n"); for (i = 0; i < 0x7FFFFFF; i++); for (i = 0; i < 0x7FFFFFF; i++); for (i = 0; i < 0x7FFFFFF; i++); system("cls"); for(;;) { system("cls"); printf(" \t\t******* Employee information management system ********\n"); printf(" \t\t* 1. Enter employee information *\n"); printf(" \t\t* 2. Display all employee information *\n"); printf(" \t\t* 3. Query employee information *\n"); printf(" \t\t* 4. New employee information *\n"); printf(" \t\t* 5. Delete employee information *\n"); printf(" \t\t* 6. Modify employee information *\n"); printf(" \t\t* 7. Sort employee information *\n"); printf(" \t\t* 8. Save the current information to a file *\n"); printf(" \t\t* 9. Back up information to file *\n"); printf(" \t\t* 10. Load employee information from file *\n"); printf(" \t\t* 0. Exit the system *\n"); printf(" \t\t*******************************\n"); printf(" \t\t Please select (0-9):"); scanf("%d",&choice); if(choice==0) break; switch(choice) { case 1: head=Create(); break; case 2: output(head);break; case 3:find(head);break; case 4: head=insert(head); break; case 5: head=del(head); break; case 6: update(head);break; case 7: sort(head);break; case 8: save_info(head);break; case 9: copy();break; case 10:head=load_info();break; } printf(" Press any key to continue ...."); getch(); } printf(" \t\t Thank you for using , bye !\n"); break; } else { printf("\n \t\t You are an illegal user !\n\n"); if(n==3) printf(" \t\t Your wrong password times exceed 3 Time , Program closed !\n"); } }}STU *Create(){ STU *head,*pnew,*pend; head=NULL; printf(" Enter employee information :\n full name \t Age \t Working years \t Gender \t marriage \t Level \t Whether or not he is on the job \n"); for(;;) { pnew=(STU *)malloc(sizeof(STU)); scanf("%s",pnew->name); if(strcmp(pnew->name,"0")==0) { printf(" Employee information is entered \n"); break; } scanf("%d%d%s%s%d%s",&pnew->age,&pnew->worktime,pnew->sex,pnew->marrige,&pnew->grade,pnew->tired); pnew->next=NULL; if(head==NULL){ head=pnew; pend=pnew; } else{ pend->next=pnew; pend=pend->next; } } return head;}void output(STU *head){ STU *p; printf(" The employee information is as follows :\n full name \t Age \t Working years \t Gender \t marriage \t Level \t Whether or not he is on the job \n"); for(p=head;p!=NULL;p=p->next) printf("%s\t%d\t%d\t%s\t%s\t%d\t%s\n",p->name,p->age,p->worktime,p->sex,p->marrige,p->grade,p->tired);}void find(STU *head){ STU *p; char name[20]; int worktime,grade,i; int choice; system("cls");for(;;) { system("cls"); printf(" \t\t******* Employee information inquiry system ********\n"); printf(" \t\t* 1. Search by employee name *\n"); printf(" \t\t* 2. Search by length of service *\n"); printf(" \t\t* 3. Search by employee level *\n"); printf(" \t\t* 0. Exit the system *\n"); printf(" \t\t*******************************\n"); printf(" \t\t Please select (0-3):"); scanf("%d",&choice); if(choice==0) break; switch(choice) { case 1: printf(" Please enter the employee name :"); scanf("%s",name); p=findByName(head,name);break; case 2: printf(" Please enter the length of service :"); scanf("%d",&worktime); p=findByWorktime(head,worktime);break; case 3: printf(" Please enter employee level :"); scanf("%d",&grade); p=findByGrade(head,grade);break; } if(p==NULL) { printf(" There is no information related to this employee !\a\n"); } else { if(choice==1) { printf(" The employee information is as follows :\n full name \t Age \t Working years \t Gender \t marriage \t Level \t Whether or not he is on the job \n"); for(p=head;p!=NULL;p=p->next) { if(strcmp(p->name,name)==0) printf("%s\t%d\t%d\t%s\t%s\t%d\t%s\n",p->name,p->age,p->worktime,p->sex,p->marrige,p->grade,p->tired); } } else if(choice==2) { printf(" The employee information is as follows :\n full name \t Age \t Working years \t Gender \t marriage \t Level \t Whether or not he is on the job \n"); for(p=head;p!=NULL;p=p->next) { if(p->worktime==worktime) printf("%s\t%d\t%d\t%s\t%s\t%d\t%s\n",p->name,p->age,p->worktime,p->sex,p->marrige,p->grade,p->tired); } } else if(choice==3) { printf(" The employee information is as follows :\n full name \t Age \t Working years \t Gender \t marriage \t Level \t Whether or not he is on the job \n"); for(p=head;p!=NULL;p=p->next) { if(p->grade==grade) printf("%s\t%d\t%d\t%s\t%s\t%d\t%s\n",p->name,p->age,p->worktime,p->sex,p->marrige,p->grade,p->tired); } } } printf(" Press any key to continue ...."); getch();}printf(" \t\t You have exited the inquiry system \n\n");}STU *findByName(STU *head,char *name){ STU *p,*result=NULL; for(p=head;p!=NULL;p=p->next) if(strcmp(p->name,name)==0) { result=p; break; }return result;}STU *findByWorktime(STU *head,int worktime){ STU *p,*result=NULL; for(p=head;p!=NULL;p=p->next) if(p->worktime==worktime) { result=p; break; }return result;}STU *findByGrade(STU *head,int grade){ STU *p,*result=NULL; for(p=head;p!=NULL;p=p->next) if(p->grade==grade) { result=p; break; } return result;}STU *insert(STU *head){ STU *pnew,*pcur,*pbefore,*p; int choice; printf(" Enter employee information :\n"); for(;;) { //1. Apply for a new node and assign a value pnew=(STU *)malloc(sizeof(STU)); printf(" The employee information is as follows :\n full name \t Age \t Working years \t Gender \t marriage \t Level \t Whether or not he is on the job \n"); scanf("%s%d%d%s%s%d%s",pnew->name,&pnew->age,&pnew->worktime,pnew->sex,pnew->marrige,&pnew->grade,pnew->tired); pnew->next=NULL; //2. Insert the new node into the linked list // If the list is empty , And just insert ; If the list is not empty , Then find the location , Then insert if(head==NULL) { head=pnew; } else { pcur=NULL; for(p=head;p!=NULL;pbefore=p,p=p->next) if(strcmp(p->name,pnew->name)==1) { pcur=p; break; } // After finding , Judge pcur Is it empty , // if pcur It's empty , be pnew The node should be inserted at the end of the linked list if(pcur==NULL) { pbefore->next=pnew; } // if pcur Non empty , be pnew The node should be inserted into pcur Before ,pbefore after , here , There are two more cases : //pcur It points to the first node , perhaps pcur Point to subsequent nodes ; else { if(pcur==head) { pnew->next=pcur; head=pnew; } else { pnew->next=pcur; pbefore->next=pnew; } } } printf(" Please select : Press 1 Continue to add -> Press 0 End adding \n"); printf("choice="); scanf("%d",&choice); if(choice==0) { printf(" Information added !\n"); break; } } return head;}STU *del(STU *head){ STU *presult,*pbefore; char name[20]; printf(" Employee information to be deleted :"); scanf("%s",&name); presult=findByNumEx(head,name,&pbefore); if(presult!=NULL) { printf(" eureka ! The employee information is as follows :\n full name \t Age \t Working years \t Gender \t marriage \t Level \t Whether or not he is on the job \n"); printf("%s\t%d\t%d\t%s\t%s\t%d\t%s\n",presult->name,presult->age,presult->worktime,presult->sex,presult->marrige,presult->grade,presult->tired); if(presult==head) { head=presult->next; } else { pbefore->next=presult->next; } printf(" Delete successful ---> "); } else printf(" There is no information related to this employee \a\a\n"); return head;}// Function description :// stay head In the linked list pointed to , Look up the student ID as num The node of // After finding , Returns two values : Pointer to the current node presult, Pointer to the previous node of the current node pbefore,// presult Return by function return value ( namely return),pbefore Through output type parameters ppBefore return STU *findByNumEx(STU *head,char name[],STU **ppbefore){ STU *p,*presult=NULL,*pbefore=NULL; for(p=head;p!=NULL;pbefore=p,p=p->next) if(strcmp(p->name,name)==0) { presult=p; break; } if(p==NULL) pbefore=NULL; *ppbefore=pbefore; return presult;}void update(STU *head){ STU *presult; char name[20]; printf(" Enter the name of the employee to be modified :\n"); scanf("%s",name); presult=findByName(head,name); if(presult==NULL) printf(" Check no one ! Can't modify !\a\n"); else { printf(" eureka ! The employee information is as follows :\n full name \t Age \t Working years \t Gender \t marriage \t Level \t Whether or not he is on the job \n"); printf("%s\t%d\t%d\t%s\t%s\t%d\t%s\n",presult->name,presult->age,presult->worktime,presult->sex,presult->marrige,presult->grade,presult->tired); printf(" Please enter modification information :\n"); printf(" full name \t Age \t Working years \t Gender \t marriage \t Level \t Whether or not he is on the job \n"); scanf("%s%d%d%s%s%d%s",presult->name,&presult->age,&presult->worktime,presult->sex,presult->marrige,&presult->grade,presult->tired); printf(" The modification is complete ---> "); }}void sort(STU *head)// Sort by level { STU *pi,*pj,*pindex,*p; STU temp; int len=sizeof(STU)-sizeof(STU *); int i,j,n=0; for(p=head;p!=NULL;p=p->next) n++; for(pi=head,i=0;i<n-1;i++,pi=pi->next){ pindex=pi; for(pj=pi->next,j=i+1;j<n;j++,pj=pj->next) if(pindex->grade> pj->grade) pindex=pj; memcpy(&temp,pi,len); memcpy(pi,pindex,len); memcpy(pindex,&temp,len); } printf(" Sorting complete ---> ");}void save_info(STU *head){ char filename[20]; FILE *fp; STU *p; printf(" Process of saving current information to file \n"); printf(" Please enter filename :"); scanf("%s",filename); if((fp=fopen(filename,"w"))==NULL) { printf(" Can't open file \n"); return; } fprintf(fp," The information of all employees is as follows :\n full name \t Age \t Working years \t Gender \t marriage \t Level \t Whether or not he is on the job \n"); for(p=head;p!=NULL;p=p->next) fprintf(fp,"%s\t%d\t%d\t%s\t%s\t%d\t%s\n",p->name,p->age,p->worktime,p->sex,p->marrige,p->grade,p->tired); fprintf(fp,"%d",0); fclose(fp); printf(" Save complete !--->");}void copy(){ FILE *in,*out; char infile[40],ch; char outfile[40]; printf(" Now enter the backup of student information file \n"); printf(" The source file name :"); scanf("%s",infile); printf(" Backup filename :"); scanf("%s",outfile); if((in=fopen(infile,"r"))==NULL) { printf(" The file could not be opened \n"); exit(0); } if((out=fopen(outfile,"w"))==NULL) { printf(" The file could not be opened \n"); exit(0); } ch=fgetc(in); while(ch!=EOF) { fputc(ch,out); ch=fgetc(in); } fclose(in); fclose(out); printf(" Backup success !\n");}STU *load_info(){ STU *head=NULL,*pnew,*pend; char filename[20]; char a[20]; FILE *fp; int i; printf(" \t\t File loading employee information , Input file name :"); scanf("%s",filename); if((fp=fopen(filename,"r"))==NULL) { printf(" \t\t Loading failed !\n"); exit(0); } for(i=0;i<8;i++) fscanf(fp,"%s",a); for(;;) { pnew=(STU *)malloc(sizeof(STU)); fscanf(fp,"%s",&pnew->name); if(strcmp(pnew->name,"0")==0) break; fscanf(fp,"%d%d%s%s%d%s",&pnew->age,&pnew->worktime,&pnew->sex,&pnew->marrige,&pnew->grade,&pnew->tired); pnew->next=NULL; if(head==NULL) { head=pnew; pend=pnew; } else { pend->next=pnew; pend=pnew; } } fclose(fp); printf(" \t\t Loading successful !\n"); return head;}char *password(){ char password[100],c; char *result=NULL; int e,count; e=0;count=0; while((c=getch())!=13&&e<100)//13 For carriage return { if(c==8&&e>0)//8 Back off { password[e--]='\0';// Delete the last one , And the counter decreases 1 printf("\b \b");// Backspace } else { password[e++]=c; printf("*");// Cover * Number , When the output space covers the previous character , Move forward again , So that the next time you enter } } password[e]='\0'; if(strcmp(password,"123456")==0) result=1; return result;}Program running effect

That's all “ How to use C Language implementation of a simple staff information management system ” All the content of this article , Thank you for reading ! I believe you will gain a lot after reading this article , Xiaobian will update different knowledge for you every day , If you want to learn more , Please pay attention to the Yisu cloud industry information channel .
边栏推荐
猜你喜欢

Storage structure and method of graph (I)

二冲程发动机均值模型仿真

ASP. Net core creates MVC projects and uploads multiple files (streaming)

直播预告 | 开源安全治理模型和工具直播研讨会

Fastapi learning (II) -- fastapi+jinjia2 template rendering web page (jump back to the rendering page)

大咖访谈 | 开源社区里各种奇怪的现状——夜天之书陈梓立tison

Can PHP split arrays

Worthington羟基类固醇脱氢酶技术说明及测定方案

Worthington对肝细胞分离系统的测试及相关优化方案

不会吧?钉钉都下载了,你还不知道可以这样玩?
随机推荐
Experiment 4 DPCM
毕业设计-----基于STM32的物联网环境检测系统
Talking about performance optimization: analysis and optimization of APP startup process
VMware virtual machine changes static IP and hostname, and uses xshell to connect
SQL报错盲注实例分析
Mysql A left(right) join B on A.id=B.id and A.age=1与A left(right) join B on A.id=B.id where A.age=1
C voice realizes TCP client and TCP server, and QT call test
实验二 YUV
Scala learning -- six uses of generics [t]
大咖访谈 | 开源社区里各种奇怪的现状——夜天之书陈梓立tison
Worthington对肝细胞分离系统的测试及相关优化方案
Scala when used Performance problems of contains().Exists()
如何用C语言实现简单职工信息管理系统
Building a sylixos environment in VMWare
自定义flink es source
matlab simulink 磷酸铁锂电池仿真
It can't be true? Nailing has been downloaded. Don't you know you can play like this?
微信小程序项目实战
1.11 ArrayList & student management system
算法面试高频题解指南【一】