国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

C++實現簡單的職工管理系統實訓代碼

2020-05-23 14:05:42
字體:
來源:轉載
供稿:網友
這篇文章主要為大家詳細介紹了C++職工管理系統實訓代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
 

本文實例為大家分享了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", "f", 15000, 3000, 18000},        {"44444", "fff", "m", 17000, 8000, 25000},        {"55555", "ggg", "f", 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, sizeof(node), 1, 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);      p = searchnode(head, 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++職工管理系統有所幫助,啟發。



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 景泰县| 同心县| 龙泉市| 铜鼓县| 沙雅县| 黄大仙区| 贡山| 岑溪市| 垦利县| 天水市| 乐平市| 南陵县| 浠水县| 成安县| 准格尔旗| 岗巴县| 仙游县| 上杭县| 泰和县| 资溪县| 兴海县| 沂源县| 柯坪县| 库伦旗| 竹山县| 南川市| 轮台县| 林西县| 鸡泽县| 井陉县| 清原| 察雅县| 定结县| 冕宁县| 邵东县| 洪湖市| 凤冈县| 绥德县| 昌邑市| 上杭县| 枣庄市|