图书管理系统c++版_数据结构课程设计.docx
#include<iostream.h> #include<fstream.h>#include<iomanip.h>static int n=0;int comp(char*,char*);class studentpublic: void getdata() tag='#' cout<<"(姓名 身份证号码 班级 成绩):" cin>>name>>number>>Class>>score; char gettag() return tag; void disp() if(tag='#') cout<<setiosflags(ios:left) <<setw(10)<<name<<setw(18)<<number<<setw(20)<<Class<<setw(20)<<score<<endl; char *getname() return name; private: char tag; char name12; char number18; char Class20; char score6;class teacherpublic: void getdata() tag='#' cout<<"(姓名 身份证号码 职称 学院):" cin>>name>>number>>zhichen>>xueyuan; char gettag() return tag; void disp() if(tag='#') cout<<setiosflags(ios:left) <<setw(10)<<name<<setw(18)<<number<<setw(20)<<zhichen<<setw(20)<<xueyuan<<endl; char *getname() return name; private: char tag; char name12; char number18; char zhichen20; char xueyuan30;class studentteacherpublic: void getdata() tag='#' cout<<"(姓名 身份证号码 班级 成绩 职称 学院):" cin>>name>>number>>Class>>score>>zhichen>>xueyuan; char gettag() return tag; void disp() if(tag='#') cout<<setiosflags(ios:left) <<setw(10)<<name<<setw(18)<<number<<setw(20)<<Class<<setw(20)<<score<<setw(20)<<zhichen<<setw(20)<<xueyuan<<endl; char *getname() return name; private: char tag; char name12; char number18; char Class20; double score; char zhichen20; char xueyuan30;void func1() ofstream output("MyFrd.dat"); student s; cout<<"输入数据"<<endl; cout<<"学生人数:" cin>>n; for(int i=0;i<n;i+) cout<<"第"<<i+1<<"个学生" s.getdata(); output.write(char *)&s,sizeof(s); output.close();void func2() ifstream input("MyFrd.dat"); student s; cout<<"输出数据"<<endl; cout<<setiosflags(ios:left) <<setw(10)<<"姓名"<<setw(18)<<"身份证号码"<<setw(20)<<"班级"<<setw(6)<<"成绩"<<endl; input.read(char *)&s,sizeof(s); while(input) s.disp(); input.read(char*)&s,sizeof(s); input.close();void func3() char sname10; ifstream file("MyFrd.dat"); student one; file.seekg(0); cout<<"输入要查询的姓名(可只输入姓氏):" cin>>sname; cout<<"输出查询结果:"<<endl; cout<<setiosflags(ios:left) <<setw(10)<<"姓名"<<setw(18)<<"身份证号码"<<setw(20)<<"班级"<<setw(6)<<"成绩"<<endl; file.read(char*)&one,sizeof(one); while(file) if(comp(one.getname(),sname)=1) one.disp(); file.read(char*)&one,sizeof(one); file.close();void func4() fstream outapp("MyFrd.dat",ios:app); student one; cout<<"添加数据:" one.getdata(); outapp.write(char*)&one,sizeof(one); outapp.close();void func5() char sname12; int i=0; fstream outdel("MyFrd.dat",ios:in|ios:out); student one; outdel.seekg(0); cout<<"输入要删除的姓名(可只输入姓氏):" cin>>sname; while(!outdel.eof() outdel.seekp(sizeof(student)*i); outdel.read(char *)&one,sizeof(one); if(comp(one.getname(),sname)=1&&one.gettag()='#') outdel.seekp(sizeof(student) *i); outdel.put('*'); i+; outdel.close();void func6() fstream outdel("student.dat",ios:in); fstream temp("temp",ios:out|ios:trunc); student s; while(!outdel.eof() outdel.read(char *)&s,sizeof(student); if(s.gettag()='#') temp.write(char *)&s,sizeof(student); outdel.close(); temp.close(); fstream outdel1("MyFrd.dat",ios:out|ios:trunc); fstream temp1("temp",ios:in); while(!temp1.eof() temp1.read(char *)&s,sizeof(student); outdel1.write(char *)&s,sizeof(student); outdel1.close(); temp1.close(); cout<<"此记录已物理删除"<<endl;void func7() ofstream output("MyFrd1.dat"); teacher s; cout<<"输入数据"<<endl; cout<<"教师人数:" cin>>n; for(int i=0;i<n;i+) cout<<"第"<<i+1<<"个教师" s.getdata(); output.write(char *)&s,sizeof(s); output.close();void func8() ifstream input("MyFrd1.dat"); teacher s; cout<<"输出数据"<<endl; cout<<setiosflags(ios:left) <<setw(10)<<"姓名"<<setw(18)<<"身份证号码"<<setw(20)<<"职称"<<setw(20)<<"学院"<<endl; input.read(char *)&s,sizeof(s); while(input) s.disp(); input.read(char*)&s,sizeof(s); input.close();void func9() char sname10; ifstream file("MyFrd1.dat"); teacher one; file.seekg(0); cout<<"输入要查询的姓名(可只输入姓氏):" cin>>sname; cout<<"输出查询结果:"<<endl; cout<<setiosflags(ios:left) <<setw(10)<<"姓名"<<setw(18)<<"身份证号码"<<setw(20)<<"职称"<<setw(20)<<"学院"<<endl; file.read(char*)&one,sizeof(one); while(file) if(comp(one.getname(),sname)=1) one.disp(); file.read(char*)&one,sizeof(one); file.close();void func0() fstream outapp("MyFrd.dat1",ios:app); teacher one; cout<<"添加数据:" one.getdata(); outapp.write(char*)&one,sizeof(one); outapp.close();void func01() char sname12; int i=0; fstream outdel("MyFrd1.dat",ios:in|ios:out); teacher one; outdel.seekg(0); cout<<"输入要删除的姓名(可只输入姓氏):" cin>>sname; while(!outdel.eof() outdel.seekp(sizeof(teacher)*i); outdel.read(char *)&one,sizeof(one); if(comp(one.getname(),sname)=1&&one.gettag()='#') outdel.seekp(sizeof(teacher) *i); outdel.put('*'); i+; outdel.close();void func02() fstream outdel("teacher.dat",ios:in); fstream temp("temp",ios:out|ios:trunc); teacher s; while(!outdel.eof() outdel.read(char *)&s,sizeof(teacher); if(s.gettag()='#') temp.write(char *)&s,sizeof(teacher); outdel.close(); temp.close(); fstream outdel1("MyFrd1.dat",ios:out|ios:trunc); fstream temp1("temp",ios:in); while(!temp1.eof() temp1.read(char *)&s,sizeof(teacher); outdel1.write(char *)&s,sizeof(teacher); outdel1.close(); temp1.close(); cout<<"此记录已物理删除"<<endl;void func03() ofstream output("MyFrd2.dat"); studentteacher s; cout<<"输入数据"<<endl; cout<<"学生人数:" cin>>n; for(int i=0;i<n;i+) cout<<"第"<<i+1<<"个学生" s.getdata(); output.write(char *)&s,sizeof(s); output.close();void func04() ifstream input("MyFrd2.dat"); studentteacher s; cout<<"输出数据"<<endl; cout<<setiosflags(ios:left) <<setw(10)<<"姓名"<<setw(18)<<"身份证号码"<<setw(20)<<"班级"<<setw(20)<<"成绩"<<setw(20)<<"职称"<<setw(20)<<"学院"<<endl; input.read(char *)&s,sizeof(s); while(input) s.disp(); input.read(char*)&s,sizeof(s); input.close();void func05() char sname10; ifstream file("MyFrd2.dat"); studentteacher one; file.seekg(0); cout<<"输入要查询的姓名(可只输入姓氏):" cin>>sname; cout<<"输出查询结果:"<<endl; cout<<setiosflags(ios:left) <<setw(10)<<"姓名"<<setw(18)<<"身份证号码"<<setw(20)<<"班级"<<setw(6)<<"成绩"<<endl; file.read(char*)&one,sizeof(one); while(file) if(comp(one.getname(),sname)=1) one.disp(); file.read(char*)&one,sizeof(one); file.close();void func06() fstream outapp("MyFrd2.dat",ios:app); studentteacher one; cout<<"添加数据:" one.getdata(); outapp.write(char*)&one,sizeof(one); outapp.close();void func07() char sname12; int i=0; fstream outdel("MyFrd2.dat",ios:in|ios:out); studentteacher one; outdel.seekg(0); cout<<"输入要删除的姓名(可只输入姓氏):" cin>>sname; while(!outdel.eof() outdel.seekp(sizeof(studentteacher)*i); outdel.read(char *)&one,sizeof(one); if(comp(one.getname(),sname)=1&&one.gettag()='#') outdel.seekp(sizeof(studentteacher) *i); outdel.put('*'); i+; outdel.close();void func08() fstream outdel("studentteacher.dat",ios:in); fstream temp("temp",ios:out|ios:trunc); studentteacher s; while(!outdel.eof() outdel.read(char *)&s,sizeof(studentteacher); if(s.gettag()='#') temp.write(char *)&s,sizeof(studentteacher); outdel.close(); temp.close(); fstream outdel1("MyFrd2.dat",ios:out|ios:trunc); fstream temp1("temp",ios:in); while(!temp1.eof() temp1.read(char *)&s,sizeof(studentteacher); outdel1.write(char *)&s,sizeof(studentteacher); outdel1.close(); temp1.close(); cout<<"此记录已物理删除"<<endl;void func09() char sname10; ifstream file("MyFrd.dat"); student one; file.seekg(0); cout<<"输入要修改的姓名(可只输入姓氏):" cin>>sname; cout<<"输出查询结果:"<<endl; cout<<setiosflags(ios:left) <<setw(10)<<"姓名"<<setw(18)<<"身份证号码"<<setw(20)<<"班级"<<setw(6)<<"成绩"<<endl; file.read(char*)&one,sizeof(one); while(file) if(comp(one.getname(),sname)=1) one.disp(); file.read(char*)&one,sizeof(one); file.close(); ofstream output("MyFrd.dat"); student s; cout<<"重新输入数据:"<<endl; s.getdata(); output.write(char *)&s,sizeof(s); output.close();void func10() char sname10; ifstream file("MyFrd1.dat"); teacher one; file.seekg(0); cout<<"输入要修改的姓名(可只输入姓氏):" cin>>sname; cout<<"输出查询结果:"<<endl; cout<<setiosflags(ios:left) <<setw(10)<<"姓名"<<setw(18)<<"身份证号码"<<setw(20)<<"班级"<<setw(6)<<"成绩"<<endl; file.read(char*)&one,sizeof(one); while(file) if(comp(one.getname(),sname)=1) one.disp(); file.read(char*)&one,sizeof(one); file.close(); ofstream output("MyFrd1.dat"); teacher s; cout<<"重新输入数据:"<<endl; s.getdata(); output.write(char *)&s,sizeof(s); output.close();void func11() char sname10; ifstream file("MyFrd2.dat"); studentteacher one; file.seekg(0); cout<<"输入要修改的姓名(可只输入姓氏):" cin>>sname; cout<<"输出查询结果:"<<endl; cout<<setiosflags(ios:left) <<setw(10)<<"姓名"<<setw(18)<<"身份证号码"<<setw(20)<<"班级"<<setw(6)<<"成绩"<<endl; file.read(char*)&one,sizeof(one); while(file) if(comp(one.getname(),sname)=1) one.disp(); file.read(char*)&one,sizeof(one); file.close(); ofstream output("MyFrd2.dat"); studentteacher s; cout<<"重新输入数据:"<<endl; s.getdata(); output.write(char *)&s,sizeof(s); output.close();int comp(char s1,char s2) int i=0; while(s1i!='0'&&s2i!='0'&&s1i=s2i) i+; if(s1i='0'|s2i='0') return 1; else return 0;void main() int sel; do cout<<"请输入(1:输入数据 2:输出数据 3:按姓名查询"<<endl<<"4:添加数据 5:逻辑删除 6:物理删除 7:修改记录 其它退出" cin>>sel; switch(sel) case 1: char a,b; while(1) cout<<"请输入你所选择的操作对象(学生(1),老师(2),研究生(3):" cin>>a; if(a='1') func1(); else if(a='2') func7(); else if(a='3') func03(); else cout<<"输入错误!"<<endl; cout<<"继续吗?(Y/N)" cin>>b; while(b!='y'&&b!='Y'&&b!='n'&&b!='N') cout<<"对不起,你输入错误!请重新输入:" cin>>b; if(b='n'|b='N') break; break; case 2: char c,d; while(1) cout<<"请输入你所选择的操作对象(学生(1),老师(2),研究生(3):" cin>>c; if(c='1') func2(); else if(c='2') func8(); else if(c='3') func04(); else cout<<"输入错误!"<<endl; cout<<"继续吗?(Y/N)" cin>>d; while(d!='y'&&d!='Y'&&d!='n'&&d!='N') cout<<"对不起,你输入错误!请重新输入:" cin>>d; if(d='n'|d='N') break; break; case 3: char e,f; while(1) cout<<"请输入你所选择的操作对象(学生(1),老师(2),研究生(3):" cin>>e; if(e='1') func3(); else if(e='2') func9(); else if(e='3') func04(); else cout<<"输入错误!"<<endl; cout<<"继续吗?(Y/N)" cin>>f; while(b!='y'&&b!='Y'&&b!='n'&&b!='N') cout<<"对不起,你输入错误!请重新输入:" cin>>f; if(f='n'|f='N') break; break; case 4: char g,h; while(1) cout<<"请输入你所选择的操作对象(学生(1),老师(2),研究生(3):" cin>>g; if(g='1') func4(); else if(g='2') func0(); else if(g='3') func06(); else cout<<"输入错误!"<<endl; cout<<"继续吗?(Y/N)" cin>>h; while(h!='y'&&h!='Y'&&h!='n'&&h!='N') cout<<"对不起,你输入错误!请重新输入:" cin>>h; if(h='n'|h='N') break; break; case 5: char m,n; while(1) cout<<"请输入你所选择的操作对象(学生(1),老师(2),研究生(3):" cin>>m; if(m='1') func5(); else if(m='2') func01(); else if(m='3') func07(); else cout<<"输入错误!"<<endl; cout<<"继续吗?(Y/N)" cin>>n; while(n!='y'&&n!='Y'&&n!='n'&&n!='N') cout<<"对不起,你输入错误!请重新输入:" cin>>n; if(n='n'|n='N') break; break; case 6: char x,z; while(1) cout<<"请输入你所选择的操作对象(学生(1),老师(2),研究生(3):" cin>>x; if(x='1') func6(); else if(x='2') func02(); else if(x='3') func08(); else cout<<"输入错误!"<<endl; cout<<"继续吗?(Y/N)" cin>>z; while(z!='y'&&z!='Y'&&z!='n'&&z!='N') cout<<"对不起,你输入错误!请重新输入:" cin>>z; if(z='n'|z='N') break; break; case 7: char s,t; while(1) cout<<"请输入你所选择的操作对象(学生(1),老师(2),研究生(3):" cin>>s; if(s='1') func09(); else if(s='2') func10(); else if(s='3') func11(); else cout<<"输入错误!"<<endl; cout<<"继续吗?(Y/N)" cin>>t; while(t!='y'&&t!='Y'&&t!='n'&&t!='N') cout<<"对不起,你输入错误!请重新输入:" cin>>t; if(t='n'|t='N') break; break; default: cout<<"输入错误!"<<endl; break; while(sel>=1&&sel<=6);