1、学生选修课管理系统C+课程设计#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()
2、; 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.l
3、ianxendl; 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) fl
4、ag1=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;
5、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,
6、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(stud
7、ent); 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(studen
8、t); 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:*en
9、dl; 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*size
10、of(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);
11、 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; s
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1