




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、/由于对fsream的不熟练,不会对指定部分的数据的修改,因而删除了一些功能,同时也导致了只能对消费额进行加减,但不能导入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类中成员函数-/-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类中成员函数-/-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);/如果指针没到文件尾,继续读取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);/如果指针没到文件尾,继续读取 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类中成员函数-/-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 本科生基本信息查询结果 endl; cout 学号: unde1.number endl; cout 姓名: endl; cout 专业班级: 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);/如果指针没到文件尾,继续读取 if(ensurance) cout 该学号不存在! endl; file.close(
15、);void undergraduate:outputClassStudent(char s) undergraduate under4; cout endl endl s 学生基本信息 endl 学号 姓名 专业班级 班长 年龄 性别 籍贯 电话 余额 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);/如果指针没到文件尾,继续读取 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);/如果指针没到文件尾,继续读取 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 该学号已经录入 endl; loop1=1; break; file.read(char*)&undInput,sizeof(undInput);/如果指针没到文件尾,继续读取*/ 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);/如果指针没到文件尾,继续读取 void undergraduate:underSearchAll() undergraduate under5; cout endl endl 本科生基本信息 endl 学号 姓名 专业班级 班长 年龄 性别 籍贯 电话 余额 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);/如果指针没到文件尾,继续读取 file.close();/-/-以下为postgraduate类中成员函数-/-void postgraduate:searchPostgraduate() /通过学号及姓名查找学生信息 postgraduate post1; int ensurance=1; char number220,name220; cout number2; cout name2; cout endl endl 研究生基本信息查询结果 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);/如果指针没到文件尾,继续读取
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 该学号已经录入 endl; loop1=1; break; file.read(char*)&postInput,sizeof(postInput);/如果指针没到文件尾,继续读取*/ 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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《深入理解课件制作原则》课件
- 初一语文上册《春》解析
- 审计理论与实务考试模拟题+答案(附解析)
- 高等教育学模拟题与参考答案解析
- 2025年1月通信初级工考试题及答案(附解析)
- 自然遗迹保护与国际法律公约考核试卷
- 环境监测与海洋资源合理利用考核试卷
- 老年人休闲活动与康复锻炼考核试卷
- 淀粉产品的质量安全与食品安全管理考核试卷
- 《J采购管理策略培训》课件
- 2025年工程管理试题及答案
- 《电缆状态监测》课件
- 神经鞘瘤MRI诊断要点及鉴别诊断课件
- 青梅绿茶测试题及答案
- GA 1812.2-2024银行系统反恐怖防范要求第2部分:数据中心
- 国家职业技术技能标准 6-31-01-03 电工 人社厅发2018145号
- 2024《整治形式主义为基层减负若干规定》全文课件
- DZ∕T 0227-2010 地质岩心钻探规程(正式版)
- 国有企业合规管理
- XX市农业局文件材料归档范围及文书档案保管期限表【模板】
- 高考物理力学求极值的常用方法
评论
0/150
提交评论