C++实现小型图书管理系统_第1页
C++实现小型图书管理系统_第2页
C++实现小型图书管理系统_第3页
C++实现小型图书管理系统_第4页
C++实现小型图书管理系统_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第C++实现小型图书管理系统本文实例为大家分享了C++实现小型图书管理系统的具体代码,供大家参考,具体内容如下

因为课程设计的原因,需要实现一个小型图书管理系统

包含功能:

问题描述:

设计一个系统,对图书信息进行管理,信息描述:有关该系统基本信息的描述,如:图书名称、图书编号、单价、作者、存在状态、借书人姓名、性别、学号等。

基本要求:

基本功能:

1、新进图书基本信息的输入。

2、图书基本信息的查询。

3、对撤消图书信息的删除。

4、为借书人办理注册。

5、办理借书手续(非注册会员不能借书)。

6、办理还书手续。

7、统计图书库存、已借出图书数量。

需要创建三个文本文件:record.txtbook.txtreader.txt

operating.h的头文件:

#includeiostream

#includefstream

#includestring

#includetime.h

#includesstream

#includevector

#includeiomanip

usingnamespacestd;

intall_stock=0;

intout_stock=0;

inttimes=0;

voidoutData(vectorstringres,intn)

//n为txt中每行数据个数

for(inti=0;ires.size();i+=n){

for(intj=0;jj++)

coutsetw(12)res[i+j]"";

coutendl;

}

voidBookEntry()

doubleprice;

stringbookname,writer;

fstreamout;

out.open("book.txt",ios::app);

if(!out)

{

cerr"打开文件失败!"endl;

}

time_ttt=time(NULL);//这句返回的只是一个时间cuo

cout"请输入书籍名称"endl;

cinbookname;

cout"请输入书籍作者"endl;

cinwriter;

cout"请输入书籍价格"endl;

while(!(cinprice)

||price=0)

{

cin.clear();

cin.ignore(100,'\n');

cout"请输入正确的价格"endl;

}

outtt""bookname""writer""price"""0""\n";

out.close();

voidBookMes()

fstreamin;

stringline;

//用于存放分割后的字符串

vectorstringres;

stringtemp;//暂存字符串

in.open("book.txt",ios::in);

if(!in)

{

cerr"打开文件失败!"endl;

}

all_stock=0;

while(getline(in,line))

{

all_stock++;

//coutlineendl;

//将字符串读到input中

stringstreaminput(line);//将line切割通过input存入temp,然后存入res中

while(inputtemp)

{

res.push_back(temp);

}

}

//0书籍编号1书籍名称2作者3价格4书籍状态

//输出res

coutendlsetw(12)"书籍编号"""setw(12)"书籍名称"""setw(12)"作者"""setw(12)"价格"""setw(12)"在馆0,不在1""\n";

outData(res,5);

in.close();

voidDelBook()

stringdel_book;

stringline;

vectorstring

stringtemp;

boolflag=false;

fstreamin;

in.open("book.txt",ios::in);

if(!in)

{

cerr"打开错误文件"endl;

}

cout"请输入需要删除的图书ID"endl;

cindel_book;

while(getline(in,line))

{

//coutlineendl;

//将字符串读到input中

stringstreaminput(line);//将line切割通过input存入temp,然后存入res中

times=0;

while(inputtemp)

{

if(del_book==temptimes==0)

{

for(inti=0;ii++)

//因为一共五个第一个temp已经是del_book所以这里取得是四个

{

inputtemp;

}

inputtemp;

if(temp!="0")

{

cout"书籍状态不对";

in.close();

return;

}

flag=true;

cout"\n找到了喔,应该删除成功了\n";

continue;

}

res.push_back(temp);

times++;

}

}

//outData(res,5);

in.close();

if(!flag)

{

cout"\n错误的书籍ID\n";

return;

}

fstreamout;

out.open("book.txt",ios::out);

if(!out)

{

cerr"打开文件失败!"endl;

}

for(intj=0;jres.size();j+=5)

{

line=res[j]+""+res[j+1]+""+res[j+2]+""+res[j+3]+""+res[j+4]+"\n";

outline;

}

out.close();

voidReaderEntry()

stringreadername,sex_str;

intsex;

fstreamout;

out.open("reader.txt",ios::app);

if(!out)

{

cerr"打开文件失败!"endl;

}

time_treaderid=time(NULL);//这句返回的只是一个时间cuo

cout"请输入读者姓名"endl;

cinreadername;

do

{

cout"请输入读者性别:0为女,1为男"endl;

while(!(cinsex))

{

cin.clear();

cin.ignore(100,'\n');

cout"请输入正确的0或1"endl;

}

}while(sex!=0sex!=1);

if(sex==1)

{

sex_str="男";

}elseif(sex==0){

sex_str="女";

}else{

out.close();

return;

}

outreaderid""readername""sex_str"\n";

out.close();

/*读者信息*/

voidReaderMes()

fstreamin;

stringline;

//用于存放分割后的字符串

vectorstringres;

stringtemp;//暂存字符串

in.open("reader.txt",ios::in);

if(!in)

{

cerr"打开文件失败!"endl;

}

while(getline(in,line))

{

//coutlineendl;

//将字符串读到input中

stringstreaminput(line);//将line切割通过input存入temp,然后存入res中

while(inputtemp)

res.push_back(temp);

}

//0读者学号1读者姓名2读者性别

//输出res

coutendlsetw(12)"读者编号"""setw(12)"读者"""setw(12)"性别""\n";

outData(res,3);

in.close();

/*借阅书籍*/

voidBorrowBook()

stringbook[5];

stringreaderid;

stringreadername;

stringline;

vectorstring//取书籍状况,并且更新

stringtemp;

boolflag_book=false;//用于判断书籍是否存在

读者是否存在

boolflag_reader=false;

/*取book的图书情况,并判断是否在馆*/

fstreamin;

in.open("book.txt",ios::in);

if(!in)

{

cerr"打开错误文件"endl;

}

cout"请输入需要借的图书ID"endl;

cinbook[0];

while(getline(in,line))

{

//coutlineendl;

//将字符串读到input中

stringstreaminput(line);//将line切割通过input存入temp,然后存入res中

times=0;

while(inputtemp)

{

if(book[0]==temptimes==0)

{

res.push_back(temp);

for(inti=0;ii++)

//从书籍名称开始取,一直取到价钱

{

inputtemp;//读取了书籍编号,要及时写入res,以后要写进文本

book[1+i]=temp;

res.push_back(temp);

}

inputtemp;

//取书籍状态,如果0在馆如果1不在馆

if(temp=="0")

{

book[4]="1";

temp="1";

res.push_back(temp);

flag_book=true;

}else{

cout"\n书籍不在馆\n";

in.close();

return;

}

continue;

//继续取

}

res.push_back(temp);

times++;

}

}

in.close();

if(!flag_book)

{

cout"错误的书籍ID"endl;

return;

}

in.open("reader.txt",ios::in);

if(!in)

{

cerr"打开错误文件"endl;

}

cout"\n请输入读者ID\n";

cinreaderid;

while(getline(in,line))

{

//coutlineendl;

//将字符串读到input中

stringstreaminput(line);//将line切割通过input存入temp,然后存入res中

times=0;

while(inputtemp)

{

if(readerid==temptimes==0)

{

inputtemp;

readername=temp;

flag_reader=true;

break;

}

times++;

}

}

if(!flag_reader)

{

cout"错误的读者ID"endl;

in.close();

return;

}

in.close();

fstreamout;

out.open("record.txt",ios::app);

if(!out)

{

cerr"打开错误文件"endl;

}

line=book[0]+""+book[1]+""+readername+'\n';

outline;

cout"\n办理借书成功\n";

out.close();

out.open("book.txt",ios::out);

if(!out)

{

cerr"打开文件失败!"endl;

}

for(intj=0;jres.size();j+=5)

{

line=res[j]+""+res[j+1]+""+res[j+2]+""+res[j+3]+""+res[j+4]+"\n";

outline;

}

out.close();

voidBorrowMes()

fstreamin;

stringline;

//用于存放分割后的字符串

vectorstringres;

stringtemp;//暂存字符串

in.open("record.txt",ios::in);

if(!in)

{

cerr"打开文件失败!"endl;

}

out_stock=0;

while(getline(in,line))

{

out_stock++;

//coutlineendl;

//将字符串读到input中

stringstreaminput(line);//将line切割通过input存入temp,然后存入res中

while(inputtemp)

res.push_back(temp);

}

//0书籍编号1书籍名称2读者姓名

//输出res

coutendlsetw(12)"书籍编号"""setw(12)"书籍名称"""setw(12)"读者""\n";

outData(res,3);

in.close();

voidRtnBook()

stringrtn_book;

stringline;

vectorstring

stringtemp;

boolflag=false;

fstreamin;

in.open("record.txt",ios::in);

//先打开record查看是否有借这本书

if(!in)

{

cerr"打开错误文件"endl;

}

cout"请输入需要归还的书籍ID"endl;

cinrtn_book;

while(getline(in,line))

{

//coutlineendl;

//将字符串读到input中

stringstreaminput(line);//将line切割通过input存入temp,然后存入res中

times=0;

while(inputtemp)

{

if(rtn_book==temptimes==0)//如果有的话

{

flag=true;

for(inti=0;ii++)

//因为一共三个第一个temp已经是del_book所以这里取得是两个

{

inputtemp;//将删除的东西不输出到向量中

}

continue;

}

res.push_back(temp);

times++;

}

}

//outData(res,3);

in.close();

if(!flag)

{

cout"该图书不存在或者没有被外借"endl;

return;

}

fstreamout;

out.open("record.txt",ios::out);//record已经删除成功

if(!out)

{

cerr"打开文件失败!"endl;

}

for(intj=0;jres.size();j+=3)

{

line=res[j]+""+res[j+1]+""+res[j+2]

+"\n";

outline;

}

out.close();

vectorstringres_book;

in.open("book.txt",ios::in);//开始取被修改的书籍

if(!in)

{

cerr"打开错误文件"endl;

}

while(getline(in,line))

{

//coutlineendl;

//将字符串读到input中

stringstreaminput(line);//将line切割通过input存入temp,然后存入res中

times=0;

while(inputtemp)

{

if(rtn_book==temptimes==0)

{

res_book.push_back(temp);

for(inti=0;ii++)

//因为一共五个第一个temp已经是rtn_book所以这里取得是四个

{

inputtemp;

res_book.push_back(temp);

}

inputtemp;//最后一个取得是书籍状态,需要修改书籍状态

temp="0";

res_book.push_back(temp);

continue;

}

res_book.push_back(temp);

times++;

}

}

//outData(res,5);

in.close();

out.open("book.txt",ios::out);//再存入文本中;

if(!out)

{

cerr"打开文件失败!"endl;

}

for(intj=0;jres_book.size();j+=5)

{

line=res_book[j]+""+res_book[j+1]+""+res_book[j+2]+""+res_book[j+3]+""+res_book[j+4]+"\n";

outline;

}

out.close();

cout"\n找到了喔,应该还书成功了\n";

voidCountBook()

{

cout"\n图书馆书籍情况";

BookMes();

cout"图书馆一共有:"all_stock"本书\n\n\n";

cout"\n图书馆书籍外借情况";

BorrowMes();

cout"图书馆目前外借:"out_stock"本书\n\n";

cout"\n\n图书馆当前在馆书籍还有:"all_stock-out_stock"本书\n";

}

main.cpp的主函数

#include"operating.h"

intmain()

intorder;

do

{

order=-1;

cout"\n";

cout"----------------------------------------------------------\n";

cou

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论