版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、#include #include #include #include using namespace std;class Person /人員類(抽象類)protected: double num; /編號(hào) char Name20; /姓名 int Age; /年齡 int Duty; /人員類別標(biāo)志(0-教師,1-實(shí)驗(yàn)員,2-行政人員,3-教師兼實(shí)驗(yàn)員,4-行政兼教師) double Salary; /基本工資 Person *next; /指針域public: Person() /基類構(gòu)造 next=0; /指針域設(shè)置為空 virtual Person() /基類虛析構(gòu) virtual
2、void Input()=0; /從鍵盤輸入數(shù)據(jù) virtual void Input(ifstream& ifs)=0; /從文件輸入數(shù)據(jù)(引用) virtual void Output()=0; /向屏幕輸出數(shù)據(jù) virtual void Output(ofstream& ofs)=0; /向文件輸出數(shù)據(jù) virtual double Incoming()=0; /計(jì)算收入 friend class College; class Teacher:virtual public Person /教師類protected: int Hours; /教師課時(shí)public: /為對(duì)象設(shè)置數(shù)據(jù)分為兩種
3、途徑,通過1)構(gòu)造函數(shù),2)一般成員函數(shù) /本程序采用:缺省構(gòu)造+Input() Teacher() /構(gòu)造函數(shù),初始化部分?jǐn)?shù)據(jù) Duty=0; Salary=800; void Input() /鍵盤補(bǔ)充輸入其它數(shù)據(jù) coutnum; coutName; coutAge; coutHours; Salary=Incoming(); void Input(ifstream& ifs) ifsnumNameAgeDutyHoursSalary; void Output() coutnumtNametAgetDutytHourstSalarytendl; void Output(ofstream&
4、 ofs) ofsnumtNametAgetDutytHourstSalaryt20) return Salary+(Hours-20)*20; else return Salary; ; class Assistant:virtual public Person /實(shí)驗(yàn)員protected: int Allowance; public: Assistant() Duty=1; Salary=650; Allowance=150; void Input() coutnum; coutName; coutAge; Salary=Incoming(); void Input(ifstream& i
5、fs) ifsnumNameAgeDutySalary; void Output() coutnumtNametAgetDutyttSalarytendl; void Output(ofstream& ofs) ofsnumtNametAgetDutyttSalarytendl; double Incoming() return Salary+Allowance; ; class Manager:virtual public Person /行政人員protected: int Allowance; public: Manager() Duty=2; Salary=750; Allowance
6、=250; void Input() coutnum; coutName; coutAge; Salary=Incoming(); void Input(ifstream& ifs) ifsnumNameAgeDutySalary; void Output() coutnumtNametAgetDutyttSalarytendl; void Output(ofstream& ofs) ofsnumtNametAgetDutytSalarytendl; double Incoming() return Salary+Allowance; ; class Teacher_Assistant:pub
7、lic Teacher,public Assistant /教師兼實(shí)驗(yàn)員 protected: int Allowance; int Hours;public: Teacher_Assistant() Duty=3; Salary=800; Allowance=150; void Input() coutnum; coutName; coutAge; coutAllowance; coutHours; Salary=Incoming(); void Input(ifstream& ifs) ifsnumNameAgeDutyHoursSalary; void Output() coutnumt
8、NametAgetDutytAllowance tSalaryendl; void Output(ofstream& ofs) ofsnumtNametAgetDutytAllowancet Salaryt20) return Salary+(Hours-20)*20+Allowance; else return Salary+Allowance; ; class Manager_Teacher:public Manager,public Teacher /行政兼教師 protected: int Allowance; int Hours; public: Manager_Teacher()
9、Duty=4; int Salary=750; Allowance=250; void Input() coutnum; coutName; coutAge; coutHours; Salary=Incoming(); void Input(ifstream& ifs) ifsnumNameAgeDutyHoursSalary; void Output() coutnumtNametAgetDutytHourstSalarytendl; void Output(ofstream& ofs) ofsnumtNametAgetDutytHourstSalaryt20) return Salary+
10、(Hours-20)*20+Allowance; else return Salary+Allowance; ; class Collegeprivate: Person *PL; void Clear(); int College:Find(int ID,Person *p1,Person *p2); int College:Find1( char *NAME,Person *p1,Person *p2);public: College(); /構(gòu)造 College(); /析構(gòu) void Add(); /增加職工 void Delete(); /刪除職工 void Modify(); /修
11、改職工 void Print(); /輸出職工信息 void Save(); /職工信息存盤 void Load(); /職工信息裝入 void Find(); /查找 void Build(); /導(dǎo)引 void Stat(); /統(tǒng)計(jì) void Interface2(); ; College:College() /構(gòu)造函數(shù)(創(chuàng)建1個(gè)頭結(jié)點(diǎn)的鏈表) Person *p=new Teacher; PL=p; coutnext; delete p; p=PL; PL=0; void College:Add() /增加職工 char c; do coutnext)p=p-next; int ch;
12、 coutch; /創(chuàng)建新結(jié)點(diǎn),錄入數(shù)據(jù),連接到鏈表 Teacher *pt; Assistant *pa; Manager *pm; Teacher_Assistant *pta; Manager_Teacher *pmt; switch(ch) case 0: pt=new Teacher; pt-Input(); p-next=pt; break; case 1: pa=new Assistant; pa-Input(); p-next=pa; break; case 2: pm=new Manager; pm-Input(); p-next=pm; break; case 3: pta
13、=new Teacher_Assistant; pta-Input(); p-next=pta; break; case 4: pmt=new Manager_Teacher; pmt-Input(); p-next=pmt; break; default: return; coutc; while(c=y|c=Y); Save(); void College:Clear() /清除所有的職工結(jié)點(diǎn)(僅保留頭結(jié)點(diǎn)) Person *p=PL-next; while(p) PL-next=p-next; delete p; p=PL-next; /查找void College:Find() Per
14、son *p1,*p2; int ch,num; char name20; int again=1; char ah; while(again)Interface2();coutch;if (ch=1) coutnum; Find(num,&p1,&p2);if(ch=2) coutname; Find1(name,&p1,&p2); coutah;coutnext; *p2=PL; while(*p1) if(*p1)-num=ID)cout姓名:Nameendl; cout工作證號(hào):numendl; cout工資:Incoming()Output(); break; /找到 else *p
15、2=*p1; /繼續(xù)查找 *p1=(*p1)-next; if (*p1=0) cout對(duì)不起,該類別中沒有您所要查詢的職員!next;*p2=PL;while(*p1)/if(*p1)-Name=NAME)/if(strcmp(NAME ,(*p1)-Name)=0) couttt 姓名:Nameendl; couttt 工資:Incoming()Output();break; /找到else *p2=*p1; /繼續(xù)查找*p1=(*p1)-next;if(*p1=0)coutnntt 對(duì)不起,該類別中沒有您所要查詢的職員!endl;return *p1?1:0;void College:D
16、elete() /刪除職工 coutttt* 刪除職工 *n; int num; Person *p1,*p2; coutnum; if(!Find(num,&p1,&p2) coutnext=p1-next; /連接 delete p1; cout正確刪除!n; Save(); void College:Modify() /修改職工 coutttt* 修改職工 *n; int num; Person *p1,*p2; coutnum; if(!Find(num,&p1,&p2) cout指定的人員沒有找到!n; else coutOutput(); /輸出原來的職工信息(做提示) coutI
17、nput(); /輸入新的職工信息(更新) cout修改完成!n; Save(); void College:Print() /輸出職工信息 coutttt* 職工信息表 *n; coutnext; if(!p) coutOutput(); p=p-next; void College:Save() /職工信息存盤? ofstream f(Person.dat,ios:out); /打開文件 /遍歷輸出至文件 Person *p=PL-next; while(p) p-Output(f); p=p-next; f.close(); /關(guān)閉文件 coutbufbufbufDuty; if(f)
18、/根據(jù)人員類型創(chuàng)建新結(jié)點(diǎn) switch(Duty) case 0: p2=new Teacher; break; case 1: p2=new Assistant; break; case 2: p2=new Manager; break; case 3: p2=new Teacher_Assistant; break; case 4: p2=new Manager_Teacher; break; default: f.close(); return; p-next=p2; p=p-next; f.seekg(t); p-Input(f); else break; /關(guān)閉文件 f.close(
19、);void College:Load() /職工信息錄入 char ah; int c; couttt* 職工信息錄入 *n; do coutc; for(int i=1;inext)p=p-next; int ch; coutch; /創(chuàng)建新結(jié)點(diǎn),錄入數(shù)據(jù),連接到鏈表 Teacher *pt; Assistant *pa; Manager *pm; Teacher_Assistant *pta; Manager_Teacher *pmt; switch(ch) case 0: pt=new Teacher; pt-Input(); p-next=pt; break; case 1: pa=
20、new Assistant; pa-Input(); p-next=pa; break; case 2: pm=new Manager; pm-Input(); p-next=pm; break; case 3: pta=new Teacher_Assistant; pta-Input(); p-next=pta; break; case 4: pmt=new Manager_Teacher; pmt-Input(); p-next=pmt; break; default: return; Save(); coutah; while(ah=Y|ah=y);void College:Stat()
21、 coutttt* 統(tǒng)計(jì)職工信息 *n;Person *p1; Person *p2; double Sa=0; int a,b,i=0; double c,d; couta; if(a=1) coutb; p1=PL-next; p2=PL; while(p1) if(p1-Duty=b) i+; /找到 p2=p1; /繼續(xù)查找 p1=p1-next; else p2=p1; /繼續(xù)查找 p1=p1-next; coutb類職工的個(gè)數(shù)是:iendl; else if(a=2) coutc; coutd; p1=PL-next; p2=PL; while(p1) if(p1-Salary=c&p1-SalaryOutput();/找到 p2=p1; /繼續(xù)查找 p1=p1-next; else p2=p1; /繼續(xù)查找 p1=p1-next; else if(a=3) Person *p=PL-next
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 代理記帳合同范文
- 服裝工裝定制合同
- 小區(qū)租用場地合同
- 外匯借款合同參考范文
- 護(hù)坡防護(hù)合同范本年
- 嘉興物業(yè)管理合同
- 外貿(mào)銷售合同中英文
- 房屋裝修租賃合同書年
- 職工勞動(dòng)合同范本
- 北京郵電大學(xué)世紀(jì)學(xué)院《代數(shù)學(xué)II》2023-2024學(xué)年第二學(xué)期期末試卷
- 醫(yī)療器械耗材售后服務(wù)承諾書
- 北京房地產(chǎn)典當(dāng)合同書
- 文學(xué)類文本閱讀 高一語文統(tǒng)編版暑假作業(yè)
- 文明施工考核標(biāo)準(zhǔn)
- 《霧都孤兒人物分析4000字(論文)》
- MZ/T 039-2013老年人能力評(píng)估
- GB/T 6329-1996膠粘劑對(duì)接接頭拉伸強(qiáng)度的測定
- 2023年遼寧鐵道職業(yè)技術(shù)學(xué)院高職單招(語文)試題庫含答案解析
- (2019新教材)人教A版高中數(shù)學(xué)必修第二冊全冊學(xué)案
- 2022年中國電信維護(hù)崗位認(rèn)證動(dòng)力專業(yè)考試題庫大全-下(判斷、填空、簡答題)
- 國家標(biāo)準(zhǔn)圖集16G101平法講解課件
評(píng)論
0/150
提交評(píng)論