学生选修课管理系统 C++课程设计.doc_第1页
学生选修课管理系统 C++课程设计.doc_第2页
学生选修课管理系统 C++课程设计.doc_第3页
学生选修课管理系统 C++课程设计.doc_第4页
学生选修课管理系统 C++课程设计.doc_第5页
已阅读5页,还剩50页未读 继续免费阅读

下载本文档

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

文档简介

#include #include#include#include #include /using namespace std;const int count =3;class situaction;class student public: int sno; char sname20; char sex3; int age; char depart20; char classno20; char lianx40; /public: friend void sselect(); friend void supdate(); friend void sdelet(); friend void saccount(); friend void sdisplay(); friend istream & operator (istream & in,student &stu) instu.snostu.snamestu.sexstu.agestu.departstu.classnostu.lianx; return in; friend ostream & operator ( ostream & out,student &stu) outstu.sno stu.sname stu.sex stu.age stu.depart stu.classno stu.lianxendl; return out; friend void xkadd(); friend void sadd();void sadd() while(1)int flag1=0; student s; cout请输入要添加的学生的学号、姓名、性别、年龄、系别、班级、联系方式s; ifstream in(e:studentfile.txt); if(!in) cout打开学生信息文件失败!endl; return ; student stu; in.read(char*)&stu,sizeof(student); while(!in.eof() if(s.sno=stu.sno) flag1=1; break; in.read(char*)&stu,sizeof(student); in.close(); if(flag1=1) cout该学生已经在文件中存在不允许添加! endl; else ofstream out(e:studentfile.txt,ios:app); out.write(char*)&s,sizeof(student); out.close(); system(pause); break;void sselect() while(1) system(cls); cout*请选择要查询的类别:*endl; cout* 按学生学号 请按1:* endl; cout* 按学生姓名 请按2:*endl; cout* 按学生系别 请按3:*endl; cout* 按学生班级 请按4:*endl; cout* 返回上一级界面 请按5:*sn; while(sn5|sn1) cout选择的数据无效,请重新输入:sn; coutendl; ifstream in(e:studentfile.txt); if(!in) cout打开学生信息文件失败!endl; return ; int flag=0; switch(sn) case 1: int no; cout请输入要查询的学生的学号no; student stu; in.read(char*)&stu,sizeof(student); while(!in.eof() if(no=stu.sno) coutstuendl; flag=1; in.read(char*)&stu,sizeof(student); break; case 2: char name20; cout请输入要查询的学生的姓名name; student stu; in.read(char*)&stu,sizeof(student); while(!in.eof() if(strcpy(name,stu.sname)=0) coutstuendl; flag=1; in.read(char*)&stu,sizeof(student); break; case 3: char dep20; cout请输入要查询的学生的系别dep; student stu; in.read(char*)&stu,sizeof(student); while(!in.eof() if(strcmp(dep,stu.depart)=0) coutstuendl; flag=1; in.read(char*)&stu,sizeof(student); break; case 4: char clno20; cout请输入要查询的学生的班级clno; student stu; in.read(char*)&stu,sizeof(student); while(!in.eof() if(strcmp(clno,stu.classno)=0) coutstuendl; flag=1; in.read(char*)&stu,sizeof(student); break; case 5: return ; in.close(); if(flag=0) cout要查询的学生在文件不存在! endl; system(pause); void supdate() while(1) system(cls); cout*请选择按下列类别查询后修改:*endl; cout* 按学生学号 请按1:* endl; cout* 按学生姓名 请按2:*endl; cout* 按学生系别 请按3:*endl; cout* 按学生班级 请按4:*endl; cout* 返回上一级界面 请按5:*sn; while(sn5|sn1) cout选择的数据无效,请重新输入:sn; coutendl; fstream in(e:studentfile.txt,ios:in|ios:out); if(!in) cout打开学生信息文件失败!endl; return ; int flag=0; switch(sn) case 1: int no; cout请输入要查询的学生的学号no; student stu; int i=0; in.seekg(i*sizeof(student),ios:beg); in.read(char*)&stu,sizeof(student); while(!in.eof() if(no=stu.sno) coutstuendl; cout请输入要修改的学生的学号、姓名、性别、年龄、系别、班级、联系方式stu; in.seekp(i*sizeof(student),ios:beg); in.write(char*)&stu,sizeof(student); flag=1; i+; in.seekg(i*sizeof(student),ios:beg); in.read(char*)&stu,sizeof(student); break; case 2: case 3: case 4: case 5: return ; in.close(); if(flag=0) cout要修改的学生在文件不存在! endl; system(pause); void sdelet() while(1) system(cls); cout*请选择按下列类别查询后删除:*endl; cout* 按学生学号 请按1:* endl; cout* 按学生姓名 请按2:*endl; cout* 按学生系别 请按3:*endl; cout* 按学生班级 请按4:*endl; cout* 返回上一级界面 请按5:*sn; while(sn5|sn1) cout选择的数据无效,请重新输入:sn; coutendl; student stu20; int flag=0; switch(sn) case 1: ifstream in(e:studentfile.txt); if(!in) cout打开学生信息文件失败!endl; return ; int n=0; in.read(char*)&stun,sizeof(student); while(!in.eof() n+; in.read(char*)&stun,sizeof(student); in.close(); int no; cout请输入要删除的学生的学号no; for(int i=0;in;i+) if(no=stui.sno) coutstuiendl; cout是否要删除该学生的信息!ch; if( ch=Y|ch=y) for(int j=i;jn;j+) stuj=stuj+1; n-; flag=1; if(flag=0) cout要修改的学生在文件不存在! endl; else ofstream out(e:studentfile.txt); if(!out) cout打开学生信息文件失败!endl; return ; for(int k=0;kn;k+) out.seekp(k*sizeof(student),ios:beg); out.write(char*)&stuk,sizeof(student); out.close(); break; case 2: case 3: case 4: case 5: return ; system(pause); void saccount() ifstream ifs(e:studentfile.txt); if(!ifs) cout打开文件失败!; system(pause); return ; int i=0; student s; ifs.read(char*)&s,sizeof(student); while(!ifs.eof() i+; ifs.read(char*)&s,sizeof(student); ifs.close(); cout学生:i人endl; ifs.close(); system(pause); void sdisplay() ifstream in(e:studentfile.txt,ios:in); if(!in) cout打开学生信息文件失败!endl; return ; student stu; in.read(char*)&stu,sizeof(student); while(!in.eof() coutstu (istream & in, course &cou) amecou.cxzcou.zxscou.xfcou.kcxqcou.xxrs; return in; friend ostream & operator (ostream & out,course &cou) o ame cou.cxz cou.zxs cou.xf cou.kcxq cou.xxrsendl; return out; friend void xkadd();void cadd() int flag1=0; course c; cout请输入要添加的课程的课程代码、课程名称、课程性质、总学时、学分、开课学期、选修人数c; ifstream in(e:coursefile.txt); if(!in) cout打开课程信息文件失败!endl; return ; course cou; in.read(char*)&cou,sizeof(course); while(!in.eof() if(o=o) flag1=1; break; in.read(char*)&cou,sizeof( course); in.close(); if(flag1=1) cout该课程已经在文件中存在不允许添加! endl; else ofstream out(e:coursefile.txt,ios:app); out.write(char*)&c,sizeof(course); out.close(); system(pause); void cselect()while(1) system(cls); cout* 请选择要查询的类别:*endl; cout* 按课程编号 请按1:* endl; cout* 按课程名称 请按2:*endl; cout* 返回上一级界面 请按3:*sn; while(sn3|sn1) cout选择的数据无效,请重新输入:sn; coutendl; ifstream in(e:coursefile.txt); if(!in) cout打开课程信息文件失败!endl; return ; int flag=0; switch(sn) case 1: int no; cout请输入要查询的课程的编号no; course ke; in.read(char*)&ke,sizeof(course); while(!in.eof() if(no=o) coutkeendl; flag=1; in.read(char*)&ke,sizeof(course); /if(no=ke. char*)&ke,sizeof(course); break; case 2: char name25; cout请输入要查询的课程的名称name; course ke; in.read(char*)&ke,sizeof(course); while(!in.eof() if(strcpy(name,ame)=0) coutkeendl; flag=1; in.read(char*)&ke,sizeof(course); break; case 3: return ; in.close(); if(flag=0) cout要查询的课程在文件不存在! endl; system(pause);void cupdate() while(1) system(cls); cout*请选择按下列类别查询后修改:*endl; cout* 按课程编号 请按1:* endl; cout* 按课程名称 请按2:*endl; cout* 按课程性质 请按3:*endl; cout* 按课程学分 请按4:*endl; cout* 返回上一级界面 请按5:*sn; while(sn5|sn1) cout选择的数据无效,请重新输入:sn; coutendl; fstream in(e:studentfile.txt,ios:in|ios:out); if(!in) cout打开课程信息文件失败!endl; return ; int flag=0; switch(sn) case 1: int no; cout请输入要查询的课程的编号no; course k; int i=0; in.seekg(i*sizeof(course),ios:beg); in.read(char*)&k,sizeof(course); while(!in.eof() if(no=o) coutkendl; cout请输入要修改的课程的编号,名称,性质,学分k; in.seekp(i*sizeof(course),ios:beg); in.write(char*)&k,sizeof(course); flag=1; i+; in.seekg(i*sizeof(course),ios:beg); in.read(char*)&k,sizeof(course); break; case 2: int no; cout请输入要查询的学生的学号no; student stu; int i=0; in.seekg(i*sizeof(student),ios:beg); in.read(char*)&stu,sizeof(student); while(!in.eof() if(no=s

温馨提示

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

评论

0/150

提交评论