C++員工工資管理系統(tǒng)源代碼--精選文檔_第1頁(yè)
C++員工工資管理系統(tǒng)源代碼--精選文檔_第2頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、#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; /定義一個(gè)全局變量統(tǒng)計(jì)職工人數(shù) /->定義一個(gè)職工信息的結(jié)構(gòu)體

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

3、nt()統(tǒng)計(jì)職工總數(shù)student *insert(student*head); /指針函數(shù)*insert()用來(lái)添加職工信息.student *cancel(student *head,long id); /指針函數(shù)*cancel()用來(lái)刪除職工信息.student *find(student *head,long id); /指針函數(shù)*find()用來(lái)查找職工信息.student *modify(student *head,long id); /指針函數(shù)*modife()用來(lái)修改職工的信息.void paixu(student *head); /定義paixu()函數(shù)將職工的總額從大到小排

4、列并輸出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" Information:Inform

5、ation() cout<<" ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤n"cout<<" n"cout&l

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

7、ot;cout<<" n"cout<<" ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤n"/->建立鏈表信

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

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

10、t;id)>100000) /判斷輸入的編號(hào)是否有效(100000個(gè))cout<<" 對(duì)不起您的輸入錯(cuò)誤!請(qǐng)重新輸入(>0<1000000): "cin>>p1->id; cout<<" 基本工資:"cin>>p1->paid0;while(p1->paid0)<0|(p1->paid0)>100000) /判斷輸入的分?jǐn)?shù)是否有效(>=0 <=100000)cout<<" 對(duì)不起您的輸入錯(cuò)誤!請(qǐng)重新輸入(>0<

11、;100000): "cin>>p1->paid0; cout<<" 加班工資:"cin>>p1->paid1;while(p1->paid1)<0|(p1->paid1)>100000) /判斷輸入的分?jǐn)?shù)是否有效(>=0 <=100000)cout<<" 對(duì)不起您的輸入錯(cuò)誤!請(qǐng)重新輸入(>0<100000): "cin>>p1->paid1; cout<<" 其他獎(jiǎng)金:"cin>&

12、gt;p1->paid2;while(p1->paid2)<0|(p1->paid2)>100000) /判斷輸入的分?jǐn)?shù)是否有效(>=0 <=100000)cout<<" 對(duì)不起您的輸入錯(cuò)誤!請(qǐng)重新輸入(>0<100000): "cin>>p1->paid2; p1->total=p1->paid0+p1->paid1+p1->paid2; /計(jì)算總額 if(n=0)head=p1; /如果是輸入第一組職工信息就將指針p1賦給指針headelse p2->nex

13、t=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("cls");if(head=NUL

14、L) cout<<" 這是一個(gè)空表,請(qǐng)先輸入員工信息!n"elsecout<<"-n"cout<<" *職工工資信息表*n"cout<<"-n" cout<<"|編 號(hào)| |姓 名| |性別| |基本工資| |加班工資| |其他獎(jiǎng)金| |總額|n"cout<<"-n" p1=head; /將頭指針賦給p docout<<setw(6)<<p1->id<<setw(

15、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指針賦給pwhile(p1!=NULL); /若指針p非空則

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

17、tem("cls");cout<<"t-<<請(qǐng)輸入新增員工信息>>-n"<<endl;p1=(student *)malloc(LEN); /使p1指向插入的新結(jié)點(diǎn)cout<<" 編號(hào):"cin>>p1->id;while(p1->id)<0|(p1->id)>100000)cout<<" 對(duì)不起您的輸入錯(cuò)誤!請(qǐng)重新輸入(>0<100000): "cin>>p1->id;

18、/將輸入的編號(hào)存放到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<<" 對(duì)不起您的輸入錯(cuò)誤!請(qǐng)重新輸入(>0<

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

20、 其他獎(jiǎng)金:"cin>>p1->paid2;while(p1->paid2)<0|(p1->paid2)>100000)cout<<" 對(duì)不起您的輸入錯(cuò)誤!請(qǐng)重新輸入(>0<100000): "cin>>p1->paid2; /將輸入的其他獎(jiǎng)金存放到p1所指結(jié)構(gòu)體的數(shù)組paid中 p1->total=p1->paid0+p1->paid1+p1->paid2;/計(jì)算總分 p2=head; /將頭指針賦給p2if(head=NULL) /若沒(méi)調(diào)用次函數(shù)以前的頭

21、指針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é)點(diǎn)p2=p2->next; /p2后移一個(gè)結(jié)點(diǎn)if(p1->id<=p2->id)if(head=p2)p1->next=head;head=p1; /插入到第一個(gè)結(jié)點(diǎn)之前else p3->next=p1;p1->next=p2; /插入到p3所指結(jié)點(diǎn)之后e

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

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

24、;next=p1->next; /否則將p1所指結(jié)點(diǎn)賦給p2所指結(jié)點(diǎn)將要?jiǎng)h除的職工信息跳過(guò)去cout<<" 刪除編號(hào)為"<<id<<"的職工n"n-; /將職工人數(shù)減1 return(head); /將頭指針?lè)祷?*修改職工數(shù)據(jù)*/student *Information:modify(student *head,long id)system("cls");cout<<"t-<<請(qǐng)輸入須修改的員工工資信息>>-n"<<endl

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

26、uot;|編 號(hào)| |姓 名| |性別| |基本工資| |加班工資| |其他獎(jiǎng)金| |總額|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)<<p1->paid2<<

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

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

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

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

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

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

33、>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<<"信息中沒(méi)有編號(hào)為"<<id<<"的員工.n" /結(jié)

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

35、;<"|編號(hào)| |姓名| |性別| |基本工資| |加班工資| |其他獎(jiǎng)金| |總額| |名次|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<<setw(6)<<pi->id&

36、lt;<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" /->求各工資的平均值的函數(shù)void I

37、nformation:average(student *head)int k,m;float arg1=0,arg2=0,arg3=0;if(head=NULL)/如果頭指針是空則繼續(xù)cout<<" 這是一個(gè)空表,請(qǐng)先輸入員工信息!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;cout<<" *各項(xiàng)工資的平

38、均值*n"cout<<"-n"cout<<"tt基本工資的平均值: "<<setw(4)<<arg1<<"n"<<"tt加班工資的平均值: "<<setw(4)<<arg2<<"n"<<"tt獎(jiǎng)金的平均值: "<<setw(4)<<arg3<<"n"cout<<"-n&q

39、uot;/->保存函數(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" <<head->

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

41、nt *)malloc(LEN); head=NULL; ifstream in("data.txt",ios:in); in>>i; if(i=0)cout<<" data 文件中的數(shù)據(jù)為空,請(qǐng)先輸入數(shù)據(jù)!"<<endl; return 0; else cout<<"n原文件已保存的信息如下:n" cout<<" "<<endl; cout<<"|姓 名| |編 號(hào)| |性別| |基本工資| |加班工資| |其他獎(jiǎng)金|

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); p1->paid0=st.paid0;

43、 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->id<<" t&qu

44、ot; << p1->sex <<" t" << p1->paid0 <<" t" << p1->paid1 <<" t" << p1->paid2 <<" t" << p1->total<<endl; cout<<" "<<endl;cout<<" 數(shù)據(jù)已經(jīng)成功讀取完畢!nn"<<

45、;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 _ _ _ 歡迎進(jìn)入員工信息統(tǒng)計(jì)管理 _ _ _ "<<endl; co

46、ut<<"t "<<endl; cout<<"t"<<endl; cout<<"t "<<endl; cout<<"t 相關(guān)操作選項(xiàng) "<<endl; cout<<"t "<<endl; cout<<"t"<<endl; cout<<"t "<<endl; cout<<"

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

48、;<"t 4. 查找員工工資 "<<endl; cout<<"t "<<endl; cout<<"t 5. 增加員工工資 "<<endl; cout<<"t "<<endl; cout<<"t 6. 刪除員工工資 "<<endl; cout<<"t "<<endl; cout<<"t 7. 修改員工信息 "&

49、lt;<endl; cout<<"t "<<endl; cout<<"t 8. 成功保存信息 "<<endl; cout<<"t "<<endl; cout<<"t 9. 安全退出系統(tǒng) "<<endl; cout<<"t "<<endl; cout<<"tn"<<endl; cout<<" 請(qǐng)輸入您的選擇(

50、0-9):" cin>>choice; while(choice<0|choice>9) cout<<" 對(duì)不起您的輸入錯(cuò)誤!請(qǐng)輸入您的選擇(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<<" 請(qǐng)輸入要查找的編號(hào)

溫馨提示

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

評(píng)論

0/150

提交評(píng)論