C項目校園信息管理(整理)_第1頁
C項目校園信息管理(整理)_第2頁
已閱讀5頁,還剩23頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、/person.h /*Copyright (c) 2005, 公司名稱*All rights reserved.* 文件名稱: person.h* 文件標識: .*摘要:person 類頭文件* 當前版本: 1.1* 作 者:輸入作者(或修改者)名字 *完成日期: .* 取代版本: 1.0* 原作者 :輸入原作者(或修改者)名字* 完成日期 .*/#ifndef PERSON_H #define PERSON_H#include #include /防止頭文件被多次編譯/#includeusing namespace std。enum ptypeSTUDENT,TEACHER,PERSONp

2、type/定義枚舉類型typedef struct date day。date。typedef struct course intxueqi 。 intzoukeshi。 charname50。course。class personpublic:char name10。char sex10。char address100。date birthday。/定/ 義 date 結構/定義 course 結構/perso 類聲明ptype type。person()。person()。virtual void Show() 。virtual void Read

3、()。virtual void Save(ofstream*ofile) 。virtual void Load(ifstream*ifile) 。 。#endif/pers on. cpp/person 類實現(xiàn)/*copyright (c) 2005, 公司名稱*All rights seserved.*文件名稱: person.cpp*文件標識: .*摘要:person 類定義文件* 當前版本: 1.0* 作 者:輸入作者(或修改者)名字 *完成日期: .*取代版本: .* 原作者 :輸入作者(或修改者)名字* 完成日期: .*/#include person.hperson:person(

4、)/初/ 始化全部成員數(shù)據(jù)name0=0。sex0=0。address0=0。type=PERSON。birthday.day=1。birthday.month=1。birthday.year=2000。person:person()void person:Show()/顯示信息coutv姓名:nameendl。coutvv 性:vvsexvve ndl。cout出期 :birthday.year_birthday.month_birthday.dayendl cout 家庭住址 :addressendl。生日void person:Read ()/輸/ 入信息coutvv姓名:name。co

5、utvv性別:sex。coutvv出生日期:birthday.year。coutvv月:。cinbirthday.month。coutvv日:。cinbirthday.day。coutvv家庭住址:vvendl。cinaddress。void perso n:Save(ofstream* ofile)/將數(shù)據(jù)存入文件/寫入文件 ofile-write(char*)&type,sizeof(type) 。size_t len=0。len=strlen(name)。ofile-write(char*)&len,sizeof(size_t) 。ofile-write(name,len)。len=st

6、rlen(sex)。ofile-write(char*)&len,sizeof(size_t) 。ofile-write(sex,len) 。len=strlen(address。)ofile-write(char*)&len,sizeof(size_t) 。ofile-write(address,len)。ofile-write(char*)&birthday,sizeof(date) 。void person:Load(ifstream* ifile)/ 將數(shù)據(jù)從文件讀出/讀入數(shù)據(jù)size_t len=0。 ifile-read(char*)&len,sizeof(size_t) 。ifi

7、le-read(name,len)。namelen=0。ifile-read(char*)&len,sizeof(size_t) 。ifile-read(sex,len)。sexlen=0。 ifile-read(char*)&len,sizeof(size_t) 。ifile-read(address,len)。 addresslen=0。ifile-read(char*)&birthday,sizeof(date) 。/stude nt.h/studen 類聲明/*Copyright (c) 2005,公司名稱*All rights reserved.*文件名稱 :student.h*文件

8、標識 :.*摘要:stude nt 類頭文件* 當前版本 :1.1* 作 者:輸入作者(或修改作者)名字*完成日期: .* 取代版本: 1.0* 原作者 :輸入作者(或修改作者)名字* 完成日期: .*/#ifndef STUDENT_H / 防止該頭文件被多次編譯#define STUDENT_H#include person.hclass student:public person/studer 類派生自 person 類public:char sclass20。char major50。course courses50。date sregiste。student ()。student()

9、。void Show()。void Read()。void Save(ofstream* ofile)。void Load(ifstream* ifile) 。#endif/stude nt.cpp/studen 類實現(xiàn)/*Copyfight (c) 2005, 公司名稱*All rights reserved.* 文件名稱 :student.cpp*文件標識 :.*摘要:student 類定義文件* 當前版本: 1.1* 作 者:輸入作者 ( 或修改作者)名字 *完成日期: .* 取代版本: 1.0* 原作者:輸入作者(或修改作者)名字 *完成日期: .*/#include student.

10、hstudent:student()/初/ 始化成員數(shù)據(jù)sclass0=0。major0=0 。sregister.day=1。sregister.month=1。 sregister.year=2000。type=STUDENT 。for(int i=0。i50。i+)0=0。coursesi.xueqi=0。coursesi.zoukeshi=0。student:student()void student:Show()/顯示信息person:Show()。/先調(diào)用基類 Show 函數(shù)cout 入 學 日 期 :sregister.year-sregister.mo

11、nth-sregister.dayendl。coutvv所學專業(yè):vvmajorvvendl。coutvv所在班級:vvsclassvvendl。coutvv所學課程:endl。for(int i=0 。 i50。 i+)if(0!=0)。void student:Read() /輸入數(shù)據(jù)person:Read(。先調(diào)用基類 Read 函數(shù)cout入學日期:sregister.year。coutvv月:。cinsregister.month。coutvv日:。cinsregister.day。coutvv所學專業(yè):major。cout

12、vv所在班級:sclass。void student:Save(ofstream* ofile) /將數(shù)據(jù)存入文件/寫入文件person:Save(ofile)。 先調(diào)用基類 Save 函數(shù)size_t len=0。len=strlen(sclass)。 ofile-write(char*)&len,sizeof(size_t) 。ofile-write(sclass,len)。len=strlen(major)。 ofile-write(char*)&len,sizeof(size_t) 。ofile-write(major,len) 。ofile-write(char*)&sregiste

13、r,sizeof(date) 。void student:Load(ifstream* ifile) /將數(shù)據(jù)從文件讀入/讀入數(shù)據(jù)person:Load(ifile)。/先調(diào)用基類 Load 函數(shù)size_t len=0。ifile-read(char*)&len,sizeof(size_t) 。 ifile-read(sclass,len)。sclasslen=0。ifile-read(char*)&len,sizeof(size_t) 。 ifile-read(major,len)。majorlen=0。ifile-read(char*)&sregister,sizeof(date)。/*

14、Copyright (c) 2005,公司名稱*All rights reserved.* 文件名稱 :teacher*文件標識 :.*摘要:teacher 類頭文件當前版本: 1.1作 者:輸入作者(或修改者)名字完成日期: .* 取代版本: 1.0* 原作者:輸入原作者(或修改者)名字*完成日期: .*/#ifndef TEACHER_H/防止該文件被多次編譯#define TEACHER_H#include person.hclass teacher:public person/teache 類派生自 person 類/teacher.h/teacher聲明public:course c

15、ourses50。date tregister。teacher()。teacher()。void Show()。void Read()。void Save (ofstream* ofile)。void Load(ifstream* ofile) 。#endif/teacher.cpp/teache 類實現(xiàn)/*Copyright (c) 2005,公司名稱*All rights reserved.*文件名稱 :student.cpp*文件標識 :.*當前版本: 1.2* 作 者:輸入作者(或修改作者)名字*完成日期: .取代版本: 1.1 *原作者:輸入原作者(或修改者)名字* 完成日期: .*

16、/#include teacher.hteacher:teacher()/初/ 始化數(shù)據(jù)成員tregister.day=1。tregister.month=1。tregister.year =2000。 type=TEACHER 。for(int i=0。i50。i+)0=0。 coursesi.xueqi=0。coursesi.zoukeshi=0。teacher:teacher()person:Show()。/先調(diào)用基類 Show 函數(shù)cout 進 校 日 期 :tregister.year-tregister.month-tregister.dayendl。co

17、ut所教課程:endl。for(int i=0。i50。i+)if(0!=0) 。void teacher:Read()/讀/ 取信息person:Read(。先調(diào)用基類 Read 函數(shù)cout進校日期:tregister.year。coutvv月:。cintregister.month。coutvv日:。cintregister.day。void teacher:Show()/顯示信息void teacher:Save(ofstream* ofile)/將數(shù)據(jù)寫入文件/寫入文件person:Save(ofile)。/洗調(diào)用基類 sa

18、ve 函數(shù)ofile-write(char*)&tregister,sizeof(date) 。void teacher:Load(ifstream*ifile) /將數(shù)據(jù)從文件讀入/讀入數(shù)據(jù)person:Load(ifile)。/洗調(diào)用基類 load 函數(shù)ifile-read(char*)&tregister,sizeof(date) 。/最后是命令調(diào)用及對象實例管理部分代碼 :/main.h/系統(tǒng)頭文件/* copyright (c) 2005,公司名稱* All rights reserved.*文件名稱 :main.h*文件標識 :.摘 要:主程序頭文件當前版本 :1.0 * 作 者:

19、輸入作者 (或修改者 )名字* 完成日期 :.*取代版本 :.* 原作者 :輸入原作者 (或修改者 )名字* 完成日期 :.*/#ifndef MAIN_H#define MAIN_H#include#include#endif/main.cpp/*Copyright (c) 2005, 公司名稱*All rights teserved.* 文件名稱 :main.cpp*文件標識 :.摘 要 :主程序定義文件當前版本 :1.2 * 作 者:輸入作者(或修改者)名字* 完成日期 :.*取代版本 :1.1* 原作者 :輸入原作者(或修改者)名字* 完成日期 :.*/#include main.h#

20、include person.h#include student.h#include teacher.h#includeusing n amespace stdlistAllPerson。 /聲明順序表全局變量void helpCMD()/顯示幫助信息coutvsetiosflags(ios:left)vsetw(20)vv可 用命令:描述:endl。coutsetiosflags(ios:left)setw(20)input 數(shù) 據(jù) 輸 入endl。coutsetiosflags(ios:left)setw(20)output 顯 示 數(shù) 據(jù)endl。coutsetiosflags(ios:

21、left)setw(20)analyze 分 析 數(shù) 據(jù)endl。coutvsetiosflags(ios:left)vvsetw(20)vvsavevv保存e ndl。coutvsetiosflags(ios:left)vvsetw(20)vvloadvv讀取e ndl。coutsetiosflags(ios:left)setw(20)exit 退 出 系 統(tǒng) endl。void inputCMD()coutA 輸入學生信息 endl 。coutB輸入教師信息bInfo 。cin.sync()。if(bInfo=a|bInfo=A) / 判斷用戶要輸入學生信息還是教師 信息student*

22、s=new student()。 /創(chuàng)建學生對象實例s-Read()。/輸入學生數(shù)據(jù)AllPerson.push_back(person*)s)。/將該對象實例存入順序表coutvv成功輸入學生信息Read()。/輸入教師數(shù)據(jù)AllPerson.push_back(person*)t)。 / 將該對象實例存入順序表coutvv成功輸入教師信息vve ndl。elsecoutvv輸入失??!請選擇輸入學生或教師信息:iterator AllPersonI i=0。for(AllPersonIterator=AllPerson.begin()。AllPersonIterator

23、!=AllPerson.end()。 +AllPersonIterator) / 遍歷順序表i+。cout-NO.i-Show() 。/ 對所有對象實例調(diào) 用 Show函數(shù)void analyzeCMD()list:iterator AllPersonIterator 。int sum=0,nstu=0,ntea=0。for(AllPersonIterator=AllPerson.begin() 。AllPersonIterator!=AllPerson.end()。 +AllPersonIterator) / 遍歷順序表if(*AllPersonIterator)-type=STUDENT)

24、/統(tǒng)計學生數(shù)量nstu+。量if(*AllPersonIterator)-type=TEACHER)/統(tǒng)計教師數(shù)ntea+。sum+。/統(tǒng)計人員總數(shù)cout 當前總人數(shù)為 :sumendl。cout其中 教師共ntea人,學生共nstu人 endl。void saveCMD()/將數(shù)據(jù)寫入文件ofstream ofile(person.dat,ios:binary|ios:trunc) 。/ 打 開pers on. dat 文件list:iterator AllPersonIterator 。/ 順序表瀏覽指針int sun=0。for(AllPersonIterator=AllPerson.

25、begin()。AllPersonIterator!=AllPerson . end()。 +AllPersonIterator) /遍歷順序 表計算人員總數(shù)sun+。ofile.write(char*)&sun,4) 。/將人員總數(shù)寫入文件for(AllPersonIterator=AllPerson.begin()。AllPersonIterator!=AllPerson . end()。 +AllPersonIterator) / 遍歷順序 表(*AllPersonIterator)-Save(&ofile) 。/ 對所有實例調(diào)用 Save 函數(shù)ofile.close() 。/關閉文件cout成功保存sun人信息endl。void loadCMD()ifstream ifile(person.dat,ios:binary)。打開 person.dat 文件int sum=0。ifile.read(char*)&sum,4) 。/讀入人員總數(shù)for(int i=0 。 iLoad(&ifile) 。AllPerson.push_back(person*)s)。/將學生對象實例放入順序表te

溫馨提示

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

評論

0/150

提交評論