This article shares the design code of C language employee management system for your reference. The specific content is as follows
The code is as follows:
#include<> #include<> #include <> struct Worker { int id;//Work number char name[16];//Name char sex[8];//gender int age;//age char edu_exp[32];//Education int wage;//salary char adress[32];//address char phong[16];//Telephone Worker* next; }; //Create the table headerWorker m_head = { 0 }; //User input informationint user_input(Worker* w) { printf("ID:"); scanf("%d", &w->id); getchar();//Absorb the carriage return characters printf("name:"); gets_s(w->name); printf("sex:"); gets_s(w->sex); printf("age:"); scanf("%d", &w->age); getchar();//Absorb the carriage return characters printf("edu_exp:"); gets_s(w->edu_exp); printf("wage:"); scanf("%d", &w->wage); getchar();//Absorb the carriage return characters printf("adress:"); gets_s(w->adress); printf("phone:"); gets_s(w->phong); return 0; } //Add an objectvoid add(Worker* w) { w->next = m_head.next; m_head.next = w; } //Press to insert objectint insert(Worker* w) { Worker* cur = m_head.next; // Current node Worker* pre = &m_head; // Previous node previously while (cur) { if (w->id < cur->id) // Find this location break; pre = cur; cur = cur->next; // Find the last object } // Insert behind the pre node w->next = pre->next; pre->next = w; return 0; } //Delete the objectint remove(int id) { Worker* cur = m_head.next;//The current node is the first object Worker* pre = &m_head;//The previous node of the current node is the head node, pointing to the first object while (cur) { if (id == cur->id)//Find the node to be deleted { pre->next = cur->next; free(cur);//Delete this node return 1;//Return 1 after successful deletion } pre = cur; cur = cur->next; } return 0; } //Find the objectint find(int id) { Worker* p = m_head.next; while (p) { if (id == p->id) { printf("ID:%d\nName:%s\nSex:%s\nAge:%d\nEdu-exp:%s\nWage:%d\nAdress:%s\nPhone:%s\n", p->id, p->name, p->sex, p->age, p->edu_exp, p->wage, p->adress, p->phong); return 1;//Return 1 after finding the target } p = p->next; } return 0; } //Travelvoid show_all() { Worker* p = m_head.next; if (!p) { printf("No employee information yet!"); return; } printf("Work number, name, gender, age, education, salary, residence address, telephone number\n"); printf("----------------------------------------------------------------\n"); while (p) { printf("%d %s %s %d %s %d %s %s\n", p->id, p->name, p->sex, p->age, p->edu_exp, p->wage, p->adress, p->phong); p = p->next; } } //Save data to the fileint save() { const char* filename = "F:\\"; FILE* fp = fopen(filename, "a"); if (fp == NULL) { printf("can not open the file...."); exit(0); } Worker* p = m_head.next; while (p) { fprintf(fp, "\r"); fprintf(fp, "%d ", p->id); fprintf(fp, "%s ", p->name); fprintf(fp, "%s ", p->sex); fprintf(fp, "%d ", p->age); fprintf(fp, "%s ", p->edu_exp); fprintf(fp, "%d ", p->wage); fprintf(fp, "%s ", p->adress); fprintf(fp, "%s ", p->phong); fprintf(fp, "\t\r\n"); p = p->next; } fclose(fp); return 0; } //Modify the objectvoid rewrite(int id) { Worker* p = m_head.next; while (p) { if (id == p->id) { user_input(p); } p = p->next; } } // Main menuvoid List() { Worker* w = NULL; char key; while (1) { do { system("cls"); printf("*******************************************************\n"); printf("* Main menu operation interface *\n"); printf("* *\n"); printf("* 1. Enter employee information *\n"); printf("* 2. Browse employee information *\n"); printf("* 3. Query employee information *\n"); printf("* 4. Delete employee information *\n"); printf("* 5. Modify employee information *\n"); printf("* 6. Instructions for use *\n"); printf("* 7. Exit *\n"); printf("* *\n"); printf("*******************************************************\n"); key = getchar(); } while (key != '1'&&key != '2'&&key != '3'&&key != '4' &&key != '5'&&key != '6'&&key != '7'); switch (key) { case '1':system("cls"); while (1) { Worker* w = (Worker*)malloc(sizeof(Worker)); user_input(w); insert(w); if (getchar() == 'N') { break; } } save(); free(w); break; case '2':system("cls"); show_all(); system("pause"); break; case '3':system("cls"); if (!m_head.next) { printf("No employee information yet!"); system("pause"); break; } while (1) { int n; printf("---------------------------------\n"); printf("Please enter the ID number you want to find:"); scanf("%d", &n); if (!find(n)) { printf("The employee information with ID number %d cannot be found...\n", n); } char ch = getchar(); if (ch == 'N') { break; } } break; case '4':system("cls"); if (!m_head.next) { printf("No employee information yet!"); system("pause"); break; } while (1) { int n; printf("---------------------------------\n"); printf("Please enter the ID number to be deleted:"); scanf("%d", &n); if (remove(n)) { printf("Successfully deleted employee information with ID number %d.\n", n); } else printf("Cannot delete employee information with ID number %d.\n", n); char ch = getchar(); if (ch == 'N')//Press N to exit { break; } } break; case '5':system("cls");// if (!m_head.next) { printf("No employee information yet!"); system("pause"); break; } while (1) { int n; printf("Please enter the ID number to be modified:\n"); scanf("%d", &n); printf("Please modify:\n"); rewrite(n); if (getchar() == 'N') { break; } } break; case '6':system("cls"); printf("Instructions for use of the employee system: Press the corresponding number to enter the corresponding submenu. If you want to exit, press N\n to start without data, you need to enter first.\n"); system("pause"); break; case '7':system("cls");// return; break; } } } int main() { List(); return 0; }
This is a simple example, mainly to give you some ideas. I just simply write to save the input data into the file. You can also write a reading data from the file to the console, and can modify it through the linked list. This is a little troublesome, but the idea is very simple. Interested students can do better.
Recommended several articles:
C++ implements a simple library management system
C++ implements a simple employee information management system
C++ Basic Student Management System
For more information about the management system, please click"Management System Special Topic"Carry out learning
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.