图书馆管理系统代码.docx

上传人:b****2 文档编号:739792 上传时间:2022-10-12 格式:DOCX 页数:21 大小:17.86KB
下载 相关 举报
图书馆管理系统代码.docx_第1页
第1页 / 共21页
图书馆管理系统代码.docx_第2页
第2页 / 共21页
图书馆管理系统代码.docx_第3页
第3页 / 共21页
图书馆管理系统代码.docx_第4页
第4页 / 共21页
图书馆管理系统代码.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

图书馆管理系统代码.docx

《图书馆管理系统代码.docx》由会员分享,可在线阅读,更多相关《图书馆管理系统代码.docx(21页珍藏版)》请在冰豆网上搜索。

图书馆管理系统代码.docx

#include

#defineDEBUG0

//宏定义决定测试代码是否编译0为不编译非0则编译

constcharbook_path[20]="books.txt";

constcharreader_path[20]="readers.txt";

//文件读写声明

voidread_from_files_to_vector();

voidwrite_all_to_files();

#ifDEBUG

voidscan_readers(){

for(reader&s:

readers){

wcout<

}

}

#endif

intmain()

{

//完成操作后需要在控制台按5中退出才会保存到文件

wcin.imbue(china);

wcout.imbue(china);

read_from_files_to_vector();

#ifDEBUG

cout<<"sizeofreaders="<

cout<<"sizeofbooks="<

scan_book();

scan_readers();

#endif

stringpassword="123456"; //密码已改

cout<<"------------欢迎使用中南大学网络在线图书系统------------"<

//这里可以添加你们小组的名单或一些装饰的字符

cout<<"--------------------请选择登录方式--------------------"<

cout<<"1管理员登陆2读者登陆"<

inta;

cin>>a;

cleanScreen();

if(a==1)

{

stringstr;

for(intj=0;j<=4;j++)

{

cout<<"请输入管理密码,你有"<<(4-j)<<"次机会"<

cin>>str;

if(password==str)

{

break;

}

elsecout<<"密码错误!

请重新输入"<

if(j==4)

return0;

}

cleanScreen();

cout<<"-------------欢迎来到图书管理系统-------------"<

cout<<"成功登陆!

你有以下操作可供选择"<

cout<

//操作循环

cout<<"1浏览图书信息"<

cout<<"2图书信息修改"<

cout<<"3图书信息添加"<

cout<<"4图书信息删除"<

cout<<"5保存信息并退出系统"<

cout<<"--------------请选择操作选项编号--------------"<

intb;

cin>>b;

cleanScreen();

while(b!

=5){

switch(b)

{

case1:

scan_book();break;

case2:

modify_book();break;

case3:

add_book();break;

case4:

delete_book();break;

default:

cout<<"输入错误,请重新输入";break;

}

cout<

cout<<"---------------请进行下一次操作---------------"<

cout<<"1浏览图书信息"<

cout<<"2图书信息修改"<

cout<<"3图书信息添加"<

cout<<"4图书信息删除"<

cout<<"5退出系统"<

cout<<"--------------请选择操作选项编号--------------"<

cin>>b;

cleanScreen();

}

write_all_to_files();

return0;

}

elseif(a==2)

{

intreaderIndex=0; //记录读者下标

//输入学号登陆

cout<<"--------------请输入学号--------------"<

wchar_tstudentnumber[20];

for(intm=0;m<=9;m++)

{

cout<<"请输入学号,你有"<<(9-m)<<"次机会"<

wcin>>studentnumber;

intt;

for(t=0;t

{

if(wcscmp(studentnumber,readers[t].cardnum)==0)

{

readerIndex=t;

break;

}

}

//判断跳出循环原因

if(t

break;

else

{

cout<<"登录账号不存在,请重新输入学号"<

continue;

}

if(m==9)

return0;

}

cleanScreen();

cout<<"------------欢迎来到读者自助系统------------"<

wcout<

你有以下操作可供选择"<

cout<

//操作循环

cout<<"1图书浏览"<

cout<<"2图书查询"<

cout<<"3图书借阅"<

cout<<"4图书返还"<

cout<<"5退出系统"<

cout<<"---------------请选择操作选项--------------"<

intc;

cin>>c;

cleanScreen();

while(c!

=5)

{

switch(c)

{

case1:

scan_book();break;

case2:

search_book();break;

case3:

borrow_book(readerIndex);break;

case4:

return_book(readerIndex);break;

default:

cout<<"输入错误!

请重新输入"<

}

cout<

cout<<"--------------请进行下一次操作--------------"<

cout<<"1图书浏览"<

cout<<"2图书查询"<

cout<<"3图书借阅"<

cout<<"4图书返还"<

cout<<"5退出系统"<

cout<<"---------------请选择操作选项---------------"<

cin>>c;

cleanScreen();

}

write_all_to_files();

return0;

}

return0;

}

//main函数结束

//写入/读取文件

voidwrite_all_to_files()

{

wofstreamoutfile;

outfile.imbue(locale("chs"));

//写入书本文件

outfile.open(book_path);

outfile<

for(inti=0;i

{

outfile<

}

outfile.close();

outfile.clear();

//写入读者文件,由于程序中没有针对读者的删改(备用,将0改为1后即可编译这段代码)

#if0

outfile.open(path:

:

reader_path);

outfile<

for(inti=0;i

{

outfile<

}

outfile.close();

#endif

return;

}

voidread_from_files_to_vector()

{

wifstreaminfile;

infile.imbue(locale("chs"));

//用于设置读写中文

bookbb;

readerrr;

//在程序目录下没有相应文件时创建空文件(备用,将0改为1后即可编译这段代码)

#if0

wofstreamcreat_if_no;

creat_if_no.imbue(locale("chs"));

creat_if_no.open(book_path,ios:

:

_Noreplace);

creat_if_no.close();

creat_if_no.clear();

creat_if_no.open(reader_path,ios:

:

_Noreplace);

creat_if_no.close();

creat_if_no.clear();

#endif

//读取书本数据

infile.open(book_path);

intsize=0;

infile>>size;

while(!

infile.eof()&&size!

=0)

{

infile>>bb;

books.push_back(bb);

size-

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > 财会金融考试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1