图书管理系统程序代码.docx_第1页
图书管理系统程序代码.docx_第2页
图书管理系统程序代码.docx_第3页
图书管理系统程序代码.docx_第4页
图书管理系统程序代码.docx_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

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

文档简介

#include#include#include#include#include#include#include #include#include/改变字体颜色 #define NONE 033m#define RED 0330;32;31m#define GREEN 0330;32;32m#define BLUE 0330;32;34m#define YELLOW 0331;33m#define LIGHT_RED 0331;31m#define LIGHT_GREEN 0331;32m#define LIGHT_BLUE 0331;34m/*程序导读:1.程序中对书的操作,可通过书名,编号来进行,flag=0按书名来操作,flag=1按书编号来操作2.程序中对用户的操作,也可通过姓名,用户ID号或编号两种方式来进行,flag=0按姓名来操作, flag=1按用户ID号或编号来操作3.本程序分5个部分,具体已标识如(1)图书管理.*/using namespace std;class Bookpublic:string book_name;string book_num;/编号string book_pre;/出版社string book_aut;/作者int book_con;/这样的书还有几本int book_mux;/这样的书总共有几本public:Book()book_con=0;book_mux=0;void show_book();/*(1)图书管理*/void Book:show_book()cout书名:book_nameendl;cout出版社:book_preendl;cout此书的作者:book_autendl;coutISBN编号:book_numendl;cout此书共有book_mux本endl;cout还有book_con本书未借出!endl;class BookNodepublic:Book book;BookNode *next;BookNode *headbook=NULL;class BookManagepublic:int totolbook;public:BookManage()totolbook=0;void addbook();void delbook(string s,int num,int flag);void findbook(string s,int flag);/查询图书;void BookManage:addbook()string h;cout添加输入0,退出输入-1h;if(h=-1)return;else if(h=0)while(1)if(h=-1)break;else if(h=0)string na,nu,p1,aut;int con;BookNode *p=new BookNode;cout请输入书名:na;p-book.book_name=na;cout请输入ISBN编号:nu;p-book.book_num=nu;cout请输入出版社:p1;p-book.book_pre=p1;cout请输入此书的作者:aut;p-book.book_aut=aut;cout请输入此书共有几本:con;p-book.book_con=con;p-book.book_mux=con;p-next=headbook;headbook=p;BookManage:totolbook+=con;cout继续添加输入0,取消添加输入-1h;elsecoutYELLOW输入字符无效!NONEendl;elsecoutYELLOW输入字符无效!NONEbook.book_name=s)if(headbook-book.book_con1)headbook-book.book_con-=num;headbook-book.book_mux-=num;elseheadbook=p-next;totolbook-=num;/delete p;else if(p-next)for(p=headbook;p-next!=NULL&p!=NULL;p=p-next)if(p-next-book.book_name=s)if(p-next-book.book_con1)p-next-book.book_con-=num;headbook-book.book_mux-=num;break;elsep-next=p-next-next;totolbook-=num;/delete p-next;break;if(p-next=NULL)coutYELLOW此书不存在!NONEbook.book_num=s)if(headbook-book.book_con1)headbook-book.book_con-=num;headbook-book.book_mux-=num;elseheadbook=p-next;totolbook-=num;/delete p;else if(p-next)for(p=headbook;p-next!=NULL&p!=NULL;p=p-next)if(p-next-book.book_num=s)if(p-next-book.book_con1)p-next-book.book_con-=num;headbook-book.book_mux-=num;break;elsep-next=p-next-next;totolbook-=num;/delete p-next;break;if(p-next=NULL)coutYELLOW此书不存在!NONEendl;break;default:coutYELLOW输入数字无效!NONEnext)/先查看是否有此书if(p-book.book_name=s)break;if(NULL=p)coutYELLOW此书不存在!NONEnext)/查看名为s的图书共有几本if(p-book.book_name=s)h+;if(h0)coutGREEN这种名字的书共有h本NONEnext)/查看图书,把所有名为s的图书的信息都打印出来if(p-book.book_name=s)p-book.show_book();/显示出图书的基本信息if(p-book.book_con=0)coutYELLOW该书已全被借出!NONEendl;coutnext)if(p-book.book_num=s)p-book.show_book();if(p-book.book_con=0)coutYELLOW该书已全被借出!NONEendl;break;if(NULL=p)coutYELLOW此书不存在!NONEendl;break;default:coutYELLOW输入数字无效!NONEendl;break;/*(2)用户管理*/class Admin/管理员public:string adm_name;/帐号string adm_passw;/密码public:Admin()adm_name=adm;adm_passw=123;class LendBookpublic:string bookname3;int count;/借多少本数time_t lend_time;time_t back_time;LendBook()count=0;class Stupublic:string stu_name;string stu_phone;/联系方式string stu_num;/学号(登录帐号)string password;/密码float debt;/欠费额LendBook lendbook;/用户借书信息public:void show_stu();/把此人所有信息(包括借书)显示出来;void Stu:show_stu()cout姓名:stu_nameendl;cout联系电话:stu_phoneendl;coutID:stu_numendl;cout欠费额:debtendl;cout已借书lendbook.count本endl;class StuNodepublic:Stu stu;StuNode *next;StuNode *headstu=NULL;class StuManage:public BookManageprivate:int totolstu;/用户总数public:StuManage()totolstu=0;void addstu();/增加用户void delstu(string s,int flag);/删除用户void findstu(string s,int flag);/查找用户void lendbook(string ss,string s,int flag);/借书void backbook(string ss,string s,int flag);/还书void paydebt(string s);/还款void mux_stu_book();/查询图书管总的图书量与总的用户量;void StuManage:addstu()string h;cout添加输入0,退出输入-1h;if(h=-1)return;else if(h=0)while(1)if(h=-1)break;else if(h=0)string na,num,p1,pa,pa1,pa2;StuNode *p=new StuNode;cout请输入姓名:na;p-stu.stu_name=na;cout请输入联系电话:p1;p-stu.stu_phone=p1;cout请输入ID:num;p-stu.stu_num=num;p-stu.lendbook.lend_time=0;p-stu.lendbook.back_time=0;while(1)cout请输入六位密码:pa1;cout请确认六位密码:pa2;if(pa1=pa2)pa=pa2;p-stu.password=pa;break;elsecoutYELLOW两次密码不一样,请重行输入!NONEstu.debt=0;p-next=headstu;headstu=p;(StuManage:totolstu)+;/用户总数加一cout继续添加输入0,取消添加输入-1h;elsecoutYELLOW输入字符无效!NONEendl;elsecoutYELLOW输入字符无效!NONEstu.stu_name=s)/当要删除的用户位于链表的头结点位置headstu=p-next;StuManage:totolstu-;delete p;else if(p-next)/非头结点位置for(p=headstu;p-next!=NULL&p!=NULL;p=p-next)if(p-next-stu.stu_name=s)p-next=p-next-next;totolstu-;/delete p-next;break;if(p-next=NULL)coutYELLOW此用户不存在!NONEstu.stu_name=s)headstu=p-next;totolstu-;delete p;else if(p-next)for(p=headstu;p-next!=NULL&p!=NULL;p=p-next)if(p-next-stu.stu_name=s)p-next=p-next-next;totolstu-;/delete p-next;break;if(p-next=NULL)coutYELLOW此用户不存在!NONEendl;break;default:coutYELLOW输入数字无效!NONEnext)if(p-stu.stu_name=s)break;if(p=NULL)coutYELLOW此用户不存在!NONEnext)if(p-stu.stu_name=s)h+;if(h0)coutGREEN这种名字的用户共有h个NONEnext)if(p-stu.stu_name=s)p-stu.show_stu();if(p-stu.lendbook.count=3)coutYELLOWsorry,您已借满3本书,不能再借了!NONEstu.lendbook.count;if(i0)cout所借书的名字为:endl;/输出用户所借书的名字while(i)coutt(m+):stu.lendbook.booknamei-1endl;i-;coutstu.lendbook.count;if(i0)cout所借书的名字为:endl;/输出用户所借书的名字while(i)coutt(m+):stu.lendbook.booknamei-1endl;i-;cout您已借了stu.lendbook.count本书!endl;cout您还可以借stu.lendbook.count本书!endl;coutnext)if(p-stu.stu_num=s)p-stu.show_stu();if(p-stu.lendbook.count=3)coutYELLOWsorry,您已借满3本书,不能再借了!NONEstu.lendbook.count;cout所借书的名字为:endl;/输出用户所借书的名字while(i)/输出用户所借书的名字coutt(m+):stu.lendbook.booknamei-1endl;i-;coutstu.lendbook.count;cout所借书的名字为:endl;/输出用户所借书的名字while(i)/输出用户所借书的名字coutt(m+):stu.lendbook.booknamei-1endl;i-;cout您已借了stu.lendbook.count本书!endl;cout您还可以借stu.lendbook.count本书!NONEendl;coutendl;break;if(p=NULL)coutYELLOW此用户不存在!NONEendl;break;default:coutYELLOW输入数字无效!NONEnext)i+;cout当前图书馆注册用户数为:inext)h+=q-book.book_mux;j+=q-book.book_con;cout当前图书馆库存的总书数为:jendl;cout已借出图书总数为:h-jnext)if(q-stu.stu_num=ss)break;if(q=NULL)coutYELLOW此用户不存在!NONEnext)if(p-book.book_name=s)int i=q-stu.lendbook.count;if(i=3|q-stu.debt0)if(i=3)&(q-stu.debt=0)coutYELLOW对不起,您借书已超过3本,不能再借!NONEendl;if(istu.debt0)coutYELLOW对不起,您因为所借图书超期已欠费,请速交清欠费再借!NONE=3)&(q-stu.debt0)coutYELLOW对不起,您借书已超过3本且有欠费,不能再借!NONEstu.lendbook.booknamei=p-book.book_name;time_t now;time(&now);q-stu.lendbook.lend_time=time(&now);/保存借书时间q-stu.lendbook.count+;/所借书数目加一p-book.book_con-;/同样的书的个数减一break;if(p=NULL)coutYELLOW此书不存在!NONEnext)if(p-book.book_num=s)int i=q-stu.lendbook.count;if(i=3|q-stu.debt0)if(i=3)&(q-stu.debt=0)coutYELLOW对不起,您借书已超过3本,不能再借!NONEendl;if(istu.debt0)coutYELLOW对不起,您因为所借图书超期已欠费,请速交清欠费再借!NONE=3)&(q-stu.debt0)coutYELLOW对不起,您借书已超过3本且有欠费,不能再借!NONEstu.lendbook.booknamei=p-book.book_name;time_t now;time(&now);q-stu.lendbook.lend_time=time(&now);q-stu.lendbook.count+;p-book.book_con-;/同样的书的个数减一break;if(p=NULL)coutYELLOW此书不存在!NONEendl;break;default:coutYELLOW输入数字无效!NONEnext)if(q-stu.stu_num=ss)break;if(q=NULL)coutYELLOW此用户不存在!NONEnext)if(p-book.book_name=s)time_t now;time(&now);q-stu.lendbook.back_time=time(&now);q-stu.lendbook.count-;p-book.book_con+;/同样的书的个数加一time_t s=difftime(q-stu.lendbook.lend_time,q-stu.lendbook.back_time);if(s2592000)/2592000为一个月的秒数int t=ceil(s-2592000)/86400);q-stu.debt=t*0.1;break;if(p=NULL)coutYELLOW此书不存在!NONEnext)if(p-book.book_num=s)time_t now;time(&now);q-stu.lendbook.back_time=time(&now);q-stu.lendbook.count-;p-book.book_con+;/同样的书的个数加一/计算借用图书的时间,超过一个月,开始计费time_t s=difftime(q-stu.lendbook.lend_time,q-stu.lendbook.back_time);if(s2592000)/2592000为一个月的秒数int t=ceil(s-2592000)/86400);q-stu.debt=t*0.1;break;if(p=NULL)coutYELLOW此书不存在!NONEendl;break;default:coutYELLOW输入数字无效!NONEnext)/查找用户if(p-stu.stu_num=s)p-stu.debt=0;coutRED缴费成功!NONEendl;break;if(p=NULL)coutYELLOW该用户不存在!NONEendl;/*(3)数据保存与下载*/void savestu()/保存读者信息文件ofstream outfile(./stu.txt,ios:out); if(!outfile)cerropen error!next)/数据写入文件outfilestu.stu_name stu.stu_phone;outfile stu.password stu.stu_num;outfile stu.debt;outfile stu.lendbook.lend_time;outfile stu.lendbook.back_time;outfile stu.lendbook.count;outfile endl;outfile.close();void savebook()/保存图书信息文件ofstream outfile(./book.txt,ios:out); if(!outfile)cerropen error!next)/数据写入文件outfilebook.book_name book.book_num;outfile book.book_pre book.book_aut;outfile book.book_mux;outfile book.book_con;outfile endl;outfile.close();void loadstu()/从学生数据文件读取ifstream infile(./stu.txt,ios:in);if(!infile)coutYELLOW数据文件不存在,请先建立该文件NONEendl;return;if(infile.eof()coutYELLOW数据库为空,请添加数据NONEp-stu.stu_namep-stu.stu_phone;infilep-stu.passwordp-stu.stu_num;infilep-stu.debtp-stu.lendbook.lend_time;infilep-stu.lendbook.back_timep-stu.lendbook.count;if(p-stu.stu_name!=)p-next=headstu;/建立用户链表headstu=p;elsedelete p;infile.close();void loadbook()/从书数据文件读取 ifstream infile(./book.txt,ios:in);if(!infile)coutYELLOW数据文件不存在,请先建立该文件NONEendl;return;if(infile.eof()coutYELLOW数据库为空,请添加数

温馨提示

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

评论

0/150

提交评论