




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
第C++實現(xiàn)圖書館管理系統(tǒng)源碼ofstreamfout("book.txt",ios::app);
foutid"\t"place"\t"year"\t"name"\t"professor"\t"endl;
fout.close();
voidBook::read(intn)
inti=0;
stringtemp,data[999],a[4];
ifstreamfin("book.txt");
while(getline(fin,temp))
{
data[i]=temp;
i+=1;
}
fin.close();
istringstreamstream(data[n]);
for(i=0;ii++)
{
data[n].erase(0,data[n].find("\t")+1);
a[i]=data[n].substr(0,data[n].find("\t"));
}
name=a[2];
professor=a[3];
streamidplaceyear;
}
main.cpp
#includeiostream
#includestring
#includevector
#include"Book.h"
#include"Student.h"
usingnamespacestd;
voidinitialize();
boolis_administrator();
boolis_student(int*n);
voidmenu1();
voidmenu2();
voidmenu3();
voidwrong_input();
voidmag_book();
voidmag_student();
voidshow_book_list();
voidshow_student_list();
voidgive_mark();
voidchange_password();
voidchoose_book(intn);
voidmy_book(intn);
voidcheck_info(intn);
voidcan_open(Booka);
voidcan_open(Studenta);
boolis_same_student_name(stringn);
boolis_same_student_tele(stringn);
boolis_same_student_addr(stringn);
boolis_same_book_name(stringn);
intmain()
intuser;
charchoice;
boolsuccess=0;
initialize();
do{
menu1();
cinchoice;
switch(choice)
{
case'1':
{
if(is_administrator()){
do{
menu2();
cinchoice;
getchar();
switch(choice)
{
case'1':mag_book();success=0;break;
case'2':mag_student();success=0;break;
case'3':show_book_list();success=0;break;
case'4':show_student_list();success=0;break;
case'5':give_mark();success=0;break;
case'6':change_password();success=0;break;
case'9':success=1;break;
case'0':success=1;break;
default:wrong_input();break;
}
}while(!success);
}
else
{
cout"Thepasswordisincorrect."endl;
system("pause");
}
}
break;
case'2':
{
if(is_student(user))
{
do{
menu3();
cinchoice;
switch(choice)
{
case'1':choose_book(user);success=0;break;
case'2':my_book(user);success=0;break;
case'3':check_info(user);success=0;break;
case'9':success=1;break;
case'0':success=1;break;
default:wrong_input();break;
}
}while(!success);
}
else
{
cout"Yournameorpasswordisincorrect."endl;
system("pause");
}
}
break;
case'0':success=1;break;
default:wrong_input();break;
}
}while(choice!='0');
return0;
voidinitialize()
ifstreaminfile1("book.txt");
if(!infile1)
{
ofstreamoutfile1("book.txt");
outfile1.close();
}
infile1.close();
ifstreaminfile2("student.txt");
if(!infile2)
{
ofstreamoutfile2("student.txt");
outfile2.close();
}
infile2.close();
ifstreaminfile3("password.txt");
if(!infile3)
{
ofstreamoutfile3("password.txt");
outfile3"123";
outfile3.close();
}
infile3.close();
ifstreaminfile4("mybook.txt");
if(!infile4)
{
ofstreamoutfile4("mybook.txt");
outfile4.close();
}
infile4.close();
boolis_administrator()
stringp1,p2;
getchar();
cout"Pleaseinputthepassword:";
getline(cin,p1);
ifstreaminfile("password.txt");
if(!infile)
{
coutendl"Outofservice"endl;
cout"Pleasepressentertoexit."endl;
system("pause");
exit(0);
}
getline(infile,p2);
infile.close();
if(p1==p2)
return1;
else
return0;
boolis_student(int*n)
Studenta[100];
Students;
stringp1,p2;
inti;
boolsuccess=0;
getchar();
cout"Pleaseinputyourname:";
getline(cin,p1);
cout"Pleaseinputyourpassword:";
getline(cin,p2);
can_open(s);
for(i=0;is.length();i++)
{
a[i].read(i);
if(a[i].get_name()==p1a[i].get_pass()==p2)
{
*n=i;
success=1;
}
}
returnsuccess;
voidmenu1()
system("cls");
coutendlendlendl;
cout"-------------------------------------------------------------------"endl;
cout"
UniversityStudentManagementSystem
"endlendl;
cout"
1.AdministratorSystem."endlendl;
cout"
2.StudentSystem."endlendl;
cout"
0.Exit."endl;
cout"-------------------------------------------------------------------"endl;
cout"Pleaseinputyourchoice:";
voidmenu2()
system("cls");
coutendlendlendl;
cout"-------------------------------------------------------------------"endl;
cout"
AdministratorSystem
"endlendl;
cout"
1.BookManagement."endlendl;
cout"
2.StudentManagement."endlendl;
cout"
3.ShowtheBookList."endlendl;
cout"
4.ShowtheStudentList."endlendl;
cout"
5.GiveMarkstoStudents."endlendl;
cout"
6.ChangeAdministratorPassword."endlendl;
cout"
9.Returntothemainmenu."endlendl;
cout"
0.Exit."endl;
cout"-------------------------------------------------------------------"endl;
cout"Pleaseinputyourchoice:";
voidmenu3()
system("cls");
coutendlendlendl;
cout"-------------------------------------------------------------------"endl;
cout"
StudentSystem"endlendl;
cout"
1.ChooseMyBooks"endlendl;
cout"
2.CheckMyBooksandGrades"endlendl;
cout"
3.CheckandChangeMyInfomation"endlendl;
cout"
9.Returntothemainmenu."endlendl;
cout"
0.Exit."endl;
cout"-------------------------------------------------------------------"endl;
cout"Pleaseinputyourchoice:";
voidwrong_input()
system("cls");
coutendlendlendlendlendlendl;
cout"
Wronginput!Pleaseinputagain."endl;
system("pause");
voidmag_book()
inti,id,plac,year;
charchoice;
boolsuccess=0,success2=0;
stringname,prof;
Booka[50];
Bookc;
do{
fflush(stdin);
system("cls");
coutendl"
BookManagement"endlendl;
cout"Whichoperationdoyouwantaboutthelistofbook"endl;
cout"1.Browseabook\n\n2.Addabook\n\n3.Modifyabook\n\n4.Deleteabook\n\n";
cinchoice;
cout"PleaseinputtheIDnumberofbook:";
cinid;
getchar();
can_open(c);
if(choice=='1')
{
success2=1;
fflush(stdin);
for(i=0;ic.length();i++)
a[i].read(i);
for(i=0;ic.length();i++)
if(id==a[i].get_id())
{
system("cls");
a[i].display();
success=1;
}
if(!success)
cout"Thebookcannotbefound.";
}
elseif(choice=='2')
{
success2=1;
fflush(stdin);
for(i=0;ic.length();i++)
{
a[i].read(i);
if(id==a[i].get_id())
success=1;
}
if(success)
cout"Thebookisexist";
else
{
do{
cout"Pleaseinputthenameofbook:";
getline(cin,name);
}while(is_same_book_name(name));
cout"Pleaseinputtheprofessor'sname:";
getline(cin,prof);
cout"Pleaseinputthemaximumquotaofpeople(connotchangelater):";
cinplac;
cout"Whichgradesareavailable"endl"1.year1\n2.year2\n3.year3\n4.year4\n5.allofstudents\n";
cinyear;
c.change(id,name,prof,plac,year);
c.write();
system("cls");
cout"Thebookhasbeensaved."endlendl;
c.display();
}
}
elseif(choice=='3')
{
success2=1;
fflush(stdin);
intl,n;
l=c.length();
for(i=0;ii++)
{
a[i].read(i);
if(id==a[i].get_id())
{
n=i;
success=1;
}
}
if(success)
{
do{
cout"Pleaseinputthenewnameofbook"id":";
getline(cin,name);
}while(is_same_book_name(name));
cout"Pleaseinputthenewprofessor'snameofbook"id":";
getline(cin,prof);
cout"Whichgradesareavailable"endl"1.year1\n2.year2\n3.year3\n4.year4\n5.allofstudents\n";
cinyear;
a[n].change(id,name,prof,a[n].get_place(),year);
ofstreamfout("book.txt");
fout.close();
for(i=0;ii++)
a[i].write();
system("cls");
cout"Thebookhasbeenchanged."endlendl;
a[n].display();
}
else
cout"Thebook"id"cannotbefound.";
}
elseif(choice=='4')
{
success2=1;
fflush(stdin);
intn,l=c.length();
for(i=0;ii++)
{
a[i].read(i);
if(id==a[i].get_id())
{
n=i;
success=1;
}
}
if(success)
{
ofstreamfout("book.txt");
fout.close();
for(i=0;il-1;i++)
if(i!=n)
a[i].write();
system("cls");
cout"Thebookhasbeendeleted."endlendl;
a[n].display();
}
else
cout"Thebook"id"cannotbefound.";
}
else
{
cout"wronginput,pleaseinputagain."endl;
system("pause");
}
}while(!success2);
coutendl;
system("pause");
voidmag_student()
inti,id,year;
charchoice;
boolsuccess=0,success2=0;
stringname,pass,gend,tele,addr;
Studenta[50];
Students;
do{
system("cls");
coutendl"
StudentManagement"endlendl;
cout"Whichoperationdoyouwantaboutthelistofstudent"endl;
cout"1.Browseastudent\n2.Addastudent\n3.Modifyastudent\n4.Deleteastudent\n";
cinchoice;
cout"PleaseinputtheIDnumberofstudent:";
cinid;
getchar();
can_open(s);
if(choice=='1')
{
success2=1;
fflush(stdin);
for(i=0;is.length();i++)
a[i].read(i);
for(i=0;is.length();i++)
if(id==a[i].get_id())
{
system("cls");
a[i].display();
success=1;
}
if(!success)
cout"Thestudentcannotbefound.";
}
elseif(choice=='2')
{
success2=1;
fflush(stdin);
for(i=0;is.length();i++)
{
a[i].read(i);
if(id==a[i].get_id())
success=1;
}
if(success)
cout"Thestudentisexist";
else
{
do{
cout"Pleaseinputthenameofstudent:";
getline(cin,name);
}while(is_same_student_name(name));
cout"Pleaseinputthepassword:";
getline(cin,pass);
do{
cout"Whatgradeisthestudentin(1-4)";
cinyear;
}while(year1||year
fflush(stdin);
do{
cout"Pleaseinputthestudent'sgender:"endl"Pleaseenter'male'or'female'
:";
getline(cin,gend);
}while(!(gend=="male"||gend=="female"));
do{
cout"Pleaseinputthetelephonenumber:";
getline(cin,tele);
}while(is_same_student_tele(tele));
do{
cout"Pleaseinputtheaddress:";
getline(cin,addr);
}while(is_same_student_addr(addr));
s.change(id,year,name,pass,gend,tele,addr);
s.add_student();
s.write();
system("cls");
cout"Theinformationofstudenthasbeensaved."endlendl;
s.display();
}
}
elseif(choice=='3')
{
success2=1;
fflush(stdin);
intl,n;
l=s.length();
for(i=0;ii++)
{
a[i].read(i);
if(id==a[i].get_id())
{
n=i;
success=1;
}
}
if(success)
{
do{
cout"Pleaseinputthenewnameofstudent"id":";
getline(cin,name);
}while(is_same_student_name(name));
pass=a[n].get_pass();
do{
cout"Whatgradeisthestudentin(1-4)";
cinyear;
}while(year1||year
fflush(stdin);
do{
cout"Pleaseinputthestudent'sgender:"endl"Pleaseenter'male'or'female'
:";
getline(cin,gend);
}while(!(gend=="male"||gend=="female"));
do{
cout"Pleaseinputthenewtelephonenumber:";
getline(cin,tele);
}while(is_same_student_tele(tele));
do{
cout"Pleaseinputthenewaddress:";
getline(cin,addr);
}while(is_same_student_addr(addr));
a[n].change(id,year,name,pass,gend,tele,addr);
ofstreamfout("student.txt");
fout.close();
for(i=0;ii++)
a[i].write();
system("cls");
cout"Thestudenthasbeenchanged."endlendl;
a[n].display();
}
else
cout"Thestudent"id"cannotbefound.";
}
elseif(choice=='4')
{
success2=1;
fflush(stdin);
intn,l=s.length();
for(i=0;ii++)
{
a[i].read(i);
if(id==a[i].get_id())
{
n=i;
success=1;
}
}
if(success)
{
a[n].sub_student();
ofstreamfout("student.txt");
fout.close();
for(i=0;ii++)
if(i!=n)
a[i].write();
system("cls");
cout"Thestudenthasbeendeleted."endlendl;
a[n].display();
}
else
cout"Thestudent"id"cannotbefound.";
}
else
{
cout"Wronginput,pleaseinputagain."endl;
system("pause");
}
}while(!success2);
coutendl;
system("pause");
voidshow_book_list()
Booka[100];
Bookc;
inti;
system("cls");
coutendl"
BooksList"endlendl;
can_open(c);
for(i=0;ic.length();i++)
{
a[i].read(i);
a[i].display();
}
coutendl;
system("pause");
voidshow_student_list()
Studenta[100];
Students;
inti;
system("cls");
coutendl"
StudentsList"endlendl;
can_open(s);
for(i=0;is.length();i++)
{
a[i].read(i);
a[i].display();
}
coutendl;
system("pause");
voidgive_mark()
inti,j,k=0,id,temp;
boolsuccess=0;
vectorintstudent,mark;
Studenta[999];
Students;
Bookb[999];
Bookc;
system("cls");
coutendl"
GiveMarks"endlendl;
cout"PleaseinputtheIDnumberofbook:";
cinid;
for(i=0;ic.length();i++)
{
b[i].read(i);
if(b[i].get_id()==id)
success=1;
}
if(!success)
cout"Thebook"id"isnotexist."endl;
else
{
cout"Thesestudent(s)areyourstudent(s):";
for(i=0;is.length();i++)
{
a[i].read(i);
a[i].read_book();
for(j=0;ja[i].get_book().size();j++)
if(id==a[i].get_book()[j])
{
k+=1;
coutendlk"."a[i].get_name();
student.push_back(i);
break;
}
}
coutendl"Pleasegivemarks;"endl;
for(i=0;ii++)
{
couta[student[i]].get_name()":
";
cintemp;
a[student[i]].change_book(id,temp);
}
for(i=0;is.length();i++)
a[i].write_book();
coutendl"Givingmarkssuccessfully!";
}
coutendl;
system("pause");
voidchange_password()
stringp1,p2,p3;
system("cls");
coutendl"
ChangeAdministratorPassword."endlendl;
cout"Pleaseinputthepassword:";
getline(cin,p1);
ifstreaminfile("password.txt");
if(!infile)
{
coutendl"Outofservice"endl;
cout"Pleasepressentertoexit."endl;
system("pause");
exit(0);
}
getline(infile,p2);
infile.close();
if(p1==p2)
{
cout"Pleaseinputthenewpassword:";
getline(cin,p3);
ofstreamoutfile("password.txt");
outfilep3;
outfile.close();
cout"Theadministratorpasswordhasbeenchanged.";
}
else
cout"Wrongpassword.";
coutendl;
system("pause");
voidchoose_book(intn)
inti,l,m,id;
boolsuccess=0;
boolcan_choose[999];
Studenta[999];
Students;
Bookb[999];
Bookc;
system("cls");
coutendl"
ChooseMyBooks"endlendl;
can_open(s);
can_open(c);
l=c.length();
for(i=0;is.length();i++)
{
a[i].read(i);
a[i].read_book();
}
cout"
Welcome,"a[n].get_name()endlendl;
for(i=0;ii++)
{
b[i].read(i);
if(((b[i].get_year()==a[n].get_year())||b[i].get_year()==5)(b[i].get_place()0))
{
can_choose[i]=1;
cout"Status:
Available"endl;
b[i].display();
}
else
{
can_choose[i]=0;
cout"Status:
Unavailable"endl;
b[i].display();
}
}
do{
cout"PleaseinputtheIDnumberofthebookyouwanttochoose:";
cinid;
success=0;
for(i=0;ii++)
if(b[i].get_id()==id)
{
m=i;
success=1;
}
}while(!success);
system("cls");
coutendlendlendl;
if(can_choose[m])
{
if(a[n].is_same_book(id))
cout"
Youhaveselectedthebook"idendl;
else
{
b[m].change(b[m].get_id(),b[m].get_name(),b[m].get_prof(),b[m].get_place()-1,b[m].get_year());
ofstreamoutfile("book.txt");
outfile.close();
for(i=0;ii++)
b[i].write();
a[n].add_book(id);
a[n].write_book();
cout"Hereisthelistofyourbooksnow:"endlendl"ID\t\tGrade"endl;
a[n].display_book();
}
}
else
cout"
Thebook'"b[m].get_name()"'cannotbeselected."endl;
system("pause");
voidmy_book(intn)
inti,l;
Studenta[999];
Students;
system("cls");
coutendl"
CheckMyBooksangGrades"endlendl;
can_open(s);
l=s.length();
for(i=0;ii++)
a[i].read(i);
cout"
Welcome,"a[n].get_name()endlendl;
a[n].read_book();
cout"BookID\tGrade"endlendl;
a[n].display_book();
system("pause");
voidcheck_info(intn)
inti,l;
charchoice;
boolsuccess=0;
stringtele,addr,pass;
Studenta[999];
Students;
system("cls");
coutendl"
CheckandChangeMyInformation"endlendl;
can_open(s);
l=s.length();
for(i=0;ii++)
a[i].read(i);
cout"
Welcome,"a[n].get_name()endlendl;
a[n].display();
coutendl"Enter1:Changemyinformation."endl;
cout"Enter2:Changemypassword."endl;
cout"Enterelse:Returntothestudentmenu:";
cinchoice;
getchar();
if(choice=='1')
{
do{
cout"Pleaseinputthenewtelephonenumber:";
getline(cin,tele);
}while(is_same_student_tele(tele));
do{
cout"Pleaseinputthenewaddress:";
getline(cin,addr);
}while(is_same_student_addr(addr));
a[n].change(a[n].get_id(),a[n].get_year(),a[n].get_name(),a[n].get_pass(),a[n].
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 賽馬問題測試題及答案
- 打造未來城市綠肺共享健康生活
- 賽道醉酒測試題及答案
- 合同協(xié)議書字號
- 承包挖沉淀池合同協(xié)議書
- 美團外賣合同協(xié)議書模板
- 查閱合同協(xié)議書
- 維修保養(yǎng)合同協(xié)議書范本
- 合同協(xié)議書怎么查找
- 保養(yǎng)合同協(xié)議書
- 大學生性健康教育智慧樹知到答案章節(jié)測試2023年南昌大學
- 信任五環(huán)(用友營銷技巧) PPT資料
- 2、圓口綱完整版課件
- 錮囚鋒-備戰(zhàn)高考總復習地理專項突破
- 2022下半年漢中市事業(yè)單位招聘考試《綜合應用能力(醫(yī)療衛(wèi)生E類)》題庫含答案解析
- MT 181-1988煤礦井下用塑料管安全性能檢驗規(guī)范
- JB/T 20173-2016輥壓干法制粒機
- GB/T 11419-2008搪瓷炊具耐溫急變性測定方法
- 乳制品領(lǐng)域:燕塘乳業(yè)企業(yè)組織結(jié)構(gòu)及部門職責
- 外科護理學題庫(中專)
- 內(nèi)部審計工作實施細則五(3篇)
評論
0/150
提交評論