图书管理系统程序代码.docx
- 文档编号:4886195
- 上传时间:2023-05-07
- 格式:DOCX
- 页数:46
- 大小:23.99KB
图书管理系统程序代码.docx
《图书管理系统程序代码.docx》由会员分享,可在线阅读,更多相关《图书管理系统程序代码.docx(46页珍藏版)》请在冰点文库上搜索。
图书管理系统程序代码
#include
#include
#include
#include
#include
#include
#include
#include
#include
//改变字体颜色
#defineNONE"\033[m"
#defineRED"\033[0;32;31m"
#defineGREEN"\033[0;32;32m"
#defineBLUE"\033[0;32;34m"
#defineYELLOW"\033[1;33m"
#defineLIGHT_RED"\033[1;31m"
#defineLIGHT_GREEN"\033[1;32m"
#defineLIGHT_BLUE"\033[1;34m"
/*
程序导读:
1.程序中对书的操作,可通过书名,编号来进行,flag=0按书名来操作,flag=1按书编号来操作
2.程序中对用户的操作,也可通过姓名,用户ID号或编号两种方式来进行,flag=0按姓名来操作,
flag=1按用户ID号或编号来操作
3.本程序分5个部分,具体已标识如
(1)图书管理...
*/
usingnamespacestd;
classBook
{
public:
stringbook_name;
stringbook_num;//编号
stringbook_pre;//出版社
stringbook_aut;//作者
intbook_con;//这样的书还有几本
intbook_mux;//这样的书总共有几本
public:
Book(){book_con=0;book_mux=0;}
voidshow_book();
};
/****************************************
(1)图书管理*******************************************/
voidBook:
:
show_book()
{
cout<<"书名:
"< cout<<"出版社: "< cout<<"此书的作者: "< cout<<"ISBN编号: "< cout<<"此书共有"< cout<<"还有"< "< } classBookNode { public: Bookbook; BookNode*next; }; BookNode*headbook=NULL; classBookManage { public: inttotolbook; public: BookManage(){totolbook=0;} voidaddbook(); voiddelbook(strings,intnum,intflag); voidfindbook(strings,intflag);//查询图书 }; voidBookManage: : addbook() { stringh; cout<<"添加输入0,退出输入-1"< cin>>h; if(h=="-1")return; elseif(h=="0") while (1) { if(h=="-1")break; elseif(h=="0") { stringna,nu,p1,aut;intcon; BookNode*p=newBookNode; cout<<"请输入书名: "< cin>>na; p->book.book_name=na; cout<<"请输入ISBN编号: "< cin>>nu; p->book.book_num=nu; cout<<"请输入出版社: "< cin>>p1; p->book.book_pre=p1; cout<<"请输入此书的作者: "< cin>>aut; p->book.book_aut=aut; cout<<"请输入此书共有几本: "< cin>>con; p->book.book_con=con; p->book.book_mux=con; p->next=headbook; headbook=p; BookManage: : totolbook+=con; cout<<"继续添加输入0,取消添加输入-1"< cin>>h; } else cout< "NONE< } else cout< "NONE< } voidBookManage: : delbook(strings,intnum,intflag) { BookNode*p=headbook; if(headbook! =NULL) { switch(flag) { case0: if(headbook->book.book_name==s) { if(headbook->book.book_con>1) {headbook->book.book_con-=num;headbook->book.book_mux-=num;} else { headbook=p->next; totolbook-=num; //deletep; } } elseif(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_con>1) { p->next->book.book_con-=num;headbook->book.book_mux-=num; break; } else { p->next=p->next->next; totolbook-=num; //deletep->next; break; } } } if(p->next==NULL) cout< "NONE< } break; case1: if(headbook->book.book_num==s) { if(headbook->book.book_con>1) {headbook->book.book_con-=num;headbook->book.book_mux-=num;} else { headbook=p->next; totolbook-=num; //deletep; } } elseif(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_con>1) { p->next->book.book_con-=num;headbook->book.book_mux-=num; break; } else { p->next=p->next->next; totolbook-=num; //deletep->next; break; } } } if(p->next==NULL) cout< "NONE< } break; default: cout< "NONE< } } } voidBookManage: : findbook(strings,intflag) { BookNode*p;inth=0; switch(flag) { case0: for(p=headbook;p! =NULL;p=p->next)//先查看是否有此书 { if(p->book.book_name==s) break; } if(NULL==p) cout< "NONE< for(p=headbook;p! =NULL;p=p->next)//查看名为s的图书共有几本 { if(p->book.book_name==s) h++; } if(h>0) cout< for(p=headbook;p! =NULL;p=p->next)//查看图书,把所有名为s的图书的信息都打印出来 { if(p->book.book_name==s) { p->book.show_book();//显示出图书的基本信息 if(p->book.book_con==0) cout< "NONE< cout< } } break; case1: for(p=headbook;p! =NULL;p=p->next) { if(p->book.book_num==s) { p->book.show_book(); if(p->book.book_con==0) cout< "NONE< } } if(NULL==p) cout< "NONE< break; default: cout< "NONE< } } /**************************************** (2)用户管理*******************************************/ classAdmin//管理员 { public: stringadm_name;//帐号 stringadm_passw;//密码 public: Admin() { adm_name="adm"; adm_passw="123"; } }; classLendBook { public: stringbookname[3]; intcount;//借多少本数 time_tlend_time; time_tback_time; LendBook(){count=0;} }; classStu { public: stringstu_name; stringstu_phone;//联系方式 stringstu_num;//学号(登录帐号) stringpassword;//密码 floatdebt;//欠费额 LendBooklendbook;//用户借书信息 public: voidshow_stu();//把此人所有信息(包括借书)显示出来 }; voidStu: : show_stu() { cout<<"姓名: "< cout<<"联系电话: "< cout<<"ID: "< cout<<"欠费额: "< cout<<"已借书"< } classStuNode { public: Stustu; StuNode*next; }; StuNode*headstu=NULL; classStuManage: publicBookManage { private: inttotolstu;//用户总数 public: StuManage(){totolstu=0;} voidaddstu();//增加用户 voiddelstu(strings,intflag);//删除用户 voidfindstu(strings,intflag);//查找用户 voidlendbook(stringss,strings,intflag);//借书 voidbackbook(stringss,strings,intflag);//还书 voidpaydebt(strings);//还款 voidmux_stu_book();//查询图书管总的图书量与总的用户量 }; voidStuManage: : addstu() { stringh; cout<<"添加输入0,退出输入-1"< cin>>h; if(h=="-1")return; elseif(h=="0") while (1) { if(h=="-1")break; elseif(h=="0") { stringna,num,p1,pa,pa1,pa2; StuNode*p=newStuNode; cout<<"请输入姓名: "< cin>>na; p->stu.stu_name=na; cout<<"请输入联系电话: "< cin>>p1; p->stu.stu_phone=p1; cout<<"请输入ID: "< cin>>num; p->stu.stu_num=num; p->stu.lendbook.lend_time=0; p->stu.lendbook.back_time=0; while (1) { cout<<"请输入六位密码: "< cin>>pa1; cout<<"请确认六位密码: "< cin>>pa2; if(pa1==pa2) { pa=pa2; p->stu.password=pa; break; } else cout< "NONE< } p->stu.debt=0; p->next=headstu; headstu=p; (StuManage: : totolstu)++;//用户总数加一 cout<<"继续添加输入0,取消添加输入-1"< cin>>h; } else cout< "NONE< } else cout< "NONE< } voidStuManage: : delstu(strings,intflag) { StuNode*p=headstu; if(headstu! =NULL) { switch(flag) { case0: if(headstu->stu.stu_name==s)//当要删除的用户位于链表的头结点位置 { headstu=p->next; StuManage: : totolstu--; deletep; } elseif(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--; //deletep->next; break; } } if(p->next==NULL) cout< "NONE< } break; case1: if(headstu->stu.stu_name==s) { headstu=p->next; totolstu--; deletep; } elseif(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--; //deletep->next; break; } } if(p->next==NULL) cout< "NONE< } break; default: cout< "NONE< } } } voidStuManage: : findstu(strings,intflag) { StuNode*p;inth=0,m=1; switch(flag) { case0: for(p=headstu;p! =NULL;p=p->next) { if(p->stu.stu_name==s) break; } if(p==NULL) cout< "NONE< for(p=headstu;p! =NULL;p=p->next) { if(p->stu.stu_name==s) h++; } if(h>0) cout< for(p=headstu;p! =NULL;p=p->next) { if(p->stu.stu_name==s) { p->stu.show_stu(); if(p->stu.lendbook.count>=3) { cout< ! ! "NONE< inti=p->stu.lendbook.count; if(i>0) cout<<"所借书的名字为: "< while(i) { cout<<"\t("< "< } cout< } else { inti=p->stu.lendbook.count; if(i>0) cout<<"所借书的名字为: "< while(i) { cout<<"\t("< "< } cout<<"您已借了"< "< cout<<"您还可以借"<<3-p->stu.lendbook.count<<"本书! "< cout< } } } break; case1: for(p=headstu;p! =NULL;p=p->next) { if(p->stu.stu_num==s) { p->stu.show_stu(); if(p->stu.lendbook.count>=3) { cout< ! ! "NONE< inti=p->stu.lendbook.count;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 图书 管理 系统 程序代码