用mysql数据库实现的C图书管理系统Word文件下载.docx
- 文档编号:4023367
- 上传时间:2023-05-02
- 格式:DOCX
- 页数:35
- 大小:23.70KB
用mysql数据库实现的C图书管理系统Word文件下载.docx
《用mysql数据库实现的C图书管理系统Word文件下载.docx》由会员分享,可在线阅读,更多相关《用mysql数据库实现的C图书管理系统Word文件下载.docx(35页珍藏版)》请在冰点文库上搜索。
*/
//定义mysql数据库变量
MYSQLmysql;
MYSQL_RES*results;
MYSQL_FIELD*fileds;
MYSQL_ROWrows;
charstrHost[]="
localhost"
;
charstrUser[]="
root"
charstrPasswd[]="
3335599"
charstrDb[]="
stu"
charstrSQL[200];
unsignedintnum_fields;
程序导读:
1.程序中对书的操作,可通过书名,编号来进行,flag=0按书名来操作,flag=1按书编号来操作
2.程序中对用户的操作,也可通过姓名,用户ID号或编号两种方式来进行,flag=0按姓名来操作,
flag=1按用户ID号或编号来操作
3.本程序分5个部分,具体已标识如
(1)图书管理...
4.本程序即可实现将数据保存至本地即stu.txt,book.txt,又可将数据保存至mysql数据库,只
需稍加修改,具体如何修改,在此就不做说明
usingnamespacestd;
classBook
{
public:
stringbook_name;
stringbook_num;
//编号
stringbook_pre;
//出版社
stringbook_aut;
//作者
intbook_con;
//这样的书还有几本
intbook_mux;
//这样的书总共有几本
Book(){book_con=0;
book_mux=0;
}
voidshow_book();
};
/****************************************
(1)图书管理*******************************************/
voidBook:
:
show_book()
cout<
<
"
书名:
book_name<
endl;
出版社:
book_pre<
此书的作者:
book_aut<
ISBN编号:
book_num<
此书共有"
book_mux<
本"
还有"
book_con<
本书未借出!
classBookNode
Bookbook;
BookNode*next;
BookNode*headbook=NULL;
voidsavebook(BookNode*p);
//保存图书信息到数据库
voiddel_sql_book(BookNode*p);
//将图书信息从数据库中删除
classBookManage
{
inttotolbook;
BookManage(){totolbook=0;
voidaddbook();
voiddelbook(strings,intnum,intflag);
voidfindbook(strings,intflag);
//查询图书
voidBookManage:
addbook()
stringh;
添加输入0,退出输入-1"
cin>
>
h;
if(h=="
-1"
)return;
elseif(h=="
0"
)
while
(1)
{
if(h=="
)break;
elseif(h=="
{
stringna,nu,p1,aut;
intcon;
BookNode*p=newBookNode;
cout<
请输入书名:
cin>
na;
p->
book.book_name=na;
请输入ISBN编号:
nu;
book.book_num=nu;
请输入出版社:
p1;
book.book_pre=p1;
请输入此书的作者:
aut;
book.book_aut=aut;
请输入此书共有几本:
con;
book.book_con=con;
book.book_mux=con;
next=headbook;
headbook=p;
savebook(p);
//添加至数据库
BookManage:
totolbook+=con;
继续添加输入0,取消添加输入-1"
}
else
cout<
YELLOW"
输入字符无效!
NONE<
}
else
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;
del_sql_book(p);
//从数据库中删除
//deletep;
}
}
elseif(p->
next)
{
for(p=headbook;
p->
next!
=NULL&
&
p!
=NULL;
p=p->
{
if(p->
next->
{
if(p->
{
p->
break;
}
else
{
next=p->
totolbook-=num;
del_sql_book(p->
next);
//deletep->
}
if(p->
next==NULL)
cout<
此书不存在!
}
break;
case1:
book.book_num==s)
default:
cout<
输入数字无效!
break;
findbook(strings,intflag)
BookNode*p;
inth=0;
switch(flag)
case0:
for(p=headbook;
next)//先查看是否有此书
{
if(p->
}
if(NULL==p)
next)//查看名为s的图书共有几本
h++;
if(h>
0)
GREEN"
这种名字的书共有"
h<
next)//查看图书,把所有名为s的图书的信息都打印出来
{
p->
book.show_book();
//显示出图书的基本信息
book.book_con==0)
该书已全被借出!
}
break;
case1:
default:
/****************************************
(2)用户管理*******************************************/
classAdmin//管理员
stringadm_name;
//帐号
stringadm_passw;
//密码
Admin()
adm_name="
adm"
adm_passw="
123"
classLendBook
stringbookname[3];
intcount;
//借多少本数
time_tlend_time;
time_tback_time;
LendBook(){count=0;
classStu
stringstu_name;
stringstu_phone;
//联系方式
stringstu_num;
//学号(登录帐号)
stringpassword;
//密码
floatdebt;
//欠费额
LendBooklendbook;
//用户借书信息
voidshow_stu();
//把此人所有信息(包括借书)显示出来
voidStu:
show_stu()
姓名:
stu_name<
联系电话:
stu_phone<
ID:
stu_num<
欠费额:
debt<
已借书"
lendbook.count<
classStuNode
Stustu;
StuNode*next;
StuNode*headstu=NULL;
voidsavestu(StuNode*p);
//保存读者信息到数据库
voiddel_sql_stu(StuNode*p);
//将读者信息从数据库中删除
classStuManage:
publicBookManage
private:
inttotolstu;
//用户总数
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()
添加输入0,退出输入-1"
{
stringna,num,p1,pa,pa1,pa2;
StuNode*p=newStuNode;
请输入姓名:
stu.stu_name=na;
请输入联系电话:
stu.stu_phone=p1;
请输入ID:
num;
stu.stu_num=num;
stu.lendbook.lend_time=0;
stu.lendbook.back_time=0;
while
(1)
请输入六位密码:
cin>
pa1;
请确认六位密码:
pa2;
if(pa1==pa2)
pa=pa2;
stu.password=pa;
break;
else
两次密码不一样,请重行输入!
stu.debt=0;
next=headstu;
headstu=p;
savestu(p);
//保存至数据库
(StuManage:
totolstu)++;
//用户总数加一
delstu(strings,intflag)
StuNode*p=headstu;
if(headstu!
if(headstu->
stu.stu_name==s)//当要删除的用户位于链表的头结点位置
headstu=p->
StuManage:
totolstu--;
del_sql_stu(p);
deletep;
next)//非头结点位置
for(p=headstu;
stu.stu_name==s)
p->
totolstu--;
del_sql_stu(p->
//deletep->
break;
此用户不存在!
totolstu--;
brea
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- mysql 数据库 实现 图书 管理 系统