C学生信息管理系统一卡通_第1页
C学生信息管理系统一卡通_第2页
C学生信息管理系统一卡通_第3页
C学生信息管理系统一卡通_第4页
C学生信息管理系统一卡通_第5页
已阅读5页,还剩24页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、/ 由于对 fsream 的不熟练,不会对指定部分的数据的修改,因而删除了一些功能,同时也导致了只能对消费额进行加减,但不能导入txt 文件。Code:Uni-card system.h#include <string>using namespace std;class personpublic:void buildAdmin();void buildUndergraduate();void buildPostgraduate();protected:char name20;char sex;char shape10;char tel12;class consumer:public

2、 personprotected: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 undergraduate

3、 :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:char monitor;class

4、 postgraduate :public student/定义研究生类public:void searchPostgraduate();void displayPostgraduate();void inputPostgraduate_wrapper();void inputPostgraduate();void inputPostgraduate1();void postPayout(char str);void postSearchAll();protected:double wage;/不清楚教职工是否配备有一卡通,所以暂不考虑教职工类Uni-card system.cpp#inclu

5、de <iostream>#include <cstring>#include <fstream>#include <string>#include <iomanip>#include "uni-card system.h"using namespace std;void onUndergraduate();void onPostgraduate();bool comp(char s1,char s2);void inputStudent();void adminOnLogin();/ 以下为 person 类中成

6、员函数 /void person:buildAdmin()/ 建立 Admin.txtfstream file("Admin.txt",ios:out|ios:app); / 打开文件,指针指向文件尾 file.close(); / 关闭文件void person:buildUndergraduate()/建立 Undergraduate.txtfstream file("Undergraduate.txt",ios:out|ios:app); / 打开文件,指针指向文件尾 file.close(); / 关闭文件void person:buildPos

7、tgraduate()/建立Postgraduate.txtfstream file("Postgraduate.txt",ios:out|ios:app); / 打开文件,指针指向文件尾 file.close(); / 关闭文件/ 以下为 admin 类中成员函数 /void admin:login()/ 管理员登录及验证int ensurance=0;char account212,password212;admin ad; cout << endl<< "管理员登录界面" << endl;cout <<

8、; "请输入您的账号: " ;cin >> account2;cout << "请输入您的密码: " ;cin >> password2;fstream file("Admin.txt",ios:in);/ 打开文件,指针在文件头file.read(char*)&ad,sizeof(ad);/读取类信息while(!file.eof()/判断文件指针是否到文件尾/判断输入的字符if(comp(ad.account,account2)&&comp(ad.password,pas

9、sword2) 是否与文件中的一样cout << "登录成功! " << endl;ensurance=1;break; file.read(char*)&ad,sizeof(ad);/ 如果指针没到文件尾,继续读取file.close();您的账号或密码输入错误! " << endl;/关闭文件/管理员在文件外录入信息管理员注册*" << endl;if(ensurance=0) cout << "file.close();if(ensurance) adminOnLogin

10、();void admin:adminRegister()admin adm;char choose;int loop=1,loop1=1;cout << endl<< "while(loop1)loop1=0;cout << "输入您的账号( 12 位以内) : " cin >> account;fstream file("Admin.txt",ios:in);/ 打开文件,指针在文件头file.read(char*)&adm,sizeof(adm); /读取类信息while(!file

11、.eof()/ 判断文件指针是否到文件尾if(comp(adm.account,account)/ 判断输入的字符是否与文件中的一样cout << "账号已被占用 !" << endl;loop1=1;break;file.read(char*)&adm,sizeof(adm);/ 如果指针没到文件尾,继续读取file.close();cout << "输入您的密码( 12 位以内) : " cin >> password;cout << "输入您的姓名: " cin

12、 >> name;while(loop)cout << "cin >> choose;选择您的性别( A. 男, B. 女) :if(choose='a'|choose='A')sex='m'loop=0;else if(choose='b'|choose='B') sex='f'loop=0;您的输入有误,请重新选择! " << endl;elsecout << "" cin >> te

13、l;strcat(shape,"Admin");cout << "输入您的电话:loop=1;while(loop)cout << "cin >> choose;if(choose='y'|choose='Y')title='y'loop=0;else if(choose='n'|choose='N') title='n'loop=0;elsecout << "void admin:adminRegis

14、ter2()admin ad;ad.adminRegister();fstream file("admin.txt",ios:out|ios:app); / file.write(char*)&ad,sizeof(ad);file.close();cout <<输入您的管理员权限级别,是否为高级( y/n ) :您的输入有误,请重新选择! " << endl;/将管理员信息录入 admin.txt打开文件,指针指向文件尾/把类信息写入文件/关闭文件信息已保存" << endl;/ 以下为 undergradua

15、te 类中成员函数 /void undergraduate:searchUndergraduate()/通过学号及姓名查找学生信息undergraduate unde1;int ensurance=1;char number220,name220;cout << "请输入您所需查询学生的学号: " ;cin >> number2;cout << "请输入该学生的姓名: " ;cin >> name2;fstream file("Undergraduate.txt",ios:in);/打开

16、文件,指针在文件头/读取类信息/判断文件指针是否到文件尾file.read(char*)&unde1,sizeof(unde1);while(!file.eof()if(comp(unde1.number,number2) if(comp(,name2) cout << endl << " "<< endl<< "本科生基本信息查询结果" <<endl; cout << "学号:"<<unde1.number <<

17、;endl;cout << "姓名:"<< << endl;cout << "专业班级:"<< unde1.nowClass <<endl;cout << "年龄:"<<unde1.age << endl;cout << "性别:"if(unde1.sex = 'm') cout << " 男"<< endl; els

18、e if(unde1.sex = 'f') cout << " 女"<< endl; cout << "班干部:"if(unde1.monitor = 'y') cout << " 班长"<< endl; else if(unde1.monitor = 'n') cout << " 无"<< endl; cout << "籍贯:"<< und

19、e1.birthPlace << endl;cout << "电话:"<< unde1.tel << endl;cout << "余额:"<< unde1.money << endl;) else cout << "您所输入姓名与学号不符!" << endl;ensurance=0; break; ) file.read(char*)&unde1,sizeof(unde1);/ 如果指针没到文件尾,继续读取 ) if(e

20、nsurance) cout << "该学号不存在!" << endl;file.close(); ) void undergraduate:outputClassStudent(char s) undergraduate under4;cout << endl<< " "<< endl<< " " << s <<"学生基本信息 " << endl<< " 学号" <&l

21、t; " 姓名" << " 专业班级" << " 班长" << "年龄"<< "性别”<<籍贯"<<电话"<< "余额"<< endl;fstream file("Undergraduate.txt",ios:in);/ 打开文件,指针在文件头file.read(char*)&under4,sizeof(under4); / 读取类信息 whi

22、le(!file.eof()/ 判断文件指针是否到文件尾if(comp(under4.nowClass,s) cout << setw(12) << under4.number << setw(8) << <<setw(16)<< under4.nowClass<< setw(3) << under4.monitor << setw(4)<< under4.age << setw(3) << under4.sex <<

23、; setw(12)<< under4.birthPlace << setw(14) << under4.tel << setw(6) << under4.money << endl;file.read(char*)&under4,sizeof(under4);/ 如果指针没到文件尾,继续读取 file.close();void undergraduate:monitorPower()undergraduate under3;int ensure=0,ensureExit=1;char number220;char

24、 name220;cout << "请输入您的学号:" ;cin >> number2;cout << "请输入您的姓名:" ;cin >> name2;fstream file("Undergraduate.txt",ios:in);/ 打开文件,指针在文件头file.read(char*)&under3,sizeof(under3); / 读取类信息while(!file.eof()/ 判断文件指针是否到文件尾if(comp(under3.number,number2)if(

25、comp(,name2)if(under3.monitor='y')ensure =1 ;else cout << "你不是班长,别冒牌了! " << endl;else cout << "您输入的学号和姓名不符! " << endl;ensureExit=0; break; file.read(char*)&under3,sizeof(under3);/ 如果指针没到文件尾,继续读取file.close();if(ensureExit) cout <&l

26、t; "您所输入的学号不存在! " << endl;if(ensure) outputClassStudent(under3.nowClass);void undergraduate:inputUndergraduate()/管理员录入本科生信息undergraduate undInput;char choose;int loop=1,loop1=1;strcat(shape,"Undergraduate");while(loop1)loop1=0;cout << "学号: " cin >> num

27、ber;fstream file("Undergraduate.txt",ios:in);/ 打开文件,指针在文件头file.read(char*)&undInput,sizeof(undInput);/读取类信息while(!file.eof()/判断文件指针是否到文件尾if(comp(undInput.number,number)/ 判断输入的字符是否与文件中的一样cout << "该学号已经录入 " << endl;loop1=1;break;file.read(char*)&undInput,sizeof(

28、undInput);/ 如果指针没到文件尾,继续读取*/file.close();cout << "cout << "cout << "姓名:" cin>> name;班级:" cin>> nowClass;年龄:" cin>> age;while(loop)cout <<性别( A. 男, B. 女) :cin >> choose;if(choose='a'|choose='A')sex='m

29、9;loop=0;else if(choose='b'|choose='B')sex='f'loop=0;elsecout << "您的输入有误,请重新选择! " << endl;cout <<cout <<籍贯:" cin >> birthPlace;电话:" cin >> tel;money = 0;loop=1; while(loop)cout << "该学生是否为本班级班长( y/n): "cin

30、 >> choose;if(choose='y'|choose='Y')monitor='y'loop=0;else if(choose='n'|choose='N')monitor='n'loop=0;elsecout << "您的输入有误,请重新选择! " << endl;void undergraduate:inputUndergraduate1()/ 管 理 员 本 科 生 信 息 进Undergraduate.txt 文件underg

31、raduate undInput1;undInput1.inputUndergraduate();fstream file("Undergraduate.txt",ios:out|ios:app); / 打开文件,指针指向文件尾file.write(char*)&undInput1,sizeof(undInput1);/把类信息写入文件file.close();/关闭文件cout << "信息已保存" << endl;void undergraduate:inputUndergraduate_wrapper()/OK! 管

32、理员录入本科生信息时单个录入或多个录入char totalChar;int total,loop=1,i;undergraduate underInputWrapper; while(loop)loop=0;cout << "本科生信息录入" << endl;cout << "您想录入多少组信息( 0-9): " ;cin >> totalChar;if(totalChar<'0'|totalChar>'9') cout << "您的输入有误

33、,请重新输入! " << 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;

34、/打开文件,指针在文件头/读取类信息/判断文件指针是否到文件尾undergraduate undePay1;fstream file("Undergraduate.txt",ios:in);file.read(char*)&undePay1,sizeof(undePay1); while(!file.eof()if(comp(undePay1.number,str) cout << "您的姓名为: " << undeP << " ? (y/n )" ;while(1) cin

35、 >> choose;if(choose='y'|choose='Y')cout << "您本次消费/充卡金额为(消费为正值,充卡为负值) : "cin >> payMoney;undePay1.money -= payMoney;cout << "您的余额为: " << undePay1.money <<endl;break;else if (choose='n'|choose='N') break;else cout

36、 << "您的输入错误" << endl; break;file.read(char*)&undePay1,sizeof(undePay1);/ 如果指针没到文件尾,继续读取 void undergraduate:underSearchAll() undergraduate under5; cout << endl<< "" << endl<< "本科生基本信息" << endl<< " 学号 " <<

37、; " 姓名 " << " 专业班级 " << " 班长 " << " 年龄 " << " 性别 "<< " 籍贯 " << " 电话 " << " 余额 " << endl;fstream file("Undergraduate.txt",ios:in);/ 打开文件,指针在文件头file.read(char*)&

38、;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&l

39、t;< setw(12)<< under5.birthPlace << setw(14) << under5.tel << setw(6) << under5.money << endl;file.read(char*)&under5,sizeof(under5);/ 如果指针没到文件尾,继续读取file.close();/ 以下为 postgraduate 类中成员函数/void postgraduate:searchPostgraduate()postgraduate post1;int ensuranc

40、e=1;char number220,name220;cout << "cin >> number2;cout << "cin >> name2;cout << endl<< "<< "/通过学号及姓名查找学生信息请输入您所需查询学生的学号:请输入该学生的姓名: " ;<< endl研究生基本信息查询结果" << endl;/打开文件,指针在文件头/读取类信息/判断文件指针是否到文件尾您所输入姓名与学号不符! " &l

41、t;< endl;fstream file("Postgraduate.txt",ios:in);file.read(char*)&post1,sizeof(post1);while(!file.eof()if(comp(post1.number,number2)if(comp(,name2)post1.displayPostgraduate();else cout << " ensurance=0;break;file.read(char*)&post1,sizeof(post1);/ 如果指针没到文件尾,继

42、续读取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 << "学号: " cin >> number;fstream f

43、ile("Postgraduate.txt",ios:in);/ 打开文件,指针在文件头file.read(char*)&postInput,sizeof(postInput);/读取类信息while(!file.eof()/ 判断文件指针是否到文件尾 if(comp(postInput.number,number)/ 判断输入的字符是否与文件中的一样cout << "该学号已经录入 " << endl;loop1=1;break;*/file.read(char*)&postInput,sizeof(postIn

44、put);/ 如果指针没到文件尾,继续读取 file.close();cout <<cout <<cout <<姓名:" cin>> name;班级:" cin>> nowClass;年龄:" cin>> age;while(loop)性别( A. 男, B. 女) :cout << "cin >> choose;if(choose='a'|choose='A') sex='m'loop=0;else if(ch

45、oose='b'|choose='B') sex='f'loop=0;elsecout <<您的输入有误,请重新选择! " << endl;cout << "籍贯:cout << "电话:cout << "工资:money = 0;loop=1;void postgraduate:inputPostgraduate1() 文件" cin >> birthPlace;" cin >> tel;"

46、cin >> wage;/管理员本科生信息进Undergraduate.txtpostgraduate postInput1;postInput1.inputPostgraduate();fstream file("Postgraduate.txt",ios:out|ios:app); / 打开文件,指针指向文件尾file.write(char*)&postInput1,sizeof(postInput1);/把类信息写入文件file.close();/关闭文件cout << "信息已保存" << endl;v

47、oid postgraduate:inputPostgraduate_wrapper()/OK! 管理员录入本科生信息时单个录入或多个录入char totalChar;int total,loop=1,i;postgraduate postInputWrapper;while(loop)loop=0;cout << "研究生信息录入" << endl;cout << "您想录入多少组信息( 0-9): " ;cin >> totalChar;if(totalChar<'0'|total

48、Char>'9')cout << "您的输入有误,请重新输入! " << endl;loop = 1;continue;total = totalChar-'0'for(i = 0; i < total; i+)cout << "第" << i+1 << " 位同学: " << endl;postInputWrapper.inputPostgraduate1() ;void postgraduate:postSearch

49、All()cout << endl<< "" << endl<< "研究生基本信息" << endl;postgraduate post3;fstream file("Postgraduate.txt",ios:in);/ 打开文件,指针在文件头 file.read(char*)&post3,sizeof(post3);/读取类信息while(!file.eof()/ 判断文件指针是否到文件尾cout << endl;post3.displayPostgr

50、aduate(); file.read(char*)&post3,sizeof(post3);/ 如果指针没到文件尾,继续读取 file.close();void postgraduate:displayPostgraduate()/ 对研究生信息进行显示cout << "学号: " << number <<endl;cout << "姓名:cout << "研究方向:cout << "年龄:cout << "性别:if(sex = '

51、m') cout << " 男 " << endl;else if(sex = 'f') cout << " 女" << endl;cout << "工资:cout << "籍贯:cout << "电话:cout << "余额: void postgraduate:postPayout(char str) char choose;double payMoney;postgraduate postP

52、ay1;fstream file("Postgraduate.txt",ios:in);file.read(char*)&postPay1,sizeof(postPay1); while(!file.eof() if(comp(postPay1.number,str) cout << ":while(1) < < name << endl;" << nowClass <<endl;< < age << endl;< < wage << en

53、dl;< < birthPlace << endl;< < tel << endl;< < money << endl;/打开文件,指针在文件头/读取类信息/判断文件指针是否到文件尾< < postP << " ?( y/n )cin >> choose;if(choose='y'|choose='Y')cout <<您本次消费 /充卡金额为(消费为正值,充卡为负值) : "cin >> payM

54、oney;postPay1.money -= payMoney;cout << "您的余额为: " << postPay1.money <<endl;break;else if (choose='n'|choose='N') break;else cout << "您的输入错误" << endl; break; file.read(char*)&postPay1,sizeof(postPay1);/ 如果指针没到文件尾,继续读取 Main.cpp#incl

55、ude <iostream>#include <stdlib.h>#include <fstream>#include <iomanip>#include "uni-card system.h"using namespace std;void onUndergraduate();void onPostgraduate();void inputStudent();void payOut();void searchLeftMoney();bool comp(char s1,char s2)/比较文件中字符和输入的字符是否相同int

56、 i=0;while(s1i!='0'&&s2i!='0'&&s1i=s2i)i+;if(s1i='0'&&s2i='0')return 1; elsereturn 0;void mainMenu()/输入主目录cout << "" << endl<<一卡通管理系统<< endl<< " " << endl<< "1.学生基本信息查询 " &

57、lt;< endl<< "2.消费信息查询与消费 " << endl<< "3.后台管理 " << endl<< "0.退出本系统 " << endl<< " " << endl<< "" << endl << endl<< "请选择您的操作(0-3):")void consumerMenu()(int loop=1;char

58、choose;while(loop)(cout << " «"endl<< "消费信息管理"<< endl<< " " << endl<< "1.消费/充卡 " << endl 消费的数额为负值即为充卡<< "0.返回上级目录 " << endl<< " " << endl<< ""<< en

59、dl <<endl<< "请选择您的操作(0-2):"cin >> choose;while(choose>'3'|choose<'0')(cout << "您的输入有误,请重新选择!" << endl;cout << "请选择您的操作(0-2):"cin >> choose;)switch(choose)(case '1': payOut();continue;case '2'

60、;: continue;case '0': loop=0;break;)void payOut()(char number120;undergraduate underl;postgraduate postPayout;cout << " " << endl<< "一卡通便捷支出" << endl<< "请输入您的学号:"cin >> numberl;if(number10='1'&&number11=T&&

61、amp;number12='1') postPayout.postPayout(number1);else if(number10='2'&&number11='2'&&number12='2') under1.underPayout(number1);else cout << "您输入的学号有误! " << endl;void studentSelectMenu()/阶段选择处的子目录及处理 int loop=1;char choose;while(lo

62、op)cout << " «"endlendl<< "学生基本信息与查询"<< endl<< " " << endl<< "1.本科生 " << endl<< "2.研究生 " << endl<< "0.返回上级目录 " << endl<< " " << endl<< "

63、"<< endl <<<< "请输入您所处阶段(0-2):"cin >> choose;while(choose>'2'|choose<'0')cout << "您的输入有误,请重新选择!" << endl;cout << "请选择您的操作(0-2):"cin >> choose;switch(choose)case '1': onUndergraduate();cont

64、inue;case '2': onPostgraduate();continue;case '0': loop=0;break;void adminMenuQ/管理员进入处的子目录及处理endlint loop=1;char choose;admin admi;while(loop)cout «I!管理员界面"« endl "« endl1 .已有账号,马上登录 "« endl2.没有账号?感觉注册吧! "« endl0.返回上级目录 "« endl &

65、quot;« endl" « endl «endl« "请选择您的操作(0-2):cin » choose;while(choose>'2'|choose<'0")(cout « "您的输入有误,请重新选择! " « endl;cout « "请选择您的操作(0-2):cin » choose;)switch (choose)(case '1': admi.login();continue;ca

66、se 2: admi.adminRegister2();continue;case 'O': loop=0;break;void adminSearchMenu()int loop=1;char choose;undergraduate underSearchALL;postgraduate postSearchAII;while(loop)cout «I!学生信息查询"« endlendl<< " " << endl<< "1.本科生 " << endl<

67、;< "2.研究生 " << endl<< "0.返回上级目录 " << endl<< " " << endl< < "" << endl <<endl< < "请选择您所需查tU学生的阶段(0-2):"cin >> choose; while(choose>'2'|choose<'0') ( cout << "您的输入有误,请重新选择!" << endl;cout <&

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论