版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、#include#include#include#include#include#include#includeusing namespace std;/日期類class date private: int year,month,day; /年、月、日三個成員 public: void set_date(int y,int m,int d) year=y;month=m;day=d;int get_year() return year;/取年份int get_month() return month;/取月份int get_day() return day;/取日期;/人員類class per
2、sonprotected:char name10;char id6;char sex2;date birth;char idCard18;public:char *get_name()return name;char *get_id()return id;char *get_sex()return sex;char *get_idCard()return idCard;int get_year()return birth.get_year();int get_month()return birth.get_month();int get_day()return birth.get_day();
3、/ 學生類 (繼承人員類)class student : public personprotected:char classNum15;public: char *get_classNum() return classNum;void printS();void get_stu();void showS();void enterStu(int&); /輸入學生記錄void showStu(); /顯示學生記錄bool searchStu(); /按姓名查找學生記錄void changeStu(); /更改學生記錄void insertStu(); /插入學生記錄void delStu(int&
4、); /刪除學生記錄;void student:printS() /輸出學生信息 coutsetw(3)get_id(); coutsetw(8)get_name(); coutsetw(4)get_sex(); coutsetw(10)get_year()年get_month()月get_day()日; coutsetw(20)get_idCard(); coutsetw(15)get_classNum()endl;void student:showS() coutsetw(4)編號; coutsetw(6)姓名; coutsetw(6)性別; coutsetw(15)出生日期; couts
5、etw(18)身份證號; coutsetw(15)學號endl;int s=0; /定義全局變量,用于記錄人事管理系統(tǒng)中的學生數void student:get_stu() ifstream file(stu.dat,ios:binary|ios:in);/打開用于讀的binary文件 if(!file) ofstream outfile(stu.dat,ios:app|ios:binary);/打開文件,并將指針指向文件尾 if(!outfile) cerrstu.dat 文件打開錯誤!endl; return; return; file.read(char*)(this),sizeof(*
6、this);/讀取一個類對象數據放入*this中 while(!file.eof() s+;/每調用一次該函數,職員總數增加1 file.read(char*)(this),sizeof(*this);/再讀取一個類對象數據放入*this中 file.close();void student:enterStu(int& s) /輸入學生信息int year,month,day;cout輸入學生信息:endl;ofstream outfile(stu.dat,ios:app|ios:binary);/打開文件,并將指針指向文件尾 coutid;coutname;coutsex;coutidCar
7、d;coutclassNum;coutyearmonthday;birth.set_date(year, month, day);coutendl;outfile.write(char*)(this),sizeof(*this);/將輸入的信息寫入文件outfile.close();cout信息建立成功!endl;s+; /每調用一次該函數,學生總數增加1void student:showStu()/顯示所有學生信息if(s=0) cout學生數據為空,請先添加學生信息!endl;elseifstream infile(stu.dat,ios:binary); /打開用于讀的binary文件i
8、nfile.read(char*)(this),sizeof(*this); /讀取一個類對象數據放入*this中cout所有學生的信息如下:endl;showS();while(!infile.eof() /沿未到達文件尾,繼續(xù)處理printS();infile.read(char*)(this),sizeof(*this);infile.close();bool student:searchStu()/按姓名查找學生信息char na10;cout請輸入你要查找學生的姓名:na;ifstream infile(stu.dat,ios:binary);infile.read(char*)(t
9、his),sizeof(*this);/打開文件,讀取數據while(!infile.eof()if(strcmp(name,na)=0) cout該學生的個人信息如下:endl; showS();printS();infile.close();return true;infile.read(char*)(this),sizeof(*this);/文件指針未到文件尾,循環(huán)讀取數據infile.close();cout對不起,你要查找的學生不存在!endl;return false;void student:changeStu() /修改數據int year,month,day;int chan
10、gemark=0; /用于標記該編號信息是否已找到char stuname20;cout請輸入你要修改信息的學生的:stuname;ofstream outfile(stuchange.dat,ios:app|ios:binary);/打開用于寫的二進制文件ifstream infile(stu.dat,ios:binary);/打開用于讀的二進制文件infile.read(char*)(this),sizeof(*this);/從stu.txt中讀取一個類對象數據放入*this中showS();while(!infile.eof()if(strcmp(name,stuname)=0)chan
11、gemark=1; cout輸入學生修改信息:endl;ofstream outfile(stuchange.dat,ios:binary);/打開文件coutid;coutname;coutsex;coutidCard;coutclassNum;coutyearmonthday;birth.set_date(year, month, day);outfile.write(char*)(this),sizeof(*this);/將輸入的信息寫入文件outfile.close();cout信息修改成功!endl;else outfile.write(char*)(this),sizeof(*th
12、is);/將讀得的數據寫入文件infile.read(char*)(this),sizeof(*this);/再次讀取一個類對象數據,放于*this中outfile.close();infile.close();if(changemark=1) /將修改后的信息寫入原文件ofstream outfile(stu.dat,ios:binary);/打開用于寫的二進制文件stu.txtifstream infile(stuchange.dat,ios:binary);/打開用于讀的二進制文件infile.read(char*)(this),sizeof(*this);/讀取一個類對象數據放入*th
13、is中while(!infile.eof()outfile.write(char*)(this),sizeof(*this);infile.read(char*)(this),sizeof(*this);infile.close();outfile.close();if(changemark=0)cout欲修改的學生不存在!endl;void student:insertStu() /插入數據 int year,month,day;cout添加學生信息:endl;ofstream outfile(stu.dat,ios:app|ios:binary);/打開文件,并將指針指向文件尾 couti
14、d;coutname;coutsex;coutidCard;coutclassNum;coutyearmonthday;birth.set_date(year, month, day);coutendl;outfile.write(char*)(this),sizeof(*this);/將輸入的信息寫入文件outfile.close();cout信息添加成功!endl;s+; /每調用一次該函數,學生總數增加1void student:delStu(int& s) /刪除學生信息char b;int delmark=0; /用于標記該編號信息是否已找到char stuname20;cout請輸
15、入要刪除學生的姓名:stuname;ofstream outfile(studel.dat,ios:binary);/打開用于寫的二進制文件ifstream infile(stu.dat,ios:binary);/打開用于讀的二進制文件infile.read(char*)(this),sizeof(*this);/從managestu.txt中讀取一個類對象數據放入*this中 cout該學生的個人信息如下:endl;coutsetw(4)編號;coutsetw(6)姓名;coutsetw(6)性別;coutsetw(15)出生日期;coutsetw(18)身份證號;coutsetw(15)學
16、號endl;while(!infile.eof()if(strcmp(name,stuname)=0)printS();coutendl你確定要刪除該學生的信息?(Y=yes/N=no)b;if(b=y|b=Y)delmark=1; /將刪除標記置為1,表示已刪除信息s-; /確定刪除信息,人事檔案管理系統(tǒng)中成員總數減1cout該學生信息已刪除!endl;elsedelmark=-1;else outfile.write(char*)(this),sizeof(*this);/將讀得的數據寫入文件infile.read(char*)(this),sizeof(*this);/再次讀取一個類對象
17、數據,放于*this中outfile.close();infile.close();if(delmark=1) /若找到了刪除對象,就用tu1.txt文件內容去充當stu.txtofstream outfile(stu.dat,ios:binary);/打開用于寫的二進制文件stu.txtifstream infile(studel.dat,ios:binary);/打開用于讀的二進制文件managestu1.txtinfile.read(char*)(this),sizeof(*this);/讀取一個類對象數據放入*this中while(!infile.eof()outfile.write(
18、char*)(this),sizeof(*this);infile.read(char*)(this),sizeof(*this);infile.close();outfile.close();if(delmark=0)cout欲刪除的學生不存在!endl;/教師類 (繼承人員類)class teacher : public personprotected:char work10; char party20;public: char *get_work() return work;char *get_party()return party;void printT();void printT1(
19、);void inputT();void get_tch();void enterTch(int&); /輸入教師記錄void showTch(); /顯示教師記錄bool searchTch(); /按姓名查找教師記錄void changeTch(); /更改教師記錄void insertTch(); /插入教師記錄void delTch(int&); /刪除教師記錄;void teacher:printT() /輸出教師信息 coutsetw(3)get_id(); coutsetw(8)get_name(); coutsetw(4)get_sex(); coutsetw(10)get_y
20、ear()年get_month()月get_day()日; coutsetw(20)get_idCard(); coutsetw(10)get_work(); coutsetw(14)get_party()endl;void teacher:printT1() /用于研究生輸出導師信息 coutsetw(6)姓名; coutsetw(6)性別; coutsetw(15)出生日期; coutsetw(18)身份證號; coutsetw(13)職務; coutsetw(13)部門endl; cout信息; coutsetw(6)get_name(); coutsetw(4)get_sex(); c
21、outsetw(10)get_year()年get_month()月get_day()日; coutsetw(20)get_idCard(); coutsetw(10)get_work(); coutsetw(14)get_party()endl;void teacher:inputT() / 用于研究生輸入導師信息 int year,month,day;coutname;coutsex;coutidCard;coutwork;coutparty;coutyearmonthday;birth.set_date(year, month, day);int t=0; void teacher:ge
22、t_tch() ifstream file(tch.dat,ios:binary|ios:in); if(!file) ofstream outfile(tch.dat,ios:app|ios:binary); if(!outfile) cerrtch.dat 文件打開錯誤!endl; return; return; file.read(char*)(this),sizeof(*this); while(!file.eof() t+; file.read(char*)(this),sizeof(*this); file.close();void teacher:enterTch(int&)in
23、t year,month,day;cout輸入教師信息:endl;ofstream outfile(tch.dat,ios:app|ios:binary); coutid;coutname;coutsex;coutidCard;coutwork;coutparty;coutyearmonthday;birth.set_date(year, month, day);coutendl;outfile.write(char*)(this),sizeof(*this);outfile.close();cout信息建立成功!endl;t+; void teacher:showTch()if(t=0) c
24、out教師數據為空,請先添加教師信息!endl;elseifstream infile(tch.dat,ios:binary);infile.read(char*)(this),sizeof(*this);cout所有教師的信息如下:endl; coutsetw(4)編號; coutsetw(6)姓名; coutsetw(6)性別; coutsetw(15)出生日期; coutsetw(18)身份證號; coutsetw(13)職務; coutsetw(13)部門endl;while(!infile.eof() printT();infile.read(char*)(this),sizeof(
25、*this); infile.close();bool teacher:searchTch()char na10;cout請輸入你要查找教師的姓名:na;ifstream infile(tch.dat,ios:binary);infile.read(char*)(this),sizeof(*this);while(!infile.eof()if(strcmp(name,na)=0)cout該教師的個人信息如下:endl; coutsetw(4)編號; coutsetw(6)姓名; coutsetw(6)性別; coutsetw(15)出生日期; coutsetw(18)身份證號; coutse
26、tw(8)職務; coutsetw(16)部門endl;printT();infile.close();return true;infile.read(char*)(this),sizeof(*this);infile.close();cout對不起,你要查找的教師不存在!endl;return false;void teacher:changeTch() int year,month,day;int changemark=0; char tchname20;cout請輸入你要修改的教師的姓名:tchname;ofstream outfile(tchchange.dat,ios:app|ios
27、:binary);ifstream infile(tch.dat,ios:binary);infile.read(char*)(this),sizeof(*this);while(!infile.eof()if(strcmp(name,tchname)=0)changemark=1; cout輸入修改信息:endl;ofstream outfile(tchchange.dat,ios:binary); coutid;coutname;coutsex;coutidCard;coutwork;coutparty;coutyearmonthday;birth.set_date(year, month
28、, day);coutendl;outfile.write(char*)(this),sizeof(*this);outfile.close();cout信息修改成功!endl;else outfile.write(char*)(this),sizeof(*this);infile.read(char*)(this),sizeof(*this);outfile.close();infile.close();if(changemark=1)ofstream outfile(tch.dat,ios:binary);ifstream infile(tchchange.dat,ios:binary);
29、infile.read(char*)(this),sizeof(*this);while(!infile.eof()outfile.write(char*)(this),sizeof(*this);infile.read(char*)(this),sizeof(*this);infile.close();outfile.close();if(changemark=0)cout欲修改的教師不存在!endl;void teacher:insertTch() int year,month,day;cout添加教師信息:endl;ofstream outfile(tch.dat,ios:app|ios
30、:binary); coutid;coutname;coutsex;coutidCard;coutwork;coutparty;coutyearmonthday;birth.set_date(year, month, day);coutendl;outfile.write(char*)(this),sizeof(*this);outfile.close();cout信息添加成功!endl;t+; void teacher:delTch(int&) char b;int delmark=0; char stuname20;cout請輸入要刪除教師的姓名:stuname;ofstream outf
31、ile(tchdel.dat,ios:binary);ifstream infile(tch.dat,ios:binary);infile.read(char*)(this),sizeof(*this); cout該教師的個人信息如下:endl; coutsetw(4)編號; coutsetw(6)姓名; coutsetw(6)性別; coutsetw(15)出生日期; coutsetw(18)身份證號; coutsetw(13)職務; coutsetw(13)部門endl;while(!infile.eof()if(strcmp(name,stuname)=0)printT();couten
32、dl你確定要刪除該教師的信息?(Y=yes/N=no)b;if(b=y|b=Y)delmark=1; s-; cout該教師信息已刪除!endl;elsedelmark=-1;else outfile.write(char*)(this),sizeof(*this);infile.read(char*)(this),sizeof(*this);outfile.close();infile.close();if(delmark=1) ofstream outfile(tch.dat,ios:binary);ifstream infile(tchdel.dat,ios:binary);infile
33、.read(char*)(this),sizeof(*this);while(!infile.eof()outfile.write(char*)(this),sizeof(*this);infile.read(char*)(this),sizeof(*this);infile.close();outfile.close();if(delmark=0)cout欲刪除的教師不存在!endl;/研究生類 (繼承學生類)class postgraduate : public studentprotected:char major20;char tutor10;teacher tch;public:vo
34、id set_postgraduate(char *major,char *party); char *get_major() return major;char *get_tutor() return tutor;void printPG();void get_PG();void enterPG(int&); void showPG(); bool searchPG(); void changePG(); void insertPG(); void delPG(int&); ;void postgraduate:printPG() coutsetw(3)get_id(); coutsetw(
35、8)get_name(); coutsetw(4)get_sex(); coutsetw(10)get_year()年get_month()月get_day()日; coutsetw(20)get_idCard(); coutsetw(15)get_classNum(); coutsetw(12)get_major()endl; coutsetw(2)導師; tch.printT1();int p=0; void postgraduate:get_PG() ifstream file(pg.dat,ios:binary|ios:in); if(!file) ofstream outfile(p
36、g.dat,ios:app|ios:binary); if(!outfile) cerrpg.dat 文件打開錯誤!endl; return; return; file.read(char*)(this),sizeof(*this); while(!file.eof() p+; file.read(char*)(this),sizeof(*this); file.close();void postgraduate:enterPG(int&)int year,month,day;cout輸入研究生信息:endl;ofstream outfile(pg.dat,ios:app|ios:binary
37、); coutid;coutname;coutsex;coutidCard;coutclassNum;coutmajor;coutyearmonthday;birth.set_date(year, month, day);coutendl;cout請輸入導師信息:endl;tch.inputT();outfile.write(char*)(this),sizeof(*this);outfile.close();cout信息建立成功!endl;p+; void postgraduate:showPG()if(p=0) cout研究生數據為空,請先添加研究生信息!endl;elseifstream
38、 infile(pg.dat,ios:binary);infile.read(char*)(this),sizeof(*this);cout所有研究生的信息如下:endl;while(!infile.eof() coutsetw(4)編號; coutsetw(6)姓名; coutsetw(6)性別; coutsetw(15)出生日期; coutsetw(18)身份證號; coutsetw(15)學號; coutsetw(14)專業(yè)endl;printPG();coutendl;infile.read(char*)(this),sizeof(*this); infile.close();bool
39、 postgraduate:searchPG()char na10;cout請輸入你要查找研究生的姓名:na;ifstream infile(pg.dat,ios:binary);infile.read(char*)(this),sizeof(*this); cout該研究生的個人信息如下:endl; coutsetw(4)編號; coutsetw(6)姓名; coutsetw(6)性別; coutsetw(15)出生日期; coutsetw(18)身份證號; coutsetw(15)學號endl;while(!infile.eof()if(strcmp(name,na)=0)printPG(
40、);infile.close();return true;infile.read(char*)(this),sizeof(*this);infile.close();cout對不起,你要查找的研究生不存在!endl;return false;void postgraduate:changePG() int year,month,day;int changemark=0; char pgname20;cout請輸入你要修改的研究生的姓名:pgname;ofstream outfile(pgchange.dat,ios:app|ios:binary);ifstream infile(pg.dat,ios:binary);infile.read(char*)(this),sizeof(*this);while(!infile.eof()if(strcmp(name,pgname)=0)changemark=1; cout輸入修改信息:endl;ofstream outfile(pgchange.dat,ios:binary); coutid;coutname;coutsex;coutidCard;coutclassNum; coutmajor
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 五年級上冊數學期中試卷及答案
- 第二學期小學科學教學工作總結
- 課程的公共性
- 鋼結構承載力計算技術要點
- 電采暖系統(tǒng)技術應用方法
- 云石線線路改造工程環(huán)境影響報告書
- 2026屆山東省濱州市高三上學期期末考試歷史試題(含答案)
- 社區(qū)考試試題解析及答案
- 社會保障法試題及答案
- 青島焊工證考試題及答案
- 醫(yī)療器械生產質量管理規(guī)范自查表(2026版)
- 銀行個人貸款風險評估管理辦法
- 創(chuàng)傷性遲發(fā)性顱內血腫
- 安全管理制度匯編報審表
- 中藥檢驗報告書書寫格式規(guī)范概要
- 中國鈷行業(yè)鈷資源分布、價格走勢、庫存及鈷回收預測
- GA 1333-2017車輛駕駛人員體內毒品含量閾值與檢驗
- 安全生產標準化管理體系全套文件
- 外科學教案-泌尿系結核
- 特種設備(行車事故)應急預案演練記錄
- 電位、電壓測定
評論
0/150
提交評論