C language implements the staff management system
- 2020-06-19 11:29:28
- OfStack
This site found a particularly good staff management system, to share a copy of C language staff management system specific implementation code for your reference, but also thank the user for sharing, the specific content is as follows
person.cpp
#include "person.h"
// Home page
int Print_Head(int * num)
{
printf("\t***********************************************\n");
printf("\t| Staff management system |\n");
printf("\t*---------------------------------------------*\n");
printf("\t| 【 1 】 new 【 2 Revised. |\n");
printf("\t* 【 3 】 the query 【 4 】 exit *\n");
printf("\t***********************************************\n");
printf("\t ◎ Please enter the serial number that you want to operate [ 】 \b\b");
*num=getchar();
return SUCCESS;
}
// Bowdlerize picture
int Print_DelRev(int* num)
{
printf("\t******************************************\n");
printf("\t* *\n");
printf("\t* 【 1 】 delete 【 2 】 to modify 【 3 】 returns *\n");
printf("\t* *\n");
printf("\t******************************************\n");
printf("\t ◎ Please enter the serial number that you want to operate [ 】 \b\b");
*num=getchar();
return SUCCESS;
}
// The query image
int Print_Que(int* num)
{
printf("\t******* ************************************\n");
printf("\t* *\n");
printf("\t* 【 1 All enquiries 【 2 】 Job number query *\n");
printf("\t* *\n");
printf("\t* 【 3 Fuzzy query 【 4 Back to menu *\n");
printf("\t* *\n");
printf("\t******************************************\n");
printf("\t ◎ Please enter the serial number that you want to operate [ 】 \b\b");
*num=getchar();
return SUCCESS;
}
// Increase the picture
int Print_Add(int* num)
{
int n=0;
printf("\t******************************************\n");
printf("\t* *\n");
printf("\t* 【 1 】 new 【 2 added 【 3 】 returns *\n");
printf("\t* *\n");
printf("\t******************************************\n");
printf("\t ◎ Please enter the serial number that you want to operate [ 】 \b\b");
*num=getchar();
return SUCCESS;
}
// header
int Print_Tittle()
{
printf("-------------------------------------------\n");
printf(" Work number | The name | gender | age | The phone \n");
printf("-------------------------------------------\n");
return SUCCESS;
}
// Select the file to open
int File_name()
{
printf("\n\t Please enter the file you want to open :");
//memset(filename,0,sizeof(filename));
if(scanf("%s", filename)!=1){
printf("\a File selection error !");
return FAILED;
}
return SUCCESS;
}
// Generate linked lists, parameters n is add Record the number
struct Employee *Creat() {
printf("\n\t ◎ Please enter the number of data to add :");
int n;
if(scanf("%d", &n)!=1) {
printf("\a error!");
}
struct Employee *head;
struct Employee *p1, *p2;
system("cls");
for(int i=1;i<n+1;i++) {
p1 = (struct Employee*)malloc(SIZE);
Print_Tittle();
scanf("%s%s%s%d%s",p1->num,p1->name,p1->sex,
p1->age,p1->tel);
p1->next = NULL;
if(i==1) {
head = p2 = p1;
}
else {
p2->next = p1;
p2 = p1;
}
}
return(head);
}
// Create a new file
int WriteData_wb(struct Employee *head) {
FILE *fp;
struct Employee *p;
if((fp = fopen(filename, "wb"))==NULL)
printf("\a Error opening file !");
p = head;
while(p!=NULL) {
if(fwrite(p,SIZE,1,fp)!=1) {
printf("\b Error writing data \n");
fclose(fp);
return FAILED;
}
p=p->next;
}
fclose(fp);
return SUCCESS;
}
// Add to an existing file
int WriteData_ab(struct Employee *head) {
FILE *fp;
struct Employee *p;
if((fp = fopen(filename, "ab"))==NULL)
printf("\a Error opening file !");
p = head;
while(p!=NULL) {
if(fwrite(p,SIZE,1,fp)!=1) {
printf("\b Error writing data \n");
fclose(fp);
return FAILED;
}
p=p->next;
}
fclose(fp);
return SUCCESS;
}
// increase
int Emp_Add()
{
system("cls");
getchar();
int add;
while(1){
system("cls");
Print_Add(&add);
while(add!='1' && add!='2' && add!='3') {
putchar('\a');
printf(" ◎ Please re-enter the valid serial number (1~3): 【 】 \b\b");
add=getchar();
}
switch(add){
case '1':
WriteData_wb(Creat());
printf("\n ◎ New file success data has been saved √ \n");
system("pause");
system("cls");
Emp_Add();
break;
case '2':
WriteData_ab(Creat());
printf("\n ◎ Data has been successfully added √ \n");
system("pause");
system("cls");
Emp_Add();
break;
case '3':
system("cls");
getchar();
Emp_Return();
break;
}
}
return SUCCESS;
}
// Read the file's data to the linked list and return it head Pointer to the
struct Employee *Read() {
struct Employee *head = NULL;
struct Employee *p1, *p2;//s = p1;p = p2;
FILE *fp;
if((fp=fopen(filename,"rb+"))==NULL)
{
printf(" Error opening file \n");
exit(0);
}
while(!feof(fp)) {
if((p1=(struct Employee*)malloc(SIZE))==NULL){
printf(" Memory request error \n");
fclose(fp);
exit(0);
}
if(fread(p1,SIZE,1,fp)!=1){
free(p1);
break;
}
if(head==NULL)
head=p2=p1;
else{
p2->next=p1;
p2=p1;
}
}
fclose(fp);
return (head);
}
// delete
int Emp_Del()
{
struct Employee* head;
struct Employee* pt1,*pt2;
char str_num[10];
memset(str_num,0,sizeof(str_num));
printf("\n ◎ Please enter the student id information you want to delete: ");
scanf("%s",str_num);
pt1=Read();
pt2=pt1->next;
head=pt1;
while(pt2!=NULL){
if(!strcmp(pt1->num,str_num)){
WriteData_wb(pt2);
}else if(!strcmp(pt2->num,str_num)){
pt1->next=pt2->next;
WriteData_wb(head);
}
pt2=pt2->next;
pt1=pt1->next;
}
if(pt2!=NULL){
printf("\t ◎ There is no data you want to delete ");
}
return SUCCESS;
}
// Modify the
int Emp_Rev()
{
struct Employee* pt1,*pt2,*head;
char str_num[10];
printf("\t ◎ Please enter the student number information you want to modify: ");
scanf("%s",str_num);
pt1=Read();
pt2=pt1->next;
head=pt1;
while(pt2!=NULL){
if(strcmp(pt1->num,str_num)==0) {
Print_Tittle();
scanf("%s%s%s%d%s",pt1->num,pt1->name,pt1->sex,
pt1->age,pt1->tel);
WriteData_wb(head);
}
else if(strcmp(pt2->num,str_num)==0) {
Print_Tittle();
scanf("%s%s%s%d%s",pt1->num,pt1->name,pt1->sex,
pt1->age,pt1->tel);
WriteData_wb(head);
}
pt2 = pt2->next;
pt1 = pt1->next;
}
if(pt2!=NULL)
printf(" There is no data stored in the database that you want to delete! \n");
return 0;
}
// bowdlerize
int Emp_DelRev()
{
getchar();
int delrev=0;
while(1){
system("cls");
Print_DelRev(&delrev);
while(delrev!='1' && delrev!='2' && delrev!='3'){
putchar('\a');
//getchar();
printf(" Please re-enter the valid serial number (1~3): 【 】 \b\b");
delrev=getchar();
}
switch(delrev){
case '1':
Emp_Del();
printf("\n ◎ The specified data has been deleted successfully !");
system("pause");
getchar();
break;
case '2':
Emp_Rev();
printf("\n The specified data has been successfully modified !");
system("pause");
getchar();
break;
case '3':
system("cls");
getchar();
Emp_Return();
break;
}
}
return SUCCESS;
}
// The overall query
int Emp_QueAll()
{
struct Employee *pt;
pt = Read();
Print_Tittle();
do {
printf("%2s%5s%4s%2d%3s\n",
pt->num,pt->name,pt->sex,pt->age,pt->tel);
pt = pt->next;
}while(pt!=NULL);
printf("\n\n");
return SUCCESS;
}
// Job number query
int Emp_QueNum()
{
struct Employee *pt;
char str_num[10];
printf("\t Please enter the student number you want to check :");
scanf("%s", str_num);
pt = Read();
Print_Tittle();
do {
if(!strcmp(pt->num,str_num)) {
printf("%2s%5s%4s%2d%3s\n",
pt->num,pt->name,pt->sex,pt->age,pt->tel);
printf("\n\n");
return 0;
}
pt = pt->next;
}while(pt!=NULL);
printf("\t There is no data stored in the database that you want to query! \n");
printf("\n\n");
return SUCCESS;
}
// Fuzzy query
int Emp_QueVague()
{
struct Employee *pt;
char str_vague[20];
int m=0;
printf("\t Please enter the key words you want to query :");
scanf("%s", str_vague);
pt = Read();
Print_Tittle();
do {
if(strstr(pt->num,str_vague)!=0||strstr(pt->name,str_vague)!=0
||strstr(pt->sex,str_vague)!=0||strstr(pt->age,str_vague)!=0
||strstr(pt->tel,str_vague)!=0) {
printf("%2s%5s%4s%2d%3s\n",
pt->num,pt->name,pt->sex,pt->age,pt->tel);
m = 1;
}
pt = pt->next;
}while(pt!=NULL);
if(!m)
printf(" There is no data stored in the database that you want to query! \n");
printf("\n\n");
return SUCCESS;
}
// The query
int Emp_Que()
{
system("cls");
int que;
while(1){
system("cls");
Print_Que(&que);
while(que!='1' && que!='2' && que!='3'){
putchar('\a');
printf("\t Please re-enter the valid serial number (1~3): 【 】 \b\b");
que=getchar();
}
switch(que){
case '1':
Emp_QueAll();
system("pause");
getchar();
break;
case '2':
Emp_QueNum();
system("pause");
getchar();
break;
case '3':
Emp_QueVague();
system("pause");
getchar();
break;
case '4':
Emp_Return();
system("pause");
getchar();
break;
}
}
return SUCCESS;
}
// return
int Emp_Return()
{
Emp_Menu();
return SUCCESS;
}
// exit
void Emp_Quit()
{
printf("\n\t ◎ Thanks for using! ");
system("pause");
exit(0);
}
//menu function
int Emp_Menu()
{
//int* Menu=NULL;
int menu=0;
//Print_Head(&Menu);
//menu=*Menu;
//delete Menu;
//printf("%d\n",menu);
Print_Head(&menu);
while(menu!='1' && menu!='2' && menu!='3'&& menu!='4') {
printf("error! please input the right number!\n");
putchar('\a');
//getchar();
printf(" ◎ Please re-enter the valid serial number (1~4): 【 】 \b\b");
menu=getchar();
}
switch(menu){
case '1':
File_name();
Emp_Add();
break;
case '2':
File_name();
Emp_DelRev();
break;
case '3':
File_name();
Emp_Que();
break;
case '4':
Emp_Quit();
break;
}
return SUCCESS;
}
/*void Sig(int n)
{
printf("\n\t ◎ The program will exit, operation has been saved! ");
system("pause");
exit(0);
}*/
int main()
{
//printf("\t When using Ctrl+C Terminates the current program! \n");
//signal(SIGINT,Sig);
Emp_Menu();
return SUCCESS;
}
person.h
#ifndef __PERSON_H__
#define __PERSON_H_
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <signal.h>
#define SUCCESS 0
#define FAILED (!SUCCESS)
#define SIZE sizeof(struct Employee)
// The global variable
int flag=0;// Return to sign
char filename[30];// File name to open
// Employee information structure
struct Employee{
char name[20];
char tel[15];
char sex[5];
char num[10];
char age[3];
struct Employee* next;
};
// To establish 1 A linked list
struct Employee* creat(int n);
// The main function
int Emp_Menu();
// Home page to print
int Print_Head();
// Censored print
int Print_DelRev();
// Add printing
int Print_Add();
// Header to print
int Print_Tittle();
// New file write
int WriteData_wb(struct Employee *head);
// Write to an existing file
int WriteData_ab(struct Employee *head);
// add
int Emp_Add();
// delete
int Emp_Del();
// Modify the
int Emp_Rev();
// The query
int Emp_Que();
// return
int Emp_Return();
// exit
void Emp_Quit();
#endif //__PERSON_H__
For more information, please pay attention to the topic management System Development.