C++員工工資管理系統(tǒng)源代碼_第1頁
C++員工工資管理系統(tǒng)源代碼_第2頁
C++員工工資管理系統(tǒng)源代碼_第3頁
C++員工工資管理系統(tǒng)源代碼_第4頁
C++員工工資管理系統(tǒng)源代碼_第5頁
已閱讀5頁,還剩12頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、文檔供參考,可復(fù)制、編制,期待您的好評與關(guān)注! #include <iomanip>#include <iostream>#include <fstream>#include <malloc.h>#include <stdlib.h>#include <string.h>using namespace std;#define NULL 0#define LEN sizeof(struct student) int const N=20;void Menu(); void Pass();int n=0; /定義一個全局變量統(tǒng)

2、計職工人數(shù) /->定義一個職工信息的結(jié)構(gòu)體struct student char nameN; /用來存放姓名char sexN; /用來存放性別long id; /用來存放編號float paid3; /用來存放工資int total; /用來存放總工資struct student *next;/->職工類class Information public:Information() ; /構(gòu)造函數(shù). Information() ; /析構(gòu)函數(shù). student *creat(); /建立鏈表void output(student *head); /顯示職工信息int count(

3、student *head); /定義函數(shù)count()統(tǒng)計職工總數(shù)student *insert(student*head); /指針函數(shù)*insert()用來添加職工信息.student *cancel(student *head,long id); /指針函數(shù)*cancel()用來刪除職工信息.student *find(student *head,long id); /指針函數(shù)*find()用來查找職工信息.student *modify(student *head,long id); /指針函數(shù)*modife()用來修改職工的信息.void paixu(student *head);

4、 /定義paixu()函數(shù)將職工的總額從大到小排列并輸出void average(student *head); /定義職工工資平均值的函數(shù)void save(student *head); /保存文件信息student *Read(); /讀取文件信息private:student *p1,*p2,*p3,*head,st; ;Information:Information() cout<<" *n"cout<<" -<<歡迎您使用員工工資管理系統(tǒng)>>-n" cout<<" *nn&

5、quot; Information:Information() cout<<" ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤n"cout<

6、<" n"cout<<" 本系統(tǒng)管理員 n"cout<<" n"cout<<" n"cout<<" -<<謝謝您使用員工工資管理系統(tǒng)>>-n" cout<<" n"cout<<" n"cout<<" 歡迎下次使用 n"cout<<" n"cout<<" n"co

7、ut<<" 再見 n"cout<<" n"cout<<" ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

8、¤n"/->建立鏈表信息student *Information:creat(void) /定義一個指向struct student的結(jié)構(gòu)體指針函數(shù)*creat()用來錄入職工信息. char chN;n=0; /用來存放職工姓名 p1=p2=(student *)malloc(LEN);/調(diào)用malloc()函數(shù)用來開辟一個新的存儲單元 cout<<" -<<請建立員工信息表,在姓名處鍵以 # 結(jié)束輸入!>>-"<<endl;cout<<" 姓名:"cin>&g

9、t;ch;head=NULL; /給指針head賦初值while (strcmp(ch,"#")!=0) /調(diào)用字符比較函數(shù)strcmp()用來判斷是否繼續(xù)輸入p1=(student *)malloc(LEN); /調(diào)用malloc()函數(shù)用來開辟一個新的存儲單元strcpy(p1->name,ch); /將循環(huán)結(jié)構(gòu)前面輸入的姓名復(fù)制到結(jié)構(gòu)體名為p1的數(shù)組name中cout<<" 性別:"cin>>p1->sex;cout<<" 編號:"cin>>p1->id;whil

10、e(p1->id)<0|(p1->id)>100000) /判斷輸入的編號是否有效(100000個)cout<<" 對不起您的輸入錯誤!請重新輸入(>0<1000000): "cin>>p1->id; cout<<" 基本工資:"cin>>p1->paid0;while(p1->paid0)<0|(p1->paid0)>100000) /判斷輸入的分數(shù)是否有效(>=0 <=100000)cout<<"

11、對不起您的輸入錯誤!請重新輸入(>0<100000): "cin>>p1->paid0; cout<<" 加班工資:"cin>>p1->paid1;while(p1->paid1)<0|(p1->paid1)>100000) /判斷輸入的分數(shù)是否有效(>=0 <=100000)cout<<" 對不起您的輸入錯誤!請重新輸入(>0<100000): "cin>>p1->paid1; cout<<&q

12、uot; 其他獎金:"cin>>p1->paid2;while(p1->paid2)<0|(p1->paid2)>100000) /判斷輸入的分數(shù)是否有效(>=0 <=100000)cout<<" 對不起您的輸入錯誤!請重新輸入(>0<100000): "cin>>p1->paid2; p1->total=p1->paid0+p1->paid1+p1->paid2; /計算總額 if(n=0)head=p1; /如果是輸入第一組職工信息就將指針p

13、1賦給指針headelse p2->next=p1; /否則將p1賦給p2所指結(jié)構(gòu)體的next指針p2=p1; /將指針p1賦給指針p2n+; /將職工人數(shù)n的值加1cout<<"n 姓名:"cin>>ch; /將輸入的姓名存放到字符數(shù)組ch中p2->next=NULL; /將p2所指結(jié)構(gòu)體的next指針重新賦空值return (head);/將輸入的第一組職工信息返回/->定義output()函數(shù)將職工的信息從頭指針?biāo)竷?nèi)容開始輸出void Information:output(student *head) system(&quo

14、t;cls");if(head=NULL) cout<<" 這是一個空表,請先輸入員工信息!n"elsecout<<"-n"cout<<" *職工工資信息表*n"cout<<"-n" cout<<"|編 號| |姓 名| |性別| |基本工資| |加班工資| |其他獎金| |總額|n"cout<<"-n" p1=head; /將頭指針賦給p docout<<setw(6)<&l

15、t;p1->id<<setw(10)<<p1->name<<setw(10)<<p1->sex<<setw(10)<<p1->paid0<<setw(10)<<p1->paid1<<setw(12)<<p1->paid2<<setw(12)<<p1->total<<endl;cout<<"-n" p1=p1->next; /將下一組職工信息的next指針賦給pw

16、hile(p1!=NULL); /若指針p非空則繼續(xù),目的是把所有的職工信息都傳給指針p然后輸出./->統(tǒng)計職工人數(shù)的函數(shù)int Information:count(struct student *head) /定義函數(shù)count()統(tǒng)計職工總數(shù)if(head=NULL)return(0); /若指針head為空返回值為0else return(1+count(head->next); /函數(shù)的遞歸調(diào)用/->添加職工的成績的函數(shù)student *Information:insert( student *head) /插入新結(jié)點定義一個指向struct student的結(jié)構(gòu)體指

17、針函數(shù)*insert()用來添加職工信息.system("cls");cout<<"t-<<請輸入新增員工信息>>-n"<<endl;p1=(student *)malloc(LEN); /使p1指向插入的新結(jié)點cout<<" 編號:"cin>>p1->id;while(p1->id)<0|(p1->id)>100000)cout<<" 對不起您的輸入錯誤!請重新輸入(>0<100000): &quo

18、t;cin>>p1->id; /將輸入的編號存放到p1所指結(jié)構(gòu)體的數(shù)組id中 cout<<" 姓名:"cin>>p1->name; /將輸入的姓名存放到結(jié)構(gòu)體名為p1的數(shù)組name中cout<<" 性別:"cin>>p1->sex; cout<<" 基本工資:"cin>>p1->paid0;while(p1->paid0)<0|(p1->paid0)>100000)cout<<" 對

19、不起您的輸入錯誤!請重新輸入(>0<100000): "cin>>p1->paid0; /將輸入的基本工資存放到p1所指結(jié)構(gòu)體的數(shù)組paid中cout<<" 加班工資:"cin>>p1->paid1;while(p1->paid1)<0|(p1->paid1)>100000)cout<<" 對不起您的輸入錯誤!請重新輸入(>0<100000): "cin>>p1->paid1; /將輸入的加班工資存放到p1所指結(jié)構(gòu)體的數(shù)

20、組paid中cout<<" 其他獎金:"cin>>p1->paid2;while(p1->paid2)<0|(p1->paid2)>100000)cout<<" 對不起您的輸入錯誤!請重新輸入(>0<100000): "cin>>p1->paid2; /將輸入的其他獎金存放到p1所指結(jié)構(gòu)體的數(shù)組paid中 p1->total=p1->paid0+p1->paid1+p1->paid2;/計算總分 p2=head; /將頭指針賦給p2if

21、(head=NULL) /若沒調(diào)用次函數(shù)以前的頭指針head為空head=p1;p1->next=NULL; /則將p1賦給頭指針head并將p1所指結(jié)構(gòu)體成員指針next賦空值else while(p1->id>p2->id)&&(p2->next!=NULL)p3=p2; /p3指向原p2指向的結(jié)點p2=p2->next; /p2后移一個結(jié)點if(p1->id<=p2->id)if(head=p2)p1->next=head;head=p1; /插入到第一個結(jié)點之前else p3->next=p1;p1-&g

22、t;next=p2; /插入到p3所指結(jié)點之后elsep2->next=p1;p1->next=NULL; /插入到尾結(jié)點之后n+; /將職工人數(shù)加1cout<<"t-<<你輸入的員工信息已經(jīng)成功插入>>-"<<endl;return (head);/->刪除職工信息student *Information:cancel(student *head,long id) /定義一個指向struct student的結(jié)構(gòu)體指針函數(shù)*delete()用來刪除考生信息. system("cls");

23、if(head=NULL) /若調(diào)用次函數(shù)以前的頭指針head為空 return(head);elsep1=head; /否則將頭指針賦給p1while(id!=p1->id&&p1->next!=NULL) /尋找要刪除的結(jié)點當(dāng)p1所指的職工編號不是輸入的職工編號并且p1所指的next指針不為空p2=p1;p1=p1->next; /p2指向原p1指向的結(jié)點p1后移一個結(jié)點if(id=p1->id) /如果輸入的職工編號是p1所指的職工編號/結(jié)點找到后刪除if(p1=head) head=p1->next; /如果head指針和p1指針相等則將下

24、一個結(jié)點賦給指針head else p2->next=p1->next; /否則將p1所指結(jié)點賦給p2所指結(jié)點將要刪除的職工信息跳過去cout<<" 刪除編號為"<<id<<"的職工n"n-; /將職工人數(shù)減1 return(head); /將頭指針返回/*修改職工數(shù)據(jù)*/student *Information:modify(student *head,long id)system("cls");cout<<"t-<<請輸入須修改的員工工資信息>

25、>-n"<<endl;p1=(student *)malloc(LEN); /使p1指向輸入的結(jié)點p1=head; /否則將頭指針賦給p1while(id!=p1->id&&p1->next!=NULL)/尋找結(jié)點當(dāng)p1所指的職工編號不是輸入的職工編號并且p1所指的next指針不為空p1=p1->next; /p2指向原p1指向的結(jié)點p1后移一個結(jié)點 if(id=p1->id) /如果要查找的職工編號是p1所指的職工編號cout<<"你需要修改的員工信息如下:n"cout<<&quo

26、t;-n"cout<<"|編 號| |姓 名| |性別| |基本工資| |加班工資| |其他獎金| |總額|n"cout<<"-n"cout<<setw(6)<<p1->id<<setw(10)<<p1->name<<setw(10)<<p1->sex<<setw(10)<<p1->paid0<<setw(10)<<p1->paid1<<setw(12)<

27、<p1->paid2<<setw(12)<<p1->total<<endl;cout<<"-n"cout<<" 編號:"cin>>p1->id;while(p1->id)<0|(p1->id)>100000)cout<<" 對不起您的輸入錯誤!請重新輸入(>0<100000): "cin>>p1->id; /將輸入的編號存放到p1所指結(jié)構(gòu)體的數(shù)組id中 cout<<

28、;" 姓名:"cin>>p1->name; /將輸入的姓名存放到結(jié)構(gòu)體名為p1的數(shù)組name中cout<<" 性別:"cin>>p1->sex; cout<<" 基本工資:"cin>>p1->paid0;while(p1->paid0)<0|(p1->paid0)>100000)cout<<" 對不起您的輸入錯誤!請重新輸入(>0<100000): "cin>>p1->pa

29、id0; /將輸入的基本工資存放到p1所指結(jié)構(gòu)體的數(shù)組paid中cout<<" 加班工資:"cin>>p1->paid1;while(p1->paid1)<0|(p1->paid1)>100000)cout<<" 對不起您的輸入錯誤!請重新輸入(>0<100000): "cin>>p1->paid1; /將輸入的加班工資存放到p1所指結(jié)構(gòu)體的數(shù)組paid中cout<<" 其他獎金:"cin>>p1->paid2

30、;while(p1->paid2)<0|(p1->paid2)>100000)cout<<" 對不起您的輸入錯誤!請重新輸入(>0<100000): "cin>>p1->paid2; /將輸入的其他獎金存放到p1所指結(jié)構(gòu)體的數(shù)組paid中 p1->total=p1->paid0+p1->paid1+p1->paid2; /計算總分 else cout<<" 需要修改的信息中沒有編號為"<<id<<"的員工.nn"

31、; /沒有想要修改的結(jié)點信息getchar();return(head);/->查找職工信息student *Information:find(student *head,long id) /定義一個指向struct student的結(jié)構(gòu)體指針函數(shù)*find()用來查找職工信息.system("cls");if(head=NULL) /若調(diào)用次函數(shù)以前的頭指針head為空cout<<" 這是一個空表,請先輸入員工信息!n"return(head); elsep1=head; /否則將頭指針賦給p1while(id!=p1->id&

32、amp;&p1->next!=NULL)/尋找結(jié)點當(dāng)p1所指的職工編號不是輸入的職工編號并且p1所指的next指針不為空p1=p1->next; /p2指向原p1指向的結(jié)點p1后移一個結(jié)點if(id=p1->id) /如果要查找的職工編號是p1所指的職工編號cout<<"-n"cout<<"|編 號| |姓 名| |性別| |基本工資| |加班工資| |其他獎金| |總額|n"cout<<"-n"cout<<setw(6)<<p1->id<

33、;<setw(10)<<p1->name<<setw(10)<<p1->sex<<setw(10)<<p1->paid0<<setw(10)<<p1->paid1<<setw(12)<<p1->paid2<<setw(12)<<p1->total<<endl;cout<<"-n"else cout<<"信息中沒有編號為"<<id<

34、<"的員工.n" /結(jié)點沒找到return(head);/-定義paixu()函數(shù)將職工的工資總額從大到小排列并輸出void Information:paixu(student *head) system("cls");int i,k,m=0,j;student *pN;/定義一個指向struct student的結(jié)構(gòu)體指針數(shù)組p if(head!=NULL)/如果頭指針是空則繼續(xù) m=count(head);cout<<"-n"cout<<" *員工工資統(tǒng)計表*n"cout<&

35、lt;"-n"cout<<"|編號| |姓名| |性別| |基本工資| |加班工資| |其他獎金| |總額| |名次|n"cout<<"-n"p1=head;for(k=0;k<m;k+)pk=p1;p1=p1->next;for(k=0;k<m-1;k+) /選擇排序法for(j=k+1;j<m;j+)if(pk->total<pj->total)p2=pk;pk=pj;pj=p2; /從大到小排列的指針 for(i=0;i<m;i+)cout<<s

36、etw(6)<<pi->id<<setw(8)<<pi->name<<setw(9)<<pi->sex<<setw(10)<<pi->paid0<<setw(10)<<pi->paid1<<setw(10)<<pi->paid2<<setw(10)<<pi->total<<setw(10)<<i+1<<endl;cout<<"-n"

37、 /->求各工資的平均值的函數(shù)void Information:average(student *head)int k,m;float arg1=0,arg2=0,arg3=0;if(head=NULL)/如果頭指針是空則繼續(xù)cout<<" 這是一個空表,請先輸入員工信息!n"elsem=count(head);p1=head;for(k=0;k<m;k+)arg1+=p1->paid0;arg2+=p1->paid1;arg3+=p1->paid2;p1=p1->next;arg1/=m;arg2/=m;arg3/=m;co

38、ut<<" *各項工資的平均值*n"cout<<"-n"cout<<"tt基本工資的平均值: "<<setw(4)<<arg1<<"n"<<"tt加班工資的平均值: "<<setw(4)<<arg2<<"n"<<"tt獎金的平均值: "<<setw(4)<<arg3<<"n&quo

39、t;cout<<"-n"/->保存函數(shù).void Information:save(student *head) system("cls"); ofstream out("data.txt",ios:out); out<<count(head)<<endl; while(head!=NULL) out<<head->name<<"t" <<head->id<<"t"<<"t

40、" <<head->sex<<"t" <<head->paid0<<"t" <<head->paid1<<"t" <<head->paid2<<"t" <<head->total<<endl; head=head->next; />讀取文件的信息student *Information:Read() system("cls")

41、; int i=0; p1=p2=( student *)malloc(LEN); head=NULL; ifstream in("data.txt",ios:in); in>>i; if(i=0)cout<<" data 文件中的數(shù)據(jù)為空,請先輸入數(shù)據(jù)!"<<endl; return 0; else cout<<"n原文件已保存的信息如下:n" cout<<" "<<endl; cout<<"|姓 名| |編 號| |性

42、別| |基本工資| |加班工資| |其他獎金| |總額|n" cout<<" "<<endl; for(;i>0;i-) p1=(student *)malloc(LEN); in>>>>st.id>>st.sex >>st.paid0>>st.paid1>>st.paid2>>st.total; strcpy(p1->name,); p1->id=st.id; strcpy(p1->sex,st.sex)

43、; p1->paid0=st.paid0; p1->paid1=st.paid1; p1->paid2=st.paid2; p1->total=st.total; if(n=0)head=p1; /如果是輸入第一組職工信息就將指針p1賦給指針head else p2->next=p1; /否則將p1賦給p2所指結(jié)構(gòu)體的next指針 p2=p1; /將指針p1賦給指針p2 n+; /將n的值加1 /顯示讀入數(shù)據(jù) cout<<" "<<p1->name<<"t" <<p1-&

44、gt;id<<" t" << p1->sex <<" t" << p1->paid0 <<" t" << p1->paid1 <<" t" << p1->paid2 <<" t" << p1->total<<endl; cout<<" "<<endl;cout<<" 數(shù)據(jù)

45、已經(jīng)成功讀取完畢!nn"<<endl; p2->next=NULL;in.close(); return (head); /->菜單void Menu() Information person; student *head=NULL; int choice; long i; head=person.Read(); do cout<<"t"<<endl; cout<<"t "<<endl; cout<<"t _ _ _ 歡迎進入員工信息統(tǒng)計管理 _ _

46、_ "<<endl; cout<<"t "<<endl; cout<<"t"<<endl; cout<<"t "<<endl; cout<<"t 相關(guān)操作選項 "<<endl; cout<<"t "<<endl; cout<<"t"<<endl; cout<<"t "<<

47、;endl; cout<<"t "<<endl; cout<<"t 1. 員工數(shù)據(jù)輸入 "<<endl; cout<<"t "<<endl; cout<<"t 2. 顯示員工工資 "<<endl; cout<<"t "<<endl; cout<<"t 3. 排序統(tǒng)計工資 "<<endl; cout<<"t &qu

48、ot;<<endl; cout<<"t 4. 查找員工工資 "<<endl; cout<<"t "<<endl; cout<<"t 5. 增加員工工資 "<<endl; cout<<"t "<<endl; cout<<"t 6. 刪除員工工資 "<<endl; cout<<"t "<<endl; cout<<&

49、quot;t 7. 修改員工信息 "<<endl; cout<<"t "<<endl; cout<<"t 8. 成功保存信息 "<<endl; cout<<"t "<<endl; cout<<"t 9. 安全退出系統(tǒng) "<<endl; cout<<"t "<<endl; cout<<"tn"<<endl; cou

50、t<<" 請輸入您的選擇(0-9):" cin>>choice; while(choice<0|choice>9) cout<<" 對不起您的輸入錯誤!請輸入您的選擇(0-9): " cin>>choice; /head=person.Read(); switch(choice) case 1: head=person.creat(); break; case 2: /head=person.Read(); person.output(head); break; case 3: /head=person.Read(); person.paixu(head); person.average(head); cout<<" 參加工作的員工人數(shù)為:"<<person.count(head)<<"人nn" break; case 4: /head=person.Read(); cout<<" 請輸入要查找的編號:&qu

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論