Examples of this article for you to share the C + + employee Management System Instance code
1. Single Worker's head document
staff.h
#ifndef staff_h_included #define STAFF_H_INCLUDED//struct body to create struct STAFF {char id[10];
Char name[10];
Char sex[10];
int pay;
int reward;
int factpay;
};
Custom structural body typedef struct staff staff;
Individual employee information to create staff createstaff ();
Single worker information output void Displaystaff (staff staff);
Modify employee information void Updatestaff (staff *staff); #endif//staff_h_included CPP file for individual employees staff.cpp #include <stdio.h> #include <stdlib.h> #include "staff.h
"Staff Createstaff () {staff staff;
printf ("-----------ID-----------\ n");
scanf ("%s", staff.id);
printf ("-----------name-----------\ n");
scanf ("%s", staff.name);
printf ("-----------sex-----------\ n");
scanf ("%s", staff.sex);
printf ("-----------pay-----------\ n");
scanf ("%d", &staff.pay);
printf ("-----------reward-----------\ n");
scanf ("%d", &staff.reward);
Staff.factpay = Staff.pay + Staff.reward;
printf ("\ n");
return staff;
} void Displaystaff (staff staff) {printf ("%10s", staff.id); printf ("%10s",Staff.name);
printf ("%10s", staff.sex);
printf ("%10d", Staff.pay);
printf ("%10d", Staff.reward);
printf ("%10d", Staff.factpay);
printf ("\ n");
} void Updatestaff (Staff *staff) {printf ("-----Show the data to be modified--------\ n");
Displaystaff (*staff);
printf ("-------Enter the data to be modified---------");
printf ("-----------pay-----------\ n");
scanf ("%d", &staff->pay);
printf ("-----------reward-----------\ n");
scanf ("%d", &staff->reward);
Staff->factpay = Staff->pay + staff->reward;
printf ("\ n");
}
2. The creation of the linked list
header file for linked list
Linklist.h
Create struct node #ifndef linklist_h_included #define linklist_h_included
#include "staff.h"
//Linked list node
{
struct staff staff;
struct Node *next;
Custom node
typedef struct node node;
typedef struct NODE *linklist;
Create a linked list
node *createlinklist ();
Data
void Displaylinklist (node *head) in the output list;
Find employee
Node *searchnode (node *head, Char id[] by employee number;
Find workers by name
void Searchnodebyname (node *head, char name[]);
Delete worker
void Delenode (linklist head, Char id[]);
Insert worker
void Insertnode (linklist Head, staff staff);
Chain list destroys
void Distroylinklist (linklist head);
#endif//linklist_h_included
Source program created by linked list
Linklist.cpp
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "staff.h" #include "linklist.h" no
De *createlinklist () {node *head, *p;
Head = (node *) malloc (sizeof (node));
Head->next = NULL; Staff a[100] = {"11111", "MMM", "f", 12000, Watts, 14000}, {"22222", "AAA", "M", 13000, 3000, 16000}, {"33 333 "," SSS "," F ", 15000, 3000, 18000}, {" 44444 "," fff "," M ", 17000, 8000, 25000}, {" 55555 "," GGG "," F ", 20
000, 5000, 25000}};
for (int i = 0; i<5; i++) {p = (node *) malloc (sizeof (node));
P->staff = A[i];
P->next = head->next;
Head->next = p;
return head;
} void Displaylinklist (node *head) {linklist p;
p = head->next;
while (P!=null) {displaystaff (p->staff);
p = p->next;
} node *searchnode (node *head, char id[]) {linklist p;
p = head;
while (P!=NULL&&STRCMP (P->next->staff.id, ID)!=0) {p = p->next; Return p->next;
} void Searchnodebyname (node *head, char name[]) {linklist p;
p = head;
while ((P!=null) && (strcmp (p->next)->staff.name, name)!=0)) {p = p->next;
printf ("-----´ëèëîª---------\ n");
printf ("%s", p->next->staff.name);
printf ("\ n");
} void Delenode (linklist head, char id[]) {linklist p;
p = head;
while (p->next&& strcmp (p->next->staff.id, ID)!=0)) {p = p->next;
} if (p->next) {p->next = p->next->next;
else {printf ("=====no found========\n");
} void Insertnode (Linklist Head, staff staff) {linklist p;
p = (node *) malloc (sizeof (node));
P->staff = Staff;
P->next = head->next;
Head->next = p;
} void Distroylinklist (Linklist head) {linklist p;
p = head;
while (p!=null) {p = p->next;
Free (p);
}
}
3. File disk
file.h
#ifndef file_h_included #define file_h_included #include "linklist.h" #include "staff.h"/
The worker information is filed void Saveinformation (Linklist head);
Employee Information loaded void Loadinformation (linklist head); #endif//file_h_included file.cpp #include <stdio.h> #include <string.h> #include <stdlib.h> #include
"File.h" #include "linklist.h" #include "staff.h" void Saveinformation (linklist h) {file *fp;
Linklist p;
if (fp = fopen ("Stu.txt", "w") = = NULL) {printf ("Failure to open stu.txt!\n");
Exit (0);
for (p = h->next; p; p=p->next) {fwrite (& (P->staff), sizeof (node), 1, FP);
Fclose (FP);
} void Loadinformation (Linklist h) {FILE *fp;
Staff Nodebuffer;
if (fp = fopen ("Stu.txt", "r") = = NULL) {printf ("\n\t data file is missing or will load test data for First run");
return;
while (Fread (&nodebuffer, sizeof (node), 1, FP)!=0) {Insertnode (H, Nodebuffer); }
}
4. Main function
mainmeun.cpp
#include <stdio.h> #include <stdlib.h> #include "linklist.h" #include "staff.h" #include "file.h" void Mainme
Un (linklist head);
void Searchmenu (linklist head);
int main (void) {linklist head=null;
int n;
printf ("------Please enter the data you want to save----------\ n");
scanf ("%d", &n);
Head = Createlinklist ();
System ("CLS");
Displaylinklist (head);
Mainmeun (head);
printf ("\ n \ nthe");
Loadinformation (head);
Saveinformation (head);
return 0;
} void Mainmeun (Linklist head) {linklist p;
Char id[10];
Char name[10];
Staff staff;
int selection;
int flag = 1;
Do {printf ("================= Staff Management System ===================\n");
printf ("==========1. List output =====2. Data Query =====\n");
printf ("=======3. Data deletion ===4. Data modification =====5. Add Data ======\n");
printf ("=======6. Linked list destruction ===7. Information save =====8. Discard Disk =====\n");
printf ("==================================================\n");
printf ("Please select the function (1~8):");
scanf ("%d", &selection);
Switch (selection) { Case 1:displaylinklist (head);
Break
Case 2:searchmenu (head);
Break
Case 3:printf ("========= Please enter the work number ==========\n");
scanf ("%s", ID);
Delenode (head, ID);
Break
Case 4:printf ("========= Please enter the work number ==========\n");
scanf ("%s", ID);
p = Searchnode (head, ID);
Updatestaff (& (P->staff));
Break
Case 5:printf ("======== Add Data =========");
Staff = Createstaff ();
Insertnode (head, Staff);
Break
Case 6:distroylinklist (head);
Break
Case 7:loadinformation (head);
Saveinformation (head);
Break
Case 8:flag = 0;
Break
}}while (flag = = 1);
printf ("========bye=====bye======");
} void Searchmenu (Linklist head) {linklist p;
int flag = 1;
Char id[10];
Char name[10];
Do {printf ("========= lookup menu ===========\n");
printf ("===1.id======2.name====3. Exit ====\n"); printf ("=================================\n ");
int selection;
printf ("= = Please select function (1~3):");
scanf ("%d", &selection);
Switch (selection) {Case 1:printf ("===== Please enter id=======\n");
scanf ("%s", ID);
p = Searchnode (head, ID);
Displaystaff (P->staff);
Break
Case 2:printf ("===== Please enter name======\n");
scanf ("%s", name);
Searchnodebyname (head, name);
Break
Case 3:flag = 0;
Break
System ("pause");
System ("CLS");
}while (flag = 1); }
The above is the entire content of this article, I hope to realize the C + + staff management system has helped, inspired.
Recommended several articles:
C + + to achieve a simple library management system
C + + realizes simple staff information management system
C + + basic Student management system