用mysql数据库实现的C图书管理系统.docx

上传人:wj 文档编号:2147296 上传时间:2023-05-02 格式:DOCX 页数:35 大小:23.70KB
下载 相关 举报
用mysql数据库实现的C图书管理系统.docx_第1页
第1页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第2页
第2页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第3页
第3页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第4页
第4页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第5页
第5页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第6页
第6页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第7页
第7页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第8页
第8页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第9页
第9页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第10页
第10页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第11页
第11页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第12页
第12页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第13页
第13页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第14页
第14页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第15页
第15页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第16页
第16页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第17页
第17页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第18页
第18页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第19页
第19页 / 共35页
用mysql数据库实现的C图书管理系统.docx_第20页
第20页 / 共35页
亲,该文档总共35页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

用mysql数据库实现的C图书管理系统.docx

《用mysql数据库实现的C图书管理系统.docx》由会员分享,可在线阅读,更多相关《用mysql数据库实现的C图书管理系统.docx(35页珍藏版)》请在冰点文库上搜索。

用mysql数据库实现的C图书管理系统.docx

#include

#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"

/*

在编译程序之前,请先开启mysql服务器(命令为sudomysqld_safe&),然后再登录mysql客户端(命令为mysql-uroot-p)建立数据库stu;建立数据表reader,book;具体操作语句如下:

createdatabasestu;

createtablereader(stu_namevarchar(20),stu_phonevarchar(15),stu_passwordvarchar(10),stu_numint,debtfloat,lend_timedouble,back_timedouble,countint);

createtablebook(book_namevarchar(40),book_autvarchar(40),book_prevarchar(40),book_numint,book_muxint,book_conint);

编译时用如下命令:

g++$(mysql_config--cflags)110.cpp-ot$(mysql_config--libs)

*/

//定义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;//这样的书总共有几本

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;

voidsavebook(BookNode*p);//保存图书信息到数据库

voiddel_sql_book(BookNode*p);//将图书信息从数据库中删除

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;

savebook(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;

del_sql_book(p);//从数据库中删除

//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;

del_sql_book(p->next);//从数据库中删除

//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;

del_sql_book(p);//从数据库中删除

//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;

del_sql_book(p->next);//从数据库中删除

//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;

voidsavestu(StuNode*p);//保存读者信息到数据库

voiddel_sql_stu(StuNode*p);//将读者信息从数据库中删除

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;

savestu(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--;

del_sql_stu(p);//从数据库中删除

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--;

del_sql_stu(p->next);//从数据库中删除

//deletep->next;

break;

}

}

if(p->next==NULL)

cout<

"NONE<

}

break;

case1:

if(headstu->stu.stu_name==s)

{

headstu=p->next;

totolstu--;

del_sql_stu(p);//从数据库中删除

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--;

del_sql_stu(p->next);//从数据库中删除

//deletep->next;

break;

}

}

if(p->next==NULL)

cout<

"NONE<

}

break;

default:

cout<

"NONE<

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2