C++实现简单的职工管理系统实训代码

C++实现简单的职工管理系统实训代码,第1张

概述本文实例为大家分享了C++职工管理系统实例代码1.单个职工的头文件staff.h 

本文实例为大家分享了C++职工管理系统实例代码

1.单个职工的头文件
staff.h 

#ifndef STAFF_H_INCLUDED#define STAFF_H_INCLUDED //结构体创建struct staff{  char ID[10];  char name[10];  char sex[10];  int pay;  int reward;  int factpay;};//自定义结构体 typedef struct staff staff;//单个职工信息创建staff Createstaff();//单个职工信息输出voID displaystaff(staff staff);//修改职工信息voID updatestaff(staff *Staff); #endif // STAFF_H_INCLUDED  单个职工的cpp文件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("-----请显示要修改的数据--------\n");  displaystaff(*Staff);   printf("-------请输入要修改的数据---------");  printf("-----------pay-----------\n");  scanf("%d",&Staff->pay);  printf("-----------reward-----------\n");  scanf("%d",&Staff->reward);  Staff->factpay = Staff->pay + Staff->reward;  printf("\n"); }

 2.链表的创建
链表的头文件
linkList.h 

#ifndef linkList_H_INCLUDED#define linkList_H_INCLUDED#include "staff.h"//链表结点创建struct Node{  struct staff Staff;  struct Node *next;};//自定义结点 typedef struct Node node;typedef struct Node *linkList;//创建链表node *CreatelinkList();//输出链表中的数据voID displaylinkList(node *head);//按职工号查找职工node *searchnode(node *head,char ID[]);//按姓名查找职工voID searchnodebyname(node *head,char name[]);//删除职工voID delenode(linkList head,char ID[]);//插入职工voID insertnode(linkList head,staff Staff);//链表销毁voID distroylinkList(linkList head); #endif // linkList_H_INCLUDED

链表创建的源程序
linkList.cpp

#include <stdio.h>#include <stdlib.h>#include <string.h>#include "staff.h"#include "linkList.h"node *CreatelinkList(){  node *head,*p;   head = (node *)malloc(sizeof(node));  head->next = NulL;  staff a[100] = {{"11111","mmm","f",12000,2000,14000},{"22222","aaa","m",13000,3000,16000},{"33333","sss",15000,18000},{"44444","fff",17000,8000,25000},{"55555","ggg",20000,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.h

#ifndef file_H_INCLUDED#define file_H_INCLUDED#include "linkList.h"#include "staff.h"//职工信息存盘voID saveinformation(linkList head );//职工信息加载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数据文件丢失或为首次运行,将加载测试数据\n");    return ;  }     while( fread(&nodeBuffer,fp)!=0 )  {    insertnode(h,nodeBuffer);  } }

4.主函数
mainmeun.cpp

#include <stdio.h>#include <stdlib.h>#include "linkList.h"#include "staff.h"#include "file.h"voID mainmeun(linkList head);voID searchmenu(linkList head); int main(voID){  linkList head=NulL;  //int n;   //printf("------请输入你要存的数据----------\n");  //scanf("%d",&n);  head = CreatelinkList();  system("cls");  //displaylinkList(head);   mainmeun(head);  printf("\n\n");  //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("=================职工管理系统===================\n");    printf("==========1.链表输出=====2.数据查询=====\n");    printf("=======3.数据删除===4.数据修改=====5.添加数据======\n");    printf("=======6.链表销毁===7.信息存盘=====8.放弃存盘=====\n");    printf("==================================================\n");     printf("======请选择功能(1~8):");    scanf("%d",&selection);    switch(selection)    {    case 1:      displaylinkList(head);      break;    case 2:      searchmenu(head);       break;    case 3:      printf("=========请输入工号==========\n");      scanf("%s",ID);      delenode(head,ID);      break;    case 4:      printf("=========请输入工号==========\n");      scanf("%s",ID);      p = searchnode(head,ID);      updatestaff(&(p->Staff));        break;    case 5:      printf("========添加数据=========");      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("=========查找菜单===========\n");    printf("===1.ID======2.name====3.退出====\n");    printf("=================================\n");     int selection;    printf("==请选择功能(1~3):");    scanf("%d",&selection);    switch(selection)    {    case 1:      printf("=====请输入ID=======\n");      scanf("%s",ID);      displaystaff(p->Staff);      break;     case 2:      printf("=====请输入name======\n");      scanf("%s",name);      searchnodebyname(head,name);      break;     case 3:      flag = 0;      break;    }    system("pause");    system("cls");    }while(flag == 1);}

以上就是本文的全部内容,希望对大家实现C++职工管理系统有所帮助,启发。

推荐几篇文章:

C++实现简单的图书管理系统

C++实现简单的职工信息管理系统

C++基础学生管理系统

总结

以上是内存溢出为你收集整理的C++实现简单的职工管理系统实训代码全部内容,希望文章能够帮你解决C++实现简单的职工管理系统实训代码所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1247094.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存