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

下載本文檔

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

文檔簡介

1、#include #include #include #include #include #include #define NULL 0int const N=20;#define LEN sizeof(struct student)using namespace std;void Menu();void Pass();int n=0; /定義一個全局變量統(tǒng)計職工人數(shù)/-定義一個職工信息的結(jié)構(gòu)體struct studentchar nameN; /用來存放姓名char sexN; /用來存放性別char zhiwuN; /用來存放職務(wù)char bumenN; / 用來存放所在部門long id

2、; /用來存放編號float paid; /用來存放工資int total; /用來存放總工資struct student *next;/-職工類class Information public: student *creat(); /建立鏈表 void output(student *head); /顯示職工信息 int count(student *head); /定義函數(shù)count()統(tǒng)計職工總數(shù) student *insert(student*head); /指針函數(shù)*insert()用來添加職工信息. student *cancel(student *head,long id); /

3、指針函數(shù)*cancel()用來刪除職工信息. student *find(student *head,long id); /指針函數(shù)*find()用來查找職工信息. student *modify(student *head,long id); /指針函數(shù)*modife()用來修改職工的信息. void paixu(student *head); /定義paixu()函數(shù)將職工的總額從大到小排列并輸出 void average(student *head); /定義職工工資平均值的函數(shù) void save(student *head); /保存文件信息 student *Read(); /讀取

4、文件信息 private: student *p1,*p2,*p3,*head,st; /-建立鏈表信息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 -endl; coutch; head=NULL; /給指針head 賦初值 while (strcmp(ch,#)!=0) /調(diào)用字符比較函數(shù)strcmp()用來判斷

5、是否繼續(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 中 coutp1-sex; coutp1-id; while(p1-id)id)100000) /判斷輸入的編號是否有效(100000個) cout0p1-id; coutp1-bumen; cout 請選擇級別:endl; cout 1.經(jīng)理endl; cout 2.技術(shù)人員endl; cout 3.銷售人員endl; cout 4.銷售經(jīng)理xuanze; switch(

6、xuanze) case 1: float wage1; cout請輸入級別:p1-zhiwu; cout請輸入經(jīng)理的工資:wage1; p1-paid=wage1; break; case 2: int worktime; int wage2; cout請輸入級別:p1-zhiwu; cout請輸入技術(shù)人員的工作時間:worktime; cout請輸入技術(shù)人員每小時的工資:wage2; p1-paid=worktime*wage2; break; case 3: int wage3; double ticheng3; cout請輸入級別:p1-zhiwu; cout請輸入當月銷售額:wage

7、3; cout請輸入提成比例:ticheng3; p1-paid=wage3*ticheng3; break; case 4: int wage4; double ticheng4; int gongzi; cout請輸入級別:p1-zhiwu; cout請輸入銷售經(jīng)理的固定工資:gongzi; cout請輸入當月銷售額:wage4; cout請輸入提成比例:ticheng4; p1-paid=gongzi+wage4*ticheng4; break; if(n=0)head=p1; /如果是輸入第一組職工信息就將指針p1 賦給指針head else p2-next=p1; /否則將p1 賦給

8、p2 所指結(jié)構(gòu)體的next 指針 p2=p1; /將指針p1 賦給指針p2 n+; /將職工人數(shù)n 的值加1 coutch; /將輸入的姓名存放到字符數(shù)組ch 中 p2-next=NULL; /將p2 所指結(jié)構(gòu)體的next 指針重新賦空值 return (head);/將輸入的第一組職工信息返回/-定義output()函數(shù)將職工的信息從頭指針所指內(nèi)容開始輸出void Information:output(student *head) system(cls); if(head=NULL) cout 這是一個空表,請先輸入職工信息!n; else cout-n; cout *職工工資信息表*n;

9、cout-n; cout|編 號| |姓 名| |性別| |所在部門| |級別| |工資|n; cout-n; p1=head; /將頭指針賦給p do coutsetw(6)idsetw(10)namesetw(10)sexsetw(10)bumensetw(10)zhiwusetw(10)paidendl; coutnext; /將下一組職工信息的next 指針賦給p while(p1!=NULL); /若指針p 非空則繼續(xù),目的是把所有的職工信息都傳給指針p 然后輸出./-統(tǒng)計職工人數(shù)的函數(shù)int Information:count(struct student *head) /定義函數(shù)

10、count()統(tǒng)計職工總數(shù) if(head=NULL)return(0); /若指針head 為空返回值為0 else return(1+count(head-next); /函數(shù)的遞歸調(diào)用/-添加職工的工資的函數(shù)student *Information:insert( student *head)/插入新結(jié)點定義一個指向struct student 的結(jié)構(gòu)體指針函數(shù)*insert()用來添加職工信息. system(cls); coutt-nendl; p1=(student *)malloc(LEN); /使p1 指向插入的新結(jié)點 coutp1-id; while(p1-id)id)100

11、000) cout0p1-id; /將輸入的編號存放到p1 所指結(jié)構(gòu)體的數(shù)組id 中 coutp1-name; /將輸入的姓名存放到結(jié)構(gòu)體名為p1 的數(shù)組name 中 coutp1-sex; coutp1-bumen; cout 請選擇級別:endl; cout 1.經(jīng)理endl; cout 2.技術(shù)人員endl; cout 3.銷售人員endl; cout 4.銷售經(jīng)理xuanze; switch(xuanze) case 1:float wage1;cout請輸入級別:p1-zhiwu;cout請輸入經(jīng)理的工資:wage1;p1-paid=wage1;break; case 2:int w

12、orktime;int wage2; cout請輸入級別:p1-zhiwu;cout請輸入技術(shù)人員的工作時間:worktime;cout請輸入技術(shù)人員每小時的工資:wage2;p1-paid=worktime*wage2;break; case 3: int wage3;double ticheng3;cout請輸入級別:p1-zhiwu;cout請輸入當月銷售額:wage3;cout請輸入提成比例:ticheng3;p1-paid=wage3*ticheng3;break; case 4:int wage4;double ticheng4;int gongzi;cout請輸入級別:p1-zh

13、iwu;cout請輸入銷售經(jīng)理的固定工資:gongzi;cout請輸入當月銷售額:wage4;cout請輸入提成比例:ticheng4;p1-paid=gongzi+wage4*ticheng4;break; p2=head; /將頭指針賦給p2 if(head=NULL) /若沒調(diào)用次函數(shù)以前的頭指針head 為空 head=p1; p1-next=NULL; /則將p1 賦給頭指針head 并將p1 所指結(jié)構(gòu)體成員指針next 賦空值 else while(p1-idp2-id)&(p2-next!=NULL) p3=p2; /p3 指向原p2 指向的結(jié)點 p2=p2-next; /p2

14、后移一個結(jié)點 if(p1-idid) if(head=p2) p1-next=head; head=p1; /插入到第一個結(jié)點之前 else p3-next=p1; p1-next=p2; /插入到p3 所指結(jié)點之后 else p2-next=p1; p1-next=NULL; /插入到尾結(jié)點之后 n+; /將職工人數(shù)加1 coutt-刪除職工信息student *Information:cancel(student *head,long id) /定義一個指向structstudent 的結(jié)構(gòu)體指針函數(shù)*delete()用來刪除考生信息. system(cls); if(head=NULL)

15、 /若調(diào)用次函數(shù)以前的頭指針head 為空 return(head); else p1=head; /否則將頭指針賦給p1 while(id!=p1-id&p1-next!=NULL) /尋找要刪除的結(jié)點當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 指針相等則將下一個結(jié)點賦給指針head else p2-next

16、=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); coutt-nid&p1-next!=NULL) /尋找結(jié)點當p1 所指的職工編號不是輸入的職工編號并且p1 所指的next 指針不為空 p1=p1-next; /p2 指向原p1 指向的結(jié)點p1 后移一個結(jié)點 if(id=p1-id) /如果要查找的職工編號是

17、p1 所指的職工編號 cout你需要修改的職工信息如下:n; cout-n; cout|編 號| |姓 名| |性別| |所屬部門| |級別| |工資|n; cout-n; coutsetw(6)idsetw(10)namesetw(10)sexsetw(10)bumensetw(10)zhiwusetw(12)paidendl; cout-n; coutp1-id; while(p1-id)id)100000) cout0p1-id; /將輸入的編號存放到p1 所指結(jié)構(gòu)體的數(shù)組id 中 coutp1-name; /將輸入的姓名存放到結(jié)構(gòu)體名為p1 的數(shù)組name 中 coutp1-sex;

18、coutp1-bumen; cout 請選擇級別:endl; cout 1.經(jīng)理endl; cout 2.技術(shù)人員endl; cout 3.銷售人員endl; cout 4.銷售經(jīng)理xuanze; switch(xuanze) case 1:float wage1;cout請輸入級別:p1-zhiwu;cout請輸入經(jīng)理的工資:wage1;p1-paid=wage1;break; case 2:int worktime;int wage2;cout請輸入級別:p1-zhiwu;cout請輸入技術(shù)人員的工作時間:worktime;cout請輸入技術(shù)人員每小時的工資:wage2;p1-paid=w

19、orktime*wage2;break; case 3: int wage3;double ticheng3;cout請輸入級別:p1-zhiwu;cout請輸入當月銷售額:wage3;cout請輸入提成比例:ticheng3;p1-paid=wage3*ticheng3;break; case 4: int wage4; double ticheng4; int gongzi; cout請輸入級別:p1-zhiwu; cout請輸入銷售經(jīng)理的固定工資:gongzi; cout請輸入當月銷售額:wage4; cout請輸入提成比例:ticheng4; p1-paid=gongzi+wage4*

20、ticheng4; break; elsecout 需要修改的信息中沒有編號為id查找職工信息student *Information:find(student *head,long id)/定義一個指向struct student 的結(jié)構(gòu)體指針函數(shù)*find()用來查找職工信息. system(cls); if(head=NULL) /若調(diào)用次函數(shù)以前的頭指針head 為空 coutid&p1-next!=NULL) /尋找結(jié)點當p1 所指的職工編號不是輸入的職工編號并且p1 所指的next 指針不為空 p1=p1-next; /p2 指向原p1 指向的結(jié)點p1 后移一個結(jié)點 if(id=p

21、1-id) /如果要查找的職工編號是p1 所指的職工編號 cout-n; cout|編 號| |姓 名| |性別| |所屬部門| |級別| |工資|n; cout-n; coutsetw(6)idsetw(10)namesetw(10)sexsetw(10)bumensetw(10)zhiwusetw(12)paidendl; cout-n; else cout信息中沒有編號為id的職工.n; /結(jié)點沒找到 return(head); /-定義paixu()函數(shù)將職工的工資總額從大到小排列并輸出void Information:paixu(student *head) system(cls);

22、 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-n; cout|編號| |姓名| |性別| |所屬部門| |級別| |工資| |名次|n; cout-n; p1=head; for(k=0;knext; for(k=0;km-1;k+) /選擇排序法 for(j=k+1;jpaidpaid) p2=pk; pk=pj; pj=p2; /從大到小排列的指針 for(i=0;im;i+)

23、 coutsetw(6)idsetw(8)namesetw(9)sexsetw(10)bumensetw(10)zhiwusetw(10)paidsetw(10)i+1endl; cout求各工資的平均值的函數(shù)void Information:average(student *head) int k,m; float arg=0; if(head=NULL)/如果頭指針是空則繼續(xù) cout 這是一個空表,請先輸入職工信息!n; else m=count(head); p1=head; for(k=0;kpaid; p1=p1-next; arg/=m; cout *工資的平均值*n; cout

24、-n; couttt 工資的平均值: setw(4)argnendl; cout保存函數(shù).void Information:save(student *head) system(cls); ofstream out(data,ios:out); outcount(head)endl; while(head!=NULL) outnametidttsextbumentzhiwutpaidtnext;/-讀取文件的信息student *Information:Read() system(cls); int i=0; p1=p2=( student *)malloc(LEN); head=NULL;

25、ifstream in(data,ios:out); ini; if(i=0)cout data 文件中的數(shù)據(jù)為空,請先輸入數(shù)據(jù)!endl; return 0; else coutn 原文件已保存的信息如下:n; cout endl; cout|姓 名| |編 號| |性別| |所屬部門| |級別| |工資|n; cout 0;i-) p1=(student *)malloc(LEN); st.idst.sexst.bumenst.zhiwust.paid; strcpy(p1-name,); p1-id=st.id; strcpy(p1-sex,st.sex)

26、; strcpy(p1-bumen,st.bumen); strcpy(p1-zhiwu,st.zhiwu); p1-paid=st.paid; 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 nametid tsex tbumen tzhiwu tpaid tendl; cout endl; cout 數(shù)據(jù)已經(jīng)成功讀取完畢!nnnext=NULL; return (head)

27、; /-菜單void Menu() Information person; student *head=NULL; int choice; long i; do couttendl; coutt endl; coutt _ _ _ 歡迎進入職工工資統(tǒng)計管理 _ _ _ endl; coutt endl; couttendl; couttendl; coutt 相關(guān)操作選項endl; couttendl; couttendl; coutt 1. 讀取文件信息 endl; coutt endl; coutt 2. 職工數(shù)據(jù)輸入 endl; coutt endl; coutt 3. 顯示職工工資 endl; coutt endl; coutt 4. 排序統(tǒng)計工資 endl; coutt

溫馨提示

  • 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)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論