C++實(shí)現(xiàn)簡單職工管理系統(tǒng)
本文實(shí)例為大家分享了C++職工管理系統(tǒng)實(shí)例代碼,供大家參考,具體內(nèi)容如下
1.單個職工的頭文件
staff.h
#ifndef STAFF_H_INCLUDED #define STAFF_H_INCLUDED //結(jié)構(gòu)體創(chuàng)建 struct staff { char ID[10]; char name[10]; char sex[10]; int pay; int reward; int factpay; }; //自定義結(jié)構(gòu)體 typedef struct staff staff; //單個職工信息創(chuàng)建 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("-----請顯示要修改的數(shù)據(jù)--------\n"); Displaystaff(*Staff); printf("-------請輸入要修改的數(shù)據(jù)---------"); printf("-----------pay-----------\n"); scanf("%d", &Staff->pay); printf("-----------reward-----------\n"); scanf("%d", &Staff->reward); Staff->factpay = Staff->pay + Staff->reward; printf("\n"); }
2.鏈表的創(chuàng)建
鏈表的頭文件
linklist.h
#ifndef LINKLIST_H_INCLUDED #define LINKLIST_H_INCLUDED #include "staff.h" //鏈表結(jié)點(diǎn)創(chuàng)建 struct Node { struct staff Staff; struct Node *next; }; //自定義結(jié)點(diǎn) typedef struct Node node; typedef struct Node *linklist; //創(chuàng)建鏈表 node *Createlinklist(); //輸出鏈表中的數(shù)據(jù) 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
鏈表創(chuàng)建的源程序
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數(shù)據(jù)文件丟失或?yàn)槭状芜\(yùn)行, 將加載測試數(shù)據(jù)\n"); return ; } while( fread(&nodeBuffer, sizeof(node), 1, fp)!=0 ) { insertnode(h, nodeBuffer); } }
4.主函數(shù)
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("------請輸入你要存的數(shù)據(jù)----------\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("=================職工管理系統(tǒng)===================\n"); printf("==========1.鏈表輸出=====2.數(shù)據(jù)查詢=====\n"); printf("=======3.數(shù)據(jù)刪除===4.數(shù)據(jù)修改=====5.添加數(shù)據(jù)======\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("========添加數(shù)據(jù)========="); 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++實(shí)現(xiàn)簡單的圖書管理系統(tǒng)
C++實(shí)現(xiàn)簡單的職工信息管理系統(tǒng)
更多學(xué)習(xí)資料請關(guān)注專題《管理系統(tǒng)開發(fā)》。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C++實(shí)現(xiàn)教職工信息管理系統(tǒng)課程設(shè)計
- C++實(shí)現(xiàn)教職工信息管理系統(tǒng)
- C++實(shí)現(xiàn)職工工資管理系統(tǒng)課程設(shè)計
- C++實(shí)現(xiàn)職工工資管理系統(tǒng)
- C++實(shí)現(xiàn)職工信息管理系統(tǒng)
- C++實(shí)現(xiàn)職工管理系統(tǒng)
- C++利用多態(tài)實(shí)現(xiàn)職工管理系統(tǒng)(項(xiàng)目開發(fā))
- C++實(shí)現(xiàn)企業(yè)職工工資管理系統(tǒng)
- C++實(shí)現(xiàn)簡單職工信息管理系統(tǒng)
- 基于C++實(shí)現(xiàn)職工管理系統(tǒng)
相關(guān)文章
C++鏈表實(shí)現(xiàn)通訊錄管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C++鏈表實(shí)現(xiàn)通訊錄管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-12-12C語言基礎(chǔ)隱式類型轉(zhuǎn)換與強(qiáng)制類型轉(zhuǎn)換示例解析
最接地氣的有關(guān)類型轉(zhuǎn)換的介紹,此處對于類型轉(zhuǎn)換的相關(guān)知識點(diǎn)做一些簡要的介紹,作者實(shí)屬初學(xué),難免文章中有內(nèi)容理解不到位或者有不當(dāng)之處,還請朋友們不吝指正,希望大家多多給予支持2021-11-11C語言實(shí)現(xiàn)將字符和數(shù)字串到一起
今天小編就為大家分享一篇C語言實(shí)現(xiàn)將字符和數(shù)字串到一起,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12C語言編程技巧 關(guān)于const和#define的區(qū)別心得
盡量用const和inline而不用#define 這個條款最好稱為:“盡量用編譯器而不用預(yù)處理”,因?yàn)?define經(jīng)常被認(rèn)為好象不是語言本身的一部分。這是問題之一。再看下面的語句:2013-02-02C++中std::construct()與std::destroy()的使用
std::construct()和std::destroy()是C++ STL中的函數(shù)模板,用于在已分配的存儲區(qū)域中構(gòu)造或銷毀對象,本文主要介紹了C++中std::construct()與std::destroy()的使用,感興趣的可以了解一下2024-02-02C++實(shí)現(xiàn)TCP客戶端及服務(wù)器Recv數(shù)據(jù)篩選處理詳解
這篇文章主要為大家介紹了C++實(shí)現(xiàn)TCP客戶端及服務(wù)器Recv數(shù)據(jù)篩選處理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10Cocos2d-x保存用戶游戲數(shù)據(jù)之XML文件是否存在問題判斷方法
這篇文章主要介紹了Cocos2d-x保存用戶游戲數(shù)據(jù)之XML文件是否存在問題判斷方法,請注意代碼中包含大量注釋,需要的朋友可以參考下2014-09-09