Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C language linked list to realize wage Management system

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to use C language linked list to realize the salary management system". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Topic: establish a salary management system to manage the relevant information of employees' wages. Employee salary related information includes employee's job number, employee's name, month, monthly salary and annual total salary, etc. The specific requirements are as follows

1. Establish the storage structure of the system.

2. Enter the monthly wages of the employees

3. Find out the monthly salary of an employee.

4. Modify the monthly salary of an employee

5. Delete the salary-related information of each employee.

6. Count the total annual salary of a certain employee

7. Rank the monthly salary or the total annual salary of the employees

Source code # include # include # include typedef struct worker {char no [12]; / / employee ID char name [40]; / / name int month [12]; / / month float gz [12]; / / monthly salary float total; / / Annual total salary struct worker * next; / / pointer to the next node} Worker / / related function declaration Worker * CreateList (Worker * L, int n); / / batch create node void DeleteList (Worker * L, char n []) based on the number of employees entered; / / delete node void LIstSearch (Worker * L, char n []); / / find employee wage information void InsertInfo (Worker * L) / insert employee salary information void SearchMonthSalary (Worker * L, char n [], int m); / find the monthly salary void Input (Worker * p, int I) of an employee; / / assign void Print (Worker * L) to the data field of the node / output the data of the entire linked list void Modify (Worker * L, char n [], int m, float s); / / modify an employee's salary void menu (); / / the menu void Save of the payroll management system (Worker * L) / / Save the salary information of employees to the file void Bubble_sort (Worker * L); / / Bubble sort to sort the linked list nodes void StatiTotal (Worker * Ljingchar n []) / / Statistics of the total annual salary of an employee / / according to the number of employees entered, the batch creation node Worker * CreateList (Worker * L, int n) / / n is the input number of workers {int i; for (I = 0; I)

< n; i++) { Worker *p; //将新生成的节点插入到链表中 p = NULL; p = (Worker *)malloc(sizeof(Worker)); Input(p, i); //为节点的数据域赋值 p->

Next = L-> next; L-> next = p;} return L;} void DeleteList (Worker * L, char n []) / / Delete employee information by name {int i; Worker * p = L-> next, * pre = L / / defines the point of the p pointer to the header node, defines that pre points to the header node, and pre always points to p's precursor node if (p = = NULL) printf ("data is empty and cannot be deleted!") ; else {while (strcmp (p-> name, n)! = 0) {pre = p; p = pre- > next; if (p = = NULL) {printf ("No relevant information was found and cannot be deleted\ n"); return }} pre- > next = p-> next; free (p); printf ("deleted successfully");}} / / insert employee wage information void InsertInfo (Worker * L) {int j, k; Worker * p = NULL; p = (Worker *) malloc (sizeof (Worker)); / / generate a new node p-> total = 0 Printf ("Please enter the employee's work number:"); scanf ("% s", & p-> no); printf ("Please enter the name of the employee to be inserted:"); scanf ("% s", & p-> name); for (k = 0, j = 1; j month [k] = j; printf ("Please enter the monthly salary of the employee to be inserted (separated by a space):") For (j = 0; j)

< 12; j++) { scanf("%f", &p->

Gz [j]); / enter monthly salary p-> total + = p-> gz [j]; / / calculate the total salary} p-> next = L-> next; L-> next = p; printf ("insert successfully!");} void LIstSearch (Worker * L, char n []) {int i; Worker * p = L-> next While (p! = NULL) {if (strcmp (p-> name, n) = 0) {printf ("\ nThe salary information of the employee is as follows:\ n"); printf ("employee number:"); printf ("% s\ t\ n", p-> no); printf ("name:") Printf ("% s\ n", p-> name); printf ("the worker's monthly salary for 12 months is as follows:"); for (I = 0; I

< 12; i++) printf("%.2f ", p->

Gz [I]); printf ("\ nThe employee's total annual salary is:"); printf ("% .2f", p-> total); printf ("\ n\ n"); printf ("\ n"); p = p-> next;} else p = p-> next }} void SearchMonthSalary (Worker * L, char n [], int m) {int i; Worker * p = L-> next While (p! = NULL) {if (strcmp (p-> name, n) = = 0) {switch (m) {case 1: printf ("the worker's% d-month salary is% .2f", p-> month [0], p-> gz [0]); break Case 2: printf ("the worker's% d-month salary is% .2f", p-> month [1], p-> gz [1]); break; case 3: printf ("the worker's% d-month salary is% .2f", p-> month [2], p-> gz [2]); break Case 4: printf ("the worker's% d-month salary is% .2f", p-> month [3], p-> gz [3]); break; case 5: printf ("the worker's% d-month salary is% .2f", p-> month [4], p-> gz [4]); break Case 6: printf ("the worker's% d-month salary is% .2f", p-> month [5], p-> gz [5]); break; case 7: printf ("the worker's% d-month salary is% .2f", p-> month [6], p-> gz [6]); break Case 8: printf ("the worker's% d-month salary is% .2f", p-> month [7], p-> gz [7]); break; case 9: printf ("the worker's% d-month salary is% .2f", p-> month [8], p-> gz [8]); break Case 10: printf ("the worker's% d-month salary is% .2f", p-> month [9], p-> gz [9]); break; case 11: printf ("the worker's% d-month salary is% .2f", p-> month [10], p-> gz [10]); break Case 12: printf ("the worker's% d-month salary is% .2f", p-> month [11], p-> gz [11]); break; default: break;} p = p-> next;} else p = p-> next }} void Bubble_sort (Worker * L) / / Bubble sorting to sort the nodes of the linked list {Worker * pGrainq, tail = NULL; while ((L-> next- > next)! = tail) {p = L; Q = L-> next While (Q-> next! = tail) {if ((Q-> total) > (Q-> next- > total)) {p-> next = Q-> next; Q-> next = Q-> next- > next; p-> next- > next = Q; Q = p-> next;} Q = Q-> next P = p-> next;} tail = Q;} printf ("sort complete! The results of the total annual salary from small to large are as follows:\ n "); lager-> next; while (lumped null) {if (l-> nextlined null) {printf ("% s-> ", l-> name); lumped-> next;} else {printf ("% s ", 1-> name) Void StatiTotal (Worker * L next; n []) / / Statistics of the total annual salary of a worker {int i; Worker * pendant L-> next; while (paired salary null) {p-> total=0; if (strcmp (p-> name,n) = = 0) {for (iSitoTalent salary p-> gz [I]) Printf ("% s annual total salary is% .2f", ndjp-> total); break;} else pallep-> next;}} void Modify (Worker * L, char n [], int m, float s) {int iJournal j; Worker * p = L-> next While (p! = NULL) {if (strcmp (p-> name, n) = 0) {switch (m) {case 1: P-> gz [0] = s; break; case 2: P-> gz [1] = s; break Case 3: P-> gz [2] = s; break; case 4: P-> gz [3] = s; break; case 5: P-> gz [4] = s; break Case 6: P-> gz [5] = s; break; case 7: P-> gz [6] = s; break; case 8: P-> gz [7] = s; break Case 9: P-> gz [8] = s; break; case 10: P-> gz [9] = s; break; case 11: P-> gz [10] = s; break Case 12: P-> gz [11] = s; break; default: break;} p-> total=0; for } printf ("modified successfully!");} void Input (Worker * p, int I) {int j, k; p-> total = 0; printf ("Please enter the employee ID of% d employee:", I + 1); scanf ("% s", & p-> no); printf ("Please enter the name of% d employee:", I + 1); scanf ("% s", & p-> name) For (k = 0, j = 1; j month [k] = j; printf ("Please enter the monthly salary of the% d employee (separated by a space):", I + 1); for (j = 0; j

< 12; j++) { scanf("%f", &p->

Gz [j]); / enter monthly salary p-> total + = p-> gz [j]; / / calculate total salary}} void Print (Worker * L) / / print wage information for all employees {int i; Worker * p = L-> next; while (p! = NULL) {printf ("employee number:"); printf ("% s\ t\ n", p-> no) Printf ("name:"); printf ("% s\ n", p-> name); printf ("the worker's monthly salary for 12 months is as follows:"); for (I = 0; I

< 12; i++) printf("%.2f ", p->

Gz [I]); printf ("\ nThe total annual salary of the employee is:"); printf ("% .2f", p-> total); printf ("\ n\ n"); p = p-> next;}} void Save (Worker * L) {int i; Worker * p = L-> next; FILE * fp = fopen ("WorkerSalaryInfo.txt", "w") While (p! = NULL) {fprintf (fp, "employee number:"); fprintf (fp, "% s\ t\ n", p-> no); fprintf (fp, "name:"); fprintf (fp, "% s\ n", p-> name); fprintf (fp, "the monthly salary of the employee for 12 months is as follows:"); for (I = 0; I

< 12; i++) fprintf(fp, "%.2f ", p->

Gz [I]); fprintf (fp, "\ nThe employee's total annual salary is:"); fprintf (fp, "% .2f", p-> total); fprintf (fp, "\ n\ n"); p = p-> next;} fclose (fp); printf ("saved successfully and saved to the 'WorkerSalaryInfo.txt' file in the current directory") } void menu () {printf ("\ t\ n"); printf ("\ t\ t ▔ Welcome to the salary management system ▔\ n"); printf ("\ t\ T1. Enter the monthly salary information of the staff and workers\ n "); printf ("\ t\ T2. Find an employee's monthly salary by name\ n "); printf ("\ t\ T3. Find the monthly salary of an employee by name\ n "); printf ("\ t\ t4. Modify the monthly salary of an employee\ n "); printf ("\ t\ t5. Delete information about an employee\ n "); printf ("\ t\ t6. Insert employee salary information\ n "); printf ("\ t\ t7. Statistics of the total annual salary of an employee\ n "); printf ("\ t\ t8. Rank the total annual salary of employees from small to large\ n "); printf ("\ t\ t9. Output salary information of all employees\ n "); printf ("\ t\ t 10, save salary information of all employees to file\ n "); printf ("\ t\ t0. Exit\ n "); printf ("\ t\ t ▁ thank you for using ▁\ n ");} int main () {int item, n, m; / / item is used to receive input commands, n to receive input number of employees float s; char nam [10] Worker* L = (Worker*) malloc (sizeof (Worker)); L-> next=NULL; do {system ("cls"); menu (); printf ("\ nPlease enter the appropriate number and do the appropriate operation:\ n"); scanf ("% d", & item) Switch (item) {case 1: printf ("Please enter the number of employees you want to enter:"); scanf ("% d", & n); L = CreateList (L, n); getchar (); printf ("Please press any key to return to the main menu\ n"); getchar (); break Case 2: printf ("Please enter the name of the employee you are looking for:"); scanf ("% s", & nam); LIstSearch (L, nam); getchar (); printf ("Please press any key to return to the main menu\ n"); getchar (); break Case 3: printf ("Please enter the name of the employee you are looking for:"); scanf ("% s", & nam); printf ("Please enter the salary of the month in which you want to find the employee (1 to 12):"); scanf ("% d", & m); SearchMonthSalary (L, nam, m); getchar () Printf ("\ nPlease press any key to return to the main menu\ n"); getchar (); break; case 4: printf ("Please enter the employee name you want to modify:"); scanf ("% s", & nam); printf ("\ nPlease enter the month you want to modify:") Scanf ("% d", & m); printf ("\ nPlease enter your modified data:"); scanf ("% f", & s); Modify (L, nam, m, s); getchar (); printf ("Please press any key to return to the main menu\ n"); getchar (); break Case 5: printf ("Please enter the name of the employee you want to delete:"); scanf ("% s", & nam); DeleteList (L, nam); getchar (); printf ("Please press any key to return to the main menu\ n"); getchar (); break Case 6: InsertInfo (L); getchar (); printf ("\ nPlease press any key to return to the main menu\ n"); getchar (); break; case 7: printf ("Please enter the employee name you want to query:"); scanf ("% s", & nam) StatiTotal; getchar (); printf ("\ nPlease press any key to return to the main menu\ n"); getchar (); break; case 8: Bubble_sort (L); getchar (); printf ("\ nPlease press any key to return to the main menu\ n") Getchar (); break; case 9: printf ("Information for all employees is as follows:\ n\ n"); Print (L); getchar (); printf ("\ nPlease press any key to return to the main menu\ n"); getchar (); break Case 10: Save (L); getchar (); printf ("\ nPlease press any key to return to the main menu\ n"); getchar (); break; case 0: printf ("Thank you for using the payroll management system and are about to quit the payroll management system."); exit (0) Break;} printf ("\ n\ n");} while (item); return 0;}

Screenshots of some of the running results:

"how to use C language linked list to achieve wage management system" content is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report