《图书管理系统c++版_数据结构课程设计.docx》由会员分享,可在线阅读,更多相关《图书管理系统c++版_数据结构课程设计.docx(13页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、#include#include#includestaticintn=0;intcomp(char*,char*);classstudentpublic:voidgetdata()tag=#;coutnamenumberClassscore;chargettag()returntag;voiddisp()if(tag=#)coutsetiosflags(ios:left)setw(10)namesetw(18)numbersetw(20)Classsetw(20)scoreendl;char*getname()returnname;private:chartag;charname12;char
2、number18;charClass20;charscore6;classteacherpublic:voidgetdata()tag=#;coutnamenumberzhichenxueyuan;chargettag()returntag;voiddisp()if(tag=#)coutsetiosflags(ios:left)setw(10)namesetw(18)numbersetw(20)zhichensetw(20)xueyuanendl;char*getname()returnname;private:chartag;charname12;charnumber18;charzhich
3、en20;charxueyuan30;classstudentteacherpublic:voidgetdata()tag=#;coutnamenumberClassscorezhichenxueyuan;chargettag()returntag;voiddisp()if(tag=#)coutsetiosflags(ios:left)setw(10)namesetw(18)numbersetw(20)Classsetw(20)scoresetw(20)zhichensetw(20)xueyuanendl;char*getname()returnname;private:chartag;cha
4、rname12;charnumber18;charClass20;doublescore;charzhichen20;charxueyuan30;voidfunc1()ofstreamoutput(MyFrd.dat);students;cout输入数据endl;coutn;for(inti=0;in;i+)cout第i+1个学生;s.getdata();output.write(char*)&s,sizeof(s);output.close();voidfunc2()ifstreaminput(MyFrd.dat);students;cout输出数据endl;coutsetiosflags(
5、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();voidfunc3()charsname10;ifstreamfile(MyFrd.dat);studentone;file.seekg(0);coutsname;cout输出查询结果:endl;coutsetiosflags(ios:left)setw(10)姓名setw(18)身份证号码set
6、w(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();voidfunc4()fstreamoutapp(MyFrd.dat,ios:app);studentone;cout添加数据:;one.getdata();outapp.write(char*)&one,sizeof(one);outapp.close();voidfunc5()charsn
7、ame12;inti=0;fstreamoutdel(MyFrd.dat,ios:in|ios:out);studentone;outdel.seekg(0);coutsname;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();voidfunc6()fst
8、reamoutdel(student.dat,ios:in);fstreamtemp(temp,ios:out|ios:trunc);students;while(!outdel.eof()outdel.read(char*)&s,sizeof(student);if(s.gettag()=#)temp.write(char*)&s,sizeof(student);outdel.close();temp.close();fstreamoutdel1(MyFrd.dat,ios:out|ios:trunc);fstreamtemp1(temp,ios:in);while(!temp1.eof()
9、temp1.read(char*)&s,sizeof(student);outdel1.write(char*)&s,sizeof(student);outdel1.close();temp1.close();cout此记录已物理删除endl;voidfunc7()ofstreamoutput(MyFrd1.dat);teachers;cout输入数据endl;coutn;for(inti=0;in;i+)cout第i+1个教师;s.getdata();output.write(char*)&s,sizeof(s);output.close();voidfunc8()ifstreaminput
10、(MyFrd1.dat);teachers;cout输出数据endl;coutsetiosflags(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();voidfunc9()charsname10;ifstreamfile(MyFrd1.dat);teacherone;file.seekg(0);coutsname;cout输出查询结果:end
11、l;coutsetiosflags(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();voidfunc0()fstreamoutapp(MyFrd.dat1,ios:app);teacherone;cout添加数据:;one.getdata();outapp.write(
12、char*)&one,sizeof(one);outapp.close();voidfunc01()charsname12;inti=0;fstreamoutdel(MyFrd1.dat,ios:in|ios:out);teacherone;outdel.seekg(0);coutsname;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(t
13、eacher)*i);outdel.put(*);i+;outdel.close();voidfunc02()fstreamoutdel(teacher.dat,ios:in);fstreamtemp(temp,ios:out|ios:trunc);teachers;while(!outdel.eof()outdel.read(char*)&s,sizeof(teacher);if(s.gettag()=#)temp.write(char*)&s,sizeof(teacher);outdel.close();temp.close();fstreamoutdel1(MyFrd1.dat,ios:
14、out|ios:trunc);fstreamtemp1(temp,ios:in);while(!temp1.eof()temp1.read(char*)&s,sizeof(teacher);outdel1.write(char*)&s,sizeof(teacher);outdel1.close();temp1.close();cout此记录已物理删除endl;voidfunc03()ofstreamoutput(MyFrd2.dat);studentteachers;cout输入数据endl;coutn;for(inti=0;in;i+)cout第i+1个学生;s.getdata();outp
15、ut.write(char*)&s,sizeof(s);output.close();voidfunc04()ifstreaminput(MyFrd2.dat);studentteachers;cout输出数据endl;coutsetiosflags(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();vo
16、idfunc05()charsname10;ifstreamfile(MyFrd2.dat);studentteacherone;file.seekg(0);coutsname;cout输出查询结果:endl;coutsetiosflags(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
17、.close();voidfunc06()fstreamoutapp(MyFrd2.dat,ios:app);studentteacherone;cout添加数据:;one.getdata();outapp.write(char*)&one,sizeof(one);outapp.close();voidfunc07()charsname12;inti=0;fstreamoutdel(MyFrd2.dat,ios:in|ios:out);studentteacherone;outdel.seekg(0);coutsname;while(!outdel.eof()outdel.seekp(size
18、of(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();voidfunc08()fstreamoutdel(studentteacher.dat,ios:in);fstreamtemp(temp,ios:out|ios:trunc);studentteachers;while(!outdel.eof()ou
19、tdel.read(char*)&s,sizeof(studentteacher);if(s.gettag()=#)temp.write(char*)&s,sizeof(studentteacher);outdel.close();temp.close();fstreamoutdel1(MyFrd2.dat,ios:out|ios:trunc);fstreamtemp1(temp,ios:in);while(!temp1.eof()temp1.read(char*)&s,sizeof(studentteacher);outdel1.write(char*)&s,sizeof(studentte
20、acher);outdel1.close();temp1.close();cout此记录已物理删除endl;voidfunc09()charsname10;ifstreamfile(MyFrd.dat);studentone;file.seekg(0);coutsname;cout输出查询结果:endl;coutsetiosflags(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)
21、one.disp();file.read(char*)&one,sizeof(one);file.close();ofstreamoutput(MyFrd.dat);students;cout重新输入数据:endl;s.getdata();output.write(char*)&s,sizeof(s);output.close();voidfunc10()charsname10;ifstreamfile(MyFrd1.dat);teacherone;file.seekg(0);coutsname;cout输出查询结果:endl;coutsetiosflags(ios:left)setw(10)
22、姓名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();ofstreamoutput(MyFrd1.dat);teachers;cout重新输入数据:endl;s.getdata();output.write(char*)&s,sizeof(s);output.close();voidfunc11()charsn
23、ame10;ifstreamfile(MyFrd2.dat);studentteacherone;file.seekg(0);coutsname;cout输出查询结果:endl;coutsetiosflags(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();ofstrea
24、moutput(MyFrd2.dat);studentteachers;cout重新输入数据:endl;s.getdata();output.write(char*)&s,sizeof(s);output.close();intcomp(chars1,chars2)inti=0;while(s1i!=0&s2i!=0&s1i=s2i)i+;if(s1i=0|s2i=0)return1;elsereturn0;voidmain()intsel;docout请输入(1:输入数据2:输出数据3:按姓名查询endlsel;switch(sel)case1:chara,b;while(1)couta;i
25、f(a=1)func1();elseif(a=2)func7();elseif(a=3)func03();elsecout输入错误!endl;coutb;while(b!=y&b!=Y&b!=n&b!=N)coutb;if(b=n|b=N)break;break;case2:charc,d;while(1)coutc;if(c=1)func2();elseif(c=2)func8();elseif(c=3)func04();elsecout输入错误!endl;coutd;while(d!=y&d!=Y&d!=n&d!=N)coutd;if(d=n|d=N)break;break;case3:c
26、hare,f;while(1)coute;if(e=1)func3();elseif(e=2)func9();elseif(e=3)func04();elsecout输入错误!endl;coutf;while(b!=y&b!=Y&b!=n&b!=N)coutf;if(f=n|f=N)break;break;case4:charg,h;while(1)coutg;if(g=1)func4();elseif(g=2)func0();elseif(g=3)func06();elsecout输入错误!endl;couth;while(h!=y&h!=Y&h!=n&h!=N)couth;if(h=n|h
27、=N)break;break;case5:charm,n;while(1)coutm;if(m=1)func5();elseif(m=2)func01();elseif(m=3)func07();elsecout输入错误!endl;coutn;while(n!=y&n!=Y&n!=n&n!=N)coutn;if(n=n|n=N)break;break;case6:charx,z;while(1)coutx;if(x=1)func6();elseif(x=2)func02();elseif(x=3)func08();elsecout输入错误!endl;coutz;while(z!=y&z!=Y&z!=n&z!=N)coutz;if(z=n|z=N)break;break;case7:chars,t;while(1)couts;if(s=1)func09();elseif(s=2)func10();elseif(s=3)func11();elsecout输入错误!endl;coutt;while(t!=y&t!=Y&t!=n&t!=N)coutt;if(t=n|t=N)break;break;default:cout输入错误!=1&sel=6);
限制150内