爱玩科技网
您的当前位置:首页图书管理系统实验报告

图书管理系统实验报告

来源:爱玩科技网

5.若数据不存在,输出提示,返回

否则显示图书信息

6.关闭数据库

C/C++语言程序设计大型实验报告--图书管理系统

C/C++语言程序设计大型实验报告--图书管理系统

第四章读者管理模式

4.1查看个人信息

voidBookReader::showInfo(void)

虚继承自User类,调用User类的showInfo(void)函数显示该工作人员的序号、姓名、权限,并且显示借书数目。

4.2查找馆藏图书信息

直接调用User类的searchBook()函数

C/C++语言程序设计大型实验报告--图书管理系统

第五章工作人员管理模式

5.1查询读者信息(个人信息和读者借书情况)

voidWorker::showInfo(void)

虚继承自User类,调用User类的showInfo(void)函数显示该工作人员的序号,姓名、权限,并且显示性别和部门。

voidWorker::showReaderInfo(BookReaderreader)

将BookReader类型的指针reader指向showInfo(void)函数,即调用BookReader类的showInfo(void)函数以显示读者借书情况。

C/C++语言程序设计大型实验报告--图书管理系统

5.2还书

boolWorker::returnBook(conststringbno,conststringrno)

5.3借书

boolWorker::borrowBook(conststringbno,conststringrno)首先调用图书类和读者类的isE_isted检查

5.4查询图书信息

直接调用User类的searchBook()函数

C/C++语言程序设计大型实验报告--图书管理系统

第六章管理员管理模式

6.1添加、删除图书信息

6.1.1添加图书信息

boolLAdmin::AddBook(void)

添加图书函数,添加成功返回true,返回上层返回false

1.新建Book类型的指针。

2.用该指针调用Book类的getFromStdin()函数以及addToData()函数,获取图书信息并添加入数据库。

3.提示成功添加图书,返回true

4.若失败,提示选择重新输入或者返回上层

重新输入则再次调用该函数

返回上层则返回false。

C/C++语言程序设计大型实验报告--图书管理系统

6.1.2删除图书信息

boolLAdmin::DeleteBook(BookaBook,boolwarning)

删除图书函数,删除成功返回true,若图书不存在,或者数据库出错,或者操作被取消返回false

1.用aBook指针调用Book类的isE_isted()判断图书是否存在。若不存在,返回false

2.用aBook指针调用showInfo()显示图书信息。

3.询问是否要删除该书,若取消,返回false

否则调用DBManager类的sqlOperate函数对数据库进行删除图书操作,操作成功返回true,失败返回false

6.2添加、删除用户信息

boolLAdmin::AddMember(void)

添加用户函数,添加成功返回true,返回上层返回false

1.新建User类型的指针。

2.选择具体人员类型,并新建对应类型的指针

2.用该指针调用该类类的getFromStdin()函数以及addToData()函数,获取用户信息并添加入数据库。

3.提示成功添加用户,返回true

4.若失败,提示选择重新输入或者返回上层

重新输入则再次调用该函数

返回上层则返回false。

boolLAdmin::deleteMember(UseraUser,int_type,boolwarning)

删除用户函数,删除成功返回true,若用户不存在,或者数据库出错,或者操作被取消返回false

1.用aUser指针调用User类的isE_isted()判断用户是否存在。若不存在,返回false

2.用aUser指针调用showInfo()显示用户信息。

3.询问是否要删除该用户,若取消,返回false

否则调用DBManager类的sqlOperate函数对数据库进行删除用户操作,操作成功返回true,失败返回false

C/C++语言程序设计大型实验报告--图书管理系统

6.3查询图书信息

直接调用User类的searchBook()函数

第七章图书类

图书类的公开定义中,包括2个构造函数,重载不同类型的图书构造,重设借书数量函数(setNewBorrowNum(conststringnewNum))用于设置图书借出数量,更新数据函数(updateData(void))。另有四个函数,同用户类的虚函数一样,分别用于判断图书是否存在(isE_isted(void))、从键盘读取图书信息(getFromStdin(void))、将信息存入数据库(addToData(void))以及显示信息(showInfo(void))。

用户类的保护定义中,包括编号(no),书名(name),作者(author),出版社(press),库存量(storenum),借出量(borrownum)等六个成员变量。

ifndefBOOK_H

defineBOOK_H

include

C/C++语言程序设计大型实验报告--图书管理系统

include

include"DBManage.h"

usingnamespacestd;

classBook

public:

private:

endifstringno,name,author,press,storenum,borrownum;Book(void);Book(conststring_no);boolisE_isted(void);boolgetFromStdin(void);booladdToData(void)const;voidshowInfo(void)const;stringgetNo(void)const;stringgetBorrowNum(void)const;stringgetStoreNum(void)const;voidsetNewBorrowNum(conststringnewNum);boolupdateData(void)const;

第八章建立数据库

8.1数据储存文件说明

8.2数据库操作说明

读、存、查找、删除数据的函数全部写在DBManage.h和DBManage.cpp文件中。DBManage.h放所有的数据操作函数的声明,在DBManage.cpp文件中放置数据操作函数的实现。

ifndefDBMANAGE_H

defineDBMANAGE_H

import"c:programfilescommonfilessystemadomsado15.dll"no_namespacerename("EOF","adoEOF")

C/C++语言程序设计大型实验报告--图书管理系统

include

include

include

usingnamespacestd;

classDBManage

public:

staticboolsqlOperate(constcharsqlCommand){_ConnectionPtrpConnection=sqlOpenConnection();_CommandPtrpCommand;pCommand.CreateInstance(__uuidof(Command));pCommand->ActiveConnection=pConnection;/将库连接赋于它try{}catch(_com_errore){std::cout<<"数据库操作失败!";std::cout<Close();pCommand->CommandTe_t=sqlCommand;pCommand->E_ecute(NULL,NULL,adCmdTe_t);pConnection->Close();returntrue;static_ConnectionPtrsqlOpenConnection(){}_ConnectionPtrpConnection;CoInitialize(NULL);pConnection.CreateInstance(__uuidof(Connection));try{}catch(_com_errore){}returnNULL;/打开本地Access库Database.mdbpConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;DatareturnpConnection;Source=Database.mdb","","",adModeUnknown);

C/C++语言程序设计大型实验报告--图书管理系统

}}returnfalse;returntrue;staticboolgetDataRecord(_ConnectionPtrpConnection,conststringcommand,stringerr,mapitem,conststringCollect,intn)

}catch(_com_errore){}if(pRecordset==NULL){}try{if(!pRecordset->BOF){}_variant_tvar;for(inti=0;iGetCollect(Collect[i].c_str());if(var.vt!=VT_NULL)err="数据为空!";returnfalse;pRecordset->MoveFirst();elseerr="数据为空!";returnfalse;err=((_bstr_t)e->ErrorMessage());returnfalse;adOpenDynamic,adLockOptimistic,adCmdTe_t);{_RecordsetPtrpRecordset;pRecordset.CreateInstance(__uuidof(Recordset));try{pRecordset->Open(command.c_str(),pConnection.GetInterfacePtr(),/获取库接库的IDispatch指

C/C++语言程序设计大型实验报告--图书管理系统

}}}item[Collect[i]]=_com_util::ConvertBSTRToString((_bstr_t)var);elseitem[Collect[i]]="";catch(_com_errore){err=(_bstr_t)e->ErrorMessage();returnfalse;}pRecordset->Close();pRecordset=NULL;returntrue;staticboolgetDataRecord(_ConnectionPtrpConnection,conststringcommand,stringerr,vectoritems,conststringCollect,intn)

}catch(_com_errore){}if(pRecordset==NULL){}try{if(!pRecordset->BOF)pRecordset->MoveFirst();err="数据为空!";returnfalse;err=((_bstr_t)e->ErrorMessage());returnfalse;adOpenDynamic,adLockOptimistic,adCmdTe_t);{_RecordsetPtrpRecordset;pRecordset.CreateInstance(__uuidof(Recordset));try{pRecordset->Open(command.c_str(),pConnection.GetInterfacePtr(),/获取库接库的IDispatch指

C/C++语言程序设计大型实验报告--图书管理系统

}}else{}_variant_tvar;while(!pRecordset->adoEOF){}mapitem;for(inti=0;iMoveNe_t();var=pRecordset->GetCollect(Collect[i].c_str());if(var.vt!=VT_NULL)item[Collect[i]]=err="数据为空!";returnfalse;_com_util::ConvertBSTRToString((_bstr_t)var);elseitem[Collect[i]]="";catch(_com_errore){err=(_bstr_t)e->ErrorMessage();returnfalse;}pRecordset->Close();pRecordset=NULL;returntrue;

endif

C/C++语言程序设计大型实验报告--图书管理系统

第九章主程序结构

ifndefUERMEDOL_H

defineUERMEDOL_H

include

include

include"User.h"

include"LAdmin.h"

include"Book.h"

include"Worker.h"

include"BookReader.h"

usingnamespacestd;

e_ternenumStatue{E_IT,OFFLOGIN};

e_terninlinevoidfresh();

StatueAdminModel(LAdminuser);/执行管理员模式并返回下一个操作

StatueReaderMedol(BookReaderreader);/执行读者模式并返回下一个操作StatueWorkerMedol(Workerworker);/执行工作人员模式并返回下一个操作intLoginModel();

boolLogin(Useruser);

intLoginModel()

LabelStartLogin:

fresh();cout<<"欢迎使用图书管理系统"<choice;if(!(choice>=1choice<=4)){}

-21-cout<

C/C++语言程序设计大型实验报告--图书管理系统

returnchoice;

StatueAdminModel(LAdminadmin){

fresh();cout<<"欢迎登陆图书管理系统(管理员模式)"<choice;if(choice==1)/添加用户{}elseif(choice==2)/删除用户{int_choice;stringno;Usertodelete=NULL;cout<<"请输入要删除的用户类型(1.管理员2.读者3.工作人员)...";cin>if(!(_choice>=1_choice<=3)){}cout<<"您的输入有误!"<AddMember()){}int_choice;cout<<"您可以1)继续添加2)返回...";cin>_choice;if(_choice==1)gotoLabelAddUser;elseAdminModel(admin);LabelAddUser:LabelDeleteUser:_choice;

C/C++语言程序设计大型实验报告--图书管理系统

}else{}admin->deleteMember(todelete,todelete->getType());if(todelete!=NULL)deletetodelete;cout<<"您可以1)继续删除2)返回...";cin>_choice;if(_choice==1)gotoLabelDeleteUser;elseAdminModel(admin);cout<<"请输入要删除的用户序号...";cin>no;if(_choice==1)todelete=newLAdmin(no);elseif(_choice==2)todelete=newBookReader(no);elseif(_choice==3)todelete=newWorker(no);elseif(choice==3){}elseif(choice==4){}elseif(choice==5)/删除图书{stringno;cout<<"请输入要删除的图书序号...";cin>no;admin->DeleteBook(Book(no));cout<<"您可以1)继续删除2)返回...";int_choice;cin>_choice;if(_choice==1)gotoLabelDeleteBook;admin->AddBook();cout<<"您可以1)继续添加2)返回...";int_choice;cin>_choice;if(_choice==1)gotoLabelAddBook;elseAdminModel(admin);stringbno;admin->searchBook();int_choice;cout<<"您可以1)继续查询2)返回...";cin>_choice;if(_choice==1)gotoLabelSearchBook;elseAdminModel(admin);LabelSearchBook:LabelAddBook:LabelDeleteBook:

C/C++语言程序设计大型实验报告--图书管理系统

}elseAdminModel(admin);elseif(choice==6)/查询所有图书{}elseif(choice==7)/查询所有用户{}elseif(choice==8)/注销用户{}elseif(choice==9)returnE_IT;/退出系统系统else/错误选择重新开始{}cout<choice;switch(choice){case2:returnOFFLOGIN;break;case3:returnE_IT;break;default:AdminModel(admin);break;}returnOFFLOGIN;cout<<"您输入的选择有误!"<showAllMembers();admin->showAllBooks();

StatueReaderMedol(BookReaderreader){

fresh();cout<<"欢迎登陆图书管理系统(读者模式)"<choice;if(choice==1)/查询图书

C/C++语言程序设计大型实验报告--图书管理系统

{}elseif(choice==2)/显示信息{}elseif(choice==3)/修改密码{}elseif(choice==4)returnOFFLOGIN;elseif(choice==5)returnE_IT;elseReaderMedol(reader);returnOFFLOGIN;if(reader->resetPassWord()){}else{}int_choice;cout<<"您可以1)重试2)返回...";cin>_choice;if(_choice==1)gotoLabelRePassWord;elseReaderMedol(reader);system("pause");ReaderMedol(reader);reader->showInfo();system("pause");ReaderMedol(reader);int_choice;reader->searchBook();cout<<"您可以1)继续查询2)返回...";cin>_choice;if(_choice==1)gotoLabelSearchBook;elseReaderMedol(reader);LabelSearchBook:LabelRePassWord:

StatueWorkerMedol(Workerworker){

fresh();cout<<"欢迎登陆图书管理系统(工作人员模式)"<

C/C++语言程序设计大型实验报告--图书管理系统

<<"4)还书模式"<choice;if(choice==1)/查询图书{}elseif(choice==2)/查询读者{}elseif(choice==3)/借书系统{stringrno,bno;stringrno;cout<<"请输入您要查询的读者序号...";cin>rno;BookReaderreader=newBookReader(rno);if(!reader->isE_isted()){}else{}worker->showReaderInfo(reader);int_choice;deletereader;cout<<"您可以1)继续查询2)返回...";cin>_choice;if(_choice==1)gotoLabelSearchReader;elseWorkerMedol(worker);deletereader;cout<<"您所查询的读者不存在!"<_choice;if(_choice==1)gotoLabelSearchReader;elseWorkerMedol(worker);int_choice;worker->searchBook();cout<<"您可以1)继续查询2)返回...";cin>_choice;if(_choice==1)gotoLabelSearchBook;elseWorkerMedol(worker);LabelSearchBook:LabelSearchReader:

LabelBorrowBook:

C/C++语言程序设计大型实验报告--图书管理系统

}cout<<"请输入要借书的读者ID:";cin>rno;cout<<"请输入要借阅的图书ID:";cin>bno;if(worker->borrowBook(bno,rno))cout<<"借书成功!"<_choice;if(_choice==1){}elseWorkerMedol(worker);gotoLabelBorrowBook;elseif(choice==4)/还书系统{}elseif(choice==5)returnOFFLOGIN;/注销登录elseif(choice==6)returnE_IT;else{}returnOFFLOGIN;cout<<"您输入的选择有误!"<rno;cout<<"请输入要归还的图书ID:";cin>bno;if(worker->returnBook(bno,rno))cout<<"还书成功!"<_choice;if(_choice==1)gotoLabelReturnBook;elseWorkerMedol(worker);LabelReturnBook:

voidfresh()

chars[]="";system("cls");cout<

cout<

C/C++语言程序设计大型实验报告--图书管理系统

cout<

endif

因篇幅问题不能全部显示,请点此查看更多更全内容