C++學生信息管理系統(tǒng)(一卡通)_第1頁
C++學生信息管理系統(tǒng)(一卡通)_第2頁
C++學生信息管理系統(tǒng)(一卡通)_第3頁
C++學生信息管理系統(tǒng)(一卡通)_第4頁
C++學生信息管理系統(tǒng)(一卡通)_第5頁
已閱讀5頁,還剩18頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、/由于對fsream的不熟練,不會對指定部分的數(shù)據(jù)的修改,因而刪除了一些功能,同時也導致了只能對消費額進行加減,但不能導入txt文件。Code:Uni-card system.h#include using namespace std;class person public: void buildAdmin(); void buildUndergraduate(); void buildPostgraduate(); protected: char name20; char sex; char shape10; char tel12;class consumer:public person p

2、rotected: double money;class student :public consumer /定義學生類 protected: char number20; int age; char nowClass20; char birthPlace20;class admin :public person /定義管理員類 public: void login(); void adminRegister(); void adminRegister2(); private: char account12; char password12; char title;class undergra

3、duate :public student /定義本科生類 public: void searchUndergraduate(); void displayUndergraduate(); void inputUndergraduate_wrapper(); void inputUndergraduate(); void inputUndergraduate1(); void underPayout(char str); void monitorPower(); void outputClassStudent(char s); void underSearchAll(); private: c

4、har monitor;class postgraduate :public student /定義研究生類 public: void searchPostgraduate(); void displayPostgraduate(); void inputPostgraduate_wrapper(); void inputPostgraduate(); void inputPostgraduate1(); void postPayout(char str); void postSearchAll(); protected: double wage;/不清楚教職工是否配備有一卡通,所以暫不考慮教

5、職工類Uni-card system.cpp#include #include #include #include #include #include uni-card system.husing namespace std;void onUndergraduate();void onPostgraduate();bool comp(char s1,char s2);void inputStudent();void adminOnLogin();/-/-以下為person類中成員函數(shù)-/-void person:buildAdmin() /建立Admin.txt fstream file(Ad

6、min.txt,ios:out|ios:app); /打開文件,指針指向文件尾file.close(); /關閉文件void person:buildUndergraduate() /建立Undergraduate.txt fstream file(Undergraduate.txt,ios:out|ios:app); /打開文件,指針指向文件尾file.close(); /關閉文件void person:buildPostgraduate() /建立Postgraduate.txt fstream file(Postgraduate.txt,ios:out|ios:app); /打開文件,指

7、針指向文件尾file.close(); /關閉文件/-/-以下為admin類中成員函數(shù)-/-void admin:login() /管理員登錄及驗證 int ensurance=0; char account212,password212; admin ad; cout endl 管理員登錄界面 endl; cout account2; cout password2; fstream file(Admin.txt,ios:in);/打開文件,指針在文件頭file.read(char*)&ad,sizeof(ad); /讀取類信息while(!file.eof() /判斷文件指針是否到文件尾if

8、(comp(ad.account,account2)&comp(ad.password,password2) /判斷輸入的字符是否與文件中的一樣 cout 登錄成功! endl; ensurance=1;break; file.read(char*)&ad,sizeof(ad);/如果指針沒到文件尾,繼續(xù)讀取file.close();if(ensurance=0) cout 您的賬號或密碼輸入錯誤! endl;file.close(); /關閉文件if(ensurance) adminOnLogin();void admin:adminRegister() /管理員在文件外錄入信息 admin

9、 adm; char choose; int loop=1,loop1=1; cout endl 管理員注冊 endl; while(loop1) loop1=0; cout account; fstream file(Admin.txt,ios:in);/打開文件,指針在文件頭 file.read(char*)&adm,sizeof(adm); /讀取類信息 while(!file.eof() /判斷文件指針是否到文件尾 if(comp(adm.account,account) /判斷輸入的字符是否與文件中的一樣 cout 賬號已被占用! endl; loop1=1; break; file

10、.read(char*)&adm,sizeof(adm);/如果指針沒到文件尾,繼續(xù)讀取 file.close(); cout password; cout name; while(loop) cout choose; if(choose=a|choose=A) sex=m;loop=0; else if(choose=b|choose=B) sex=f;loop=0; else cout 您的輸入有誤,請重新選擇! endl; strcat(shape,Admin); cout tel; loop=1; while(loop) cout choose; if(choose=y|choose=

11、Y) title=y;loop=0; else if(choose=n|choose=N) title=n;loop=0; else cout 您的輸入有誤,請重新選擇! endl; void admin:adminRegister2() /將管理員信息錄入admin.txt admin ad; ad.adminRegister(); fstream file(admin.txt,ios:out|ios:app); /打開文件,指針指向文件尾file.write(char*)&ad,sizeof(ad); /把類信息寫入文件file.close(); /關閉文件cout .信息已保存 endl

12、;/-/-以下為undergraduate類中成員函數(shù)-/-void undergraduate:searchUndergraduate() /通過學號及姓名查找學生信息 undergraduate unde1; int ensurance=1; char number220,name220; cout number2; cout name2; fstream file(Undergraduate.txt,ios:in); /打開文件,指針在文件頭 file.read(char*)&unde1,sizeof(unde1); /讀取類信息 while(!file.eof() /判斷文件指針是否到

13、文件尾 if(comp(unde1.number,number2) if(comp(,name2) cout endl endl 本科生基本信息查詢結(jié)果 endl; cout 學號: unde1.number endl; cout 姓名: endl; cout 專業(yè)班級: unde1.nowClass endl; cout 年齡: unde1.age endl; cout 性別: ; if(unde1.sex = m) cout 男 endl; else if(unde1.sex = f) cout 女 endl; cout 班干部: ; if(und

14、e1.monitor = y) cout 班長 endl; else if(unde1.monitor = n) cout 無 endl; cout 籍貫: unde1.birthPlace endl; cout 電話: unde1.tel endl; cout 余額: unde1.money endl; else cout 您所輸入姓名與學號不符! endl; ensurance=0; break; file.read(char*)&unde1,sizeof(unde1);/如果指針沒到文件尾,繼續(xù)讀取 if(ensurance) cout 該學號不存在! endl; file.close(

15、);void undergraduate:outputClassStudent(char s) undergraduate under4; cout endl endl s 學生基本信息 endl 學號 姓名 專業(yè)班級 班長 年齡 性別 籍貫 電話 余額 endl; fstream file(Undergraduate.txt,ios:in);/打開文件,指針在文件頭 file.read(char*)&under4,sizeof(under4); /讀取類信息 while(!file.eof() /判斷文件指針是否到文件尾 if(comp(under4.nowClass,s) cout set

16、w(12) under4.number setw(8) setw(16) under4.nowClass setw(3) under4.monitor setw(4) under4.age setw(3) under4.sex setw(12) under4.birthPlace setw(14) under4.tel setw(6) under4.money endl; file.read(char*)&under4,sizeof(under4);/如果指針沒到文件尾,繼續(xù)讀取 file.close();void undergraduate:monitorPower(

17、) undergraduate under3; int ensure=0,ensureExit=1; char number220; char name220; cout number2; cout name2; fstream file(Undergraduate.txt,ios:in);/打開文件,指針在文件頭 file.read(char*)&under3,sizeof(under3); /讀取類信息 while(!file.eof() /判斷文件指針是否到文件尾 if(comp(under3.number,number2) if(comp(,name2) if(u

18、nder3.monitor=y) ensure =1 ; else cout 你不是班長,別冒牌了! endl; else cout 您輸入的學號和姓名不符! endl; ensureExit=0; break; file.read(char*)&under3,sizeof(under3);/如果指針沒到文件尾,繼續(xù)讀取 file.close(); if(ensureExit) cout 您所輸入的學號不存在! endl; if(ensure) outputClassStudent(under3.nowClass);void undergraduate:inputUndergraduate()

19、 /管理員錄入本科生信息 undergraduate undInput; char choose; int loop=1,loop1=1; strcat(shape,Undergraduate); while(loop1) loop1=0; cout number; fstream file(Undergraduate.txt,ios:in);/打開文件,指針在文件頭 file.read(char*)&undInput,sizeof(undInput); /讀取類信息 while(!file.eof() /判斷文件指針是否到文件尾 if(comp(undInput.number,number)

20、 /判斷輸入的字符是否與文件中的一樣 cout 該學號已經(jīng)錄入 endl; loop1=1; break; file.read(char*)&undInput,sizeof(undInput);/如果指針沒到文件尾,繼續(xù)讀取*/ file.close(); cout name; cout nowClass; cout age; while(loop) cout choose; if(choose=a|choose=A) sex=m;loop=0; else if(choose=b|choose=B) sex=f;loop=0; else cout 您的輸入有誤,請重新選擇! endl; cou

21、t birthPlace; cout tel; money = 0; loop=1; while(loop) cout choose; if(choose=y|choose=Y) monitor=y;loop=0; else if(choose=n|choose=N) monitor=n;loop=0; else cout 您的輸入有誤,請重新選擇! endl; void undergraduate:inputUndergraduate1() /管理員本科生信息進Undergraduate.txt文件 undergraduate undInput1; undInput1.inputUnderg

22、raduate(); fstream file(Undergraduate.txt,ios:out|ios:app); /打開文件,指針指向文件尾file.write(char*)&undInput1,sizeof(undInput1); /把類信息寫入文件file.close(); /關閉文件cout .信息已保存 endl;void undergraduate:inputUndergraduate_wrapper() /OK!管理員錄入本科生信息時單個錄入或多個錄入 char totalChar; int total,loop=1,i; undergraduate underInputWr

23、apper; while(loop) loop=0; cout 本科生信息錄入 endl; cout totalChar; if(totalChar9) cout 您的輸入有誤,請重新輸入! endl; loop = 1; continue; total = totalChar-0; for(i = 0; i total; i+) cout 第 i+1 位同學: endl; underInputWrapper.inputUndergraduate1() ; void undergraduate:underPayout(char str) char choose; double payMoney

24、; undergraduate undePay1; fstream file(Undergraduate.txt,ios:in); /打開文件,指針在文件頭 file.read(char*)&undePay1,sizeof(undePay1); /讀取類信息 while(!file.eof() /判斷文件指針是否到文件尾 if(comp(undePay1.number,str) cout 您的姓名為: undeP choose; if(choose=y|choose=Y) cout payMoney; undePay1.money -= payMoney; cout 您的余額為

25、: undePay1.money endl; break; else if (choose=n|choose=N) break; else cout 您的輸入錯誤 endl; break; file.read(char*)&undePay1,sizeof(undePay1);/如果指針沒到文件尾,繼續(xù)讀取 void undergraduate:underSearchAll() undergraduate under5; cout endl endl 本科生基本信息 endl 學號 姓名 專業(yè)班級 班長 年齡 性別 籍貫 電話 余額 endl; fstream file(Undergraduat

26、e.txt,ios:in);/打開文件,指針在文件頭 file.read(char*)&under5,sizeof(under5); /讀取類信息 while(!file.eof() /判斷文件指針是否到文件尾 cout setw(12) under5.number setw(8) setw(16) under5.nowClass setw(3) under5.monitor setw(4) under5.age setw(3) under5.sex setw(12) under5.birthPlace setw(14) under5.tel setw(6) under

27、5.money endl; file.read(char*)&under5,sizeof(under5);/如果指針沒到文件尾,繼續(xù)讀取 file.close();/-/-以下為postgraduate類中成員函數(shù)-/-void postgraduate:searchPostgraduate() /通過學號及姓名查找學生信息 postgraduate post1; int ensurance=1; char number220,name220; cout number2; cout name2; cout endl endl 研究生基本信息查詢結(jié)果 endl; fstream file(Pos

28、tgraduate.txt,ios:in); /打開文件,指針在文件頭 file.read(char*)&post1,sizeof(post1); /讀取類信息 while(!file.eof() /判斷文件指針是否到文件尾 if(comp(post1.number,number2) if(comp(,name2) post1.displayPostgraduate(); else cout 您所輸入姓名與學號不符! endl; ensurance=0; break; file.read(char*)&post1,sizeof(post1);/如果指針沒到文件尾,繼續(xù)讀取

29、if(ensurance) cout 該學號不存在! endl; file.close();void postgraduate:inputPostgraduate() /管理員錄入本科生信息 postgraduate postInput; char choose; int loop=1,loop1=1; strcat(shape,Postgraduate); while(loop1) loop1=0; cout number; fstream file(Postgraduate.txt,ios:in);/打開文件,指針在文件頭 file.read(char*)&postInput,sizeof

30、(postInput); /讀取類信息 while(!file.eof() /判斷文件指針是否到文件尾 if(comp(postInput.number,number) /判斷輸入的字符是否與文件中的一樣 cout 該學號已經(jīng)錄入 endl; loop1=1; break; file.read(char*)&postInput,sizeof(postInput);/如果指針沒到文件尾,繼續(xù)讀取*/ file.close(); cout name; cout nowClass; cout age; while(loop) cout choose; if(choose=a|choose=A) sex=m;loop=0; else if(choose=b|choose=B) sex=f;loop=0; else cout 您的輸入有誤,請重新選擇! endl; cout birthPlace; cout tel; cout wage; money = 0; loop=1;void postgraduate:inputPostgraduate1() /管理員本科生信息進Undergraduate.txt文件 postgradua

溫馨提示

  • 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

提交評論