Personnel Management System C language edition

Source: Internet
Author: User

int menu () {
printf ("Please follow the prompts to enter the complete operation!") \ n ");
printf ("1. Query employee information \ n");
printf ("2. Statistics of employees \ n");
printf ("3. Input employee information \ n");
printf ("4. Delete Employee information \ n");
printf ("5. Sort all employees by ID \ n");
printf ("6. Print all employee information \ n");
printf ("7. Exit system \ n");
return 0;

}

As the menu () function sees, the system has 7 functions in common


#include <stdio.h> #include <stdlib.h> #include <string.h>struct emp{int id;char name[50];struct EMP * Next;//struct emp * prev;}; struct EMP * initlist (), struct emp * addlisttailnode (struct emp * head), struct emp * deletelistnode (struct emp * head,int ID), struct emp * SEARCHEMP (struct EMP * head,int ID), int printlist (struct emp * l); int Printnode (struct emp * p); struct EM p * Sortlist (struct emp * head), int getlistlen (struct emp * head), int writetodisk (struct emp * head), struct EMP * readfrom Disk (); int menu (); int usage (struct emp * head);



#include "emp.h" int main () {struct EMP * head;head=readfromdisk (); usage (head); return 0;} struct EMP * initlist () {struct EMP * head;head= (struct emp *) malloc (sizeof (struct EMP)); Head->next=null;return Head;}  struct EMP * ADDLISTTAILNODE (struct emp * head) {int id;   Char name[50];  struct EMP * p, * last, * check;  last = head;  while (last->next!=null) {last=last->next;  } printf ("Enter: Employee ID number, name!\n");  scanf ("%d%s", &id,&name);  check = head; while (check!=last) {//Traversal check=check->next;if (id==check->id) {printf ("Join? Failed! Employee ID number repeated!  \ n ");  return head;   }} p= (struct emp *) malloc (sizeof (struct EMP));  p->id=id;  strcpy (P->name,name);    last->next=p;    last=p;  p->next=null; printf ("%s employee information added?!  \ n ", p->name);  return head;  } struct EMP * deletelistnode (struct EMP * head,int ID) {struct emp * p,* q;  p = head->next;  while (P!=null) {if (p->next->id==id) {break;  } p=p->next; } if (Head->next==null) {printf ("The book Information is empty! Delete failed!  \ n ");  }else{q = p->next;p->next = q->next;printf ("%s" The book information is deleted!) \ n ", q->name);  Free (q);  } return head;  } struct EMP * searchemp (struct EMP * head,int ID) {///query, return node information struct EMP * p;  p = head->next;  while (P!=null) {if (p->id==id) {break;  } p=p->next;  } return p;  } int Printnode (struct EMP * p) {//Print node information if (p!=null) {printf ("Employee ID:%d Employee Name:%s\n", p->id,p->name); } else{printf ("There is no such employee information in the system!")  \ n ");  } return 0;  } int printlist (struct emp * head) {//Print whole list of struct EMP * p;  p = head->next;  while (P!=null) {Printnode (P);  p=p->next;  } return 0; } struct EMP * sortlist (struct emp * head) {//Sort struct emp * p,* q;int temp_id;char temp_name[50];for (p=head->next;p!=n Ull;p=p->next) {for (Q=p->next;q!=null;q=q->next) {if (p->id>q->id) {temp_id = Q->id;q->id = P >id;p->id = temp_id;//strcpy (temp_name,q->name); strcpy (q->name,p->name); strcpy (P->name,temp_ name);}}} return head;} int Getlistlen (struct emp * head) {int len=0;struct EMP * P;p=head->next;while (p!=null) {len++;p =p->next;} return Len;} int Writetodisk (struct emp * head) {FILE * fp;struct emp * P;IF (fp = fopen ("D:\\emp.hhtx", "w")) = = 0) {printf ("Write Failed ...!! \ n "); return 0;} P=head->next;while (p!=null) {fwrite (p,sizeof (struct emp), 1,FP);p rintf ("%d%s\n", p->id,p->name);p =p- >next;} Fclose (FP); return 0;}  struct EMP * Readfromdisk () {FILE * FP; struct EMP * head,* last,* p,* temp;head = Initlist (); if (fp = fopen ("D:\\emp.hhtx", "r")) = = 0) {printf ("Load failed ... Archive data not found!\n\n "); return head;}  last = head;  p= (struct emp *) malloc (sizeof (struct EMP));  while (P!=null) {p= (struct emp *) malloc (sizeof (struct EMP)); Fread (p,sizeof (struct emp), 1,FP);p rintf ("read data:%d%s\n", p->id,p->name);            last->next=p;    last=p; P=p->next;} Fclose (FP);p rintf ("System data initialization is complete! "); return head;} int menu () {printf ("press the prompt to complete the operation!  \ n ");  printf ("1. Query employee information \ n");  printf ("2. Statistics of employees \ n");  printf ("3. Input employee information \ n");  printf ("4. Delete Employee information \ n"); printf ("5. Sort all employees by ID \ n"); printf ("6. PrintAll employee information \ n ");p rintf (" 7. Exit system \ n "); return 0;}   int usage (struct EMP * head) {int x,id;  struct EMP * P;menu (); while (1) {printf ("Please enter serial number:");  scanf ("%d", &x);  Switch (x) {case 1:printf ("Enter the ID number of the employee you want to query:");  scanf ("%d", &id);  p = searchemp (Head,id);  Printnode (P);  printf ("---------------------------------\ n"); Break  Case 2:printf ("Total%d employees \ n" In the system, Getlistlen (head)); Break;case 3:head=addlisttailnode (head);  printf ("---------------------------------\ n");  Break  Case 4:printf ("Enter the ID number of the employee you want to delete:");  scanf ("%d", &id);  Head=deletelistnode (Head,id);  printf ("---------------------------------\ n"); Break Case 5:printf ("sort starts ... \ n"); Head=sortlist (head);p rintf ("The sorting is complete!  \ n ");p rintf ("---------------------------------\ n ");  Break;case 6:printlist (head);  printf ("---------------------------------\ n");  Break  Case 7:writetodisk (head);p rintf ("Save complete ... \ n");p rintf ("exited system!\n"); printf ("---------------------------------\ n"); return 0;  Default:return 0; }} return 0;}



Personnel Management System C language edition

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.