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

时间:2019-05-14 02:20:45下载本文作者:会员上传
简介:写写帮文库小编为你整理了多篇相关的《用mysql数据库实现的C++图书管理系统》,但愿对你工作学习有帮助,当然你在写写帮文库还可以找到更多《用mysql数据库实现的C++图书管理系统》。

第一篇:用mysql数据库实现的C++图书管理系统

#include #include #include #include #include

#include #include #include #include

#include //改变字体颜色

#define NONE “33[m” #define RED “33[0;32;31m” #define GREEN “33[0;32;32m” #define BLUE “33[0;32;34m” #define YELLOW “33[1;33m”

#define LIGHT_RED “33[1;31m” #define LIGHT_GREEN “33[1;32m” #define LIGHT_BLUE “33[1;34m” /* 在编译程序之前,请先开启mysql服务器(命令为 sudo mysqld_safe &),然后再登录mysql客户端(命令为 mysql-u root-p)建立数据库 stu;建立数据表reader,book;具体操作语句如下:

create database stu;

create table reader(stu_name varchar(20),stu_phone varchar(15),stu_password varchar(10),stu_num int,debt float,lend_time double,back_time double,count int);

create table book(book_name varchar(40),book_aut varchar(40),book_pre varchar(40),book_num int,book_mux int,book_con int);

编译时用如下命令:

g++ $(mysql_config--cflags)110.cpp-o t $(mysql_config--libs)*/

//定义mysql数据库变量

MYSQL

mysql;MYSQL_RES * results;

MYSQL_FIELD *fileds;

MYSQL_ROW rows;

char strHost[] = “localhost”;

char strUser[] = “root”;

char strPasswd[] = “3335599”;

char strDb[] = “stu”;char strSQL[200];

unsigned int num_fields;/* 程序导读:

1.程序中对书的操作,可通过书名,编号来进行,flag=0按书名来操作,flag=1按书编号来操作

2.程序中对用户的操作,也可通过姓名,用户ID号或编号两种方式来进行,flag=0按姓名来操作,flag=1按用户ID号或编号来操作

3.本程序分5个部分,具体已标识如(1)图书管理...4.本程序即可实现将数据保存至本地即stu.txt,book.txt,又可将数据保存至mysql数据库,只

需稍加修改,具体如何修改,在此就不做说明 */

using namespace std;class Book { public: 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<<“书名:”<

class BookNode { public: Book book;BookNode *next;};BookNode *headbook=NULL;

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

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

class BookManage {

public: 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,退出输入-1”<>h;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;savebook(p);//添加至数据库 BookManage::totolbook+=con;

cout<<“继续添加输入0,取消添加输入-1”<

cin>>h;

}

else

cout<

void BookManage::delbook(string s,int num,int flag){ BookNode *p=headbook;if(headbook!=NULL){

switch(flag)

{

case 0:

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);//从数据库中删除

//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_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);//从数据库中删除

//delete p->next;

break;

}

}

}

if(p->next==NULL)

cout<

break;case 1:

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);//从数据库中删除

//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_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);//从数据库中删除

//delete p->next;

break;

}

}

}

if(p->next==NULL)

cout<

}

break;

default:

cout<

} } }

void BookManage::findbook(string s,int flag){ BookNode *p;int h=0;switch(flag){

case 0:

for(p=headbook;p!=NULL;p=p->next)//先查看是否有此书

{

if(p->book.book_name==s)break;} if(NULL==p)cout<next)//查看名为s的图书共有几本 { if(p->book.book_name==s)h++;} if(h>0)cout<next)//查看图书,把所有名为s的图书的信息都{

if(p->book.book_name==s){ p->book.show_book();//显示出图书的基本信息

if(p->book.book_con==0)

打印出来

}

cout<

cout<

} } break;case 1: 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<

} } if(NULL==p)cout<

/****************************************(*******************************************/

class Admin//管理员 { public: string adm_name;//帐号

string adm_passw;//密码

public: Admin(){

adm_name=“adm”;

adm_passw=“123”;} };

class LendBook { public: string bookname[3];int count;//借多少本数

time_t lend_time;time_t back_time;LendBook(){count=0;} };

class Stu { public: string stu_name;

};

2)用户管理

string stu_phone;//联系方式

string stu_num;//学号(登录帐号)string password;//密码 float debt;//欠费额

LendBook lendbook;//用户借书信息

public: void show_stu();//把此人所有信息(包括借书)显示出来

void Stu::show_stu(){ cout<<“姓名:”<

class StuNode { public: Stu stu;StuNode *next;};StuNode *headstu=NULL;

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

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

class StuManage:public BookManage { private: 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,退出输入-1”<>h;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<<“请输入姓名:”<

cin>>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;} else cout<stu.debt=0;p->next=headstu;headstu=p;savestu(p);//保存至数据库

(StuManage::totolstu)++;//用户总数加一

cout<<“继续添加输入0,取消添加输入-1”<>h;

} else cout<

void StuManage::delstu(string s,int flag){ StuNode *p=headstu;if(headstu!=NULL){

switch(flag)

{

case 0:

if(headstu->stu.stu_name==s)//当要删除的用户位于链表的头结点位置 { headstu=p->next;StuManage::totolstu--;del_sql_stu(p);//从数据库中删除

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

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

//delete p->next;

break;

}

}

if(p->next==NULL)

cout<

break;case 1:

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

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

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

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

//delete p->next;

break;

}

}

if(p->next==NULL)

cout<

}

break;

default:

cout<

} } }

void StuManage::findstu(string s,int flag){ StuNode *p;int h=0,m=1;switch(flag){

case 0:

for(p=headstu;p!=NULL;p=p->next)

{

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

break;

}

if(p==NULL)

cout<

for(p=headstu;p!=NULL;p=p->next)

{

if(p->stu.stu_name==s)h++;} if(h>0)cout<next){ if(p->stu.stu_name==s){

p->stu.show_stu();

if(p->stu.lendbook.count>=3)

{

cout<stu.lendbook.count;if(i>0)

”NONE<

cout<<“所借书的名字为:”<

while(i)

{

cout<<“t(”<stu.lendbook.bookname[i-1]<

}

cout<

}

else

{

int i=p->stu.lendbook.count;

if(i>0)

cout<<“所借书的名字为:”<

while(i)

{

cout<<“t(”<stu.lendbook.bookname[i-1]<

}

} } break;case 1:

}

cout<<“您已借了”<

stu.lendbook.count<<“本书!”<stu.lendbook.count<<“本书!”<

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<

int i=p->stu.lendbook.count;

cout<<“所借书的名字为:”<

//输出用户所借书的名字 cout<<“t(”<stu.lendbook.bookname[i-1]<

}

cout<

}

else

{

int i=p->stu.lendbook.count;

cout<<“所借书的名字为:”<

while(i)

{ //输出用户所借书的名字

cout<<“t(”<stu.lendbook.bookname[i-1]<

}

cout<<“您已借了”<

stu.lendbook.count<<“本书!”<

cout<<“您还可以借”<<3-p->stu.lendbook.count<<“本书!”NONE<

cout<

}

break;

}

}

if(p==NULL)

cout<

break;

default:

cout<

}

void StuManage::mux_stu_book(){ StuNode *p;BookNode *q;int i=0,j=0,h=0;for(p=headstu;p!=NULL;p=p->next)i++;cout<<“当前图书馆注册用户数为:”<next){

h+=q->book.book_mux;

j+=q->book.book_con;}

} cout<<“当前图书馆库存的总书记数为:”<next){

if(q->stu.stu_num==ss)

{del_sql_stu(q);break;}//丛数据库中删除

} if(q==NULL){cout<

switch(flag){

case 0:

for(p=headbook;p!=NULL;p=p->next)

{

if(p->book.book_name==s)

{

“NONE<

del_sql_book(p);//从数据库中删除 int i=q->stu.lendbook.count;if(i>=3||q->stu.debt>0){ if((i>=3)&&(q->stu.debt==0)){cout<

if((i<3)&&(q->stu.debt>0))

{cout<

if((i>=3)&&(q->stu.debt>0))

{cout<

}

else

{

//记录下所借书的名字存入用户信息中

q->stu.lendbook.bookname[i]=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)

cout<

break;

case 1:

for(p=headbook;p!=NULL;p=p->next)

{

if(p->book.book_num==s)

{

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

int i=q->stu.lendbook.count;

if(i>=3||q->stu.debt>0)

{

if((i>=3)&&(q->stu.debt==0))

{cout<

if((i<3)&&(q->stu.debt>0))

{cout<

if((i>=3)&&(q->stu.debt>0))

{cout<

}

else

{

}

q->stu.lendbook.bookname[i]=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)

cout<

break;default:

cout<

void StuManage::backbook(string ss,string s,int flag)//还书 { BookNode *p;StuNode *q;for(q=headstu;q!=NULL;q=q->next){

if(q->stu.stu_num==ss)

{del_sql_stu(q);break;}//丛数据库中删除

} if(q==NULL){cout<

switch(flag){

case 0:

for(p=headbook;p!=NULL;p=p->next)

{

if(p->book.book_name==s)

{

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

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(s>2592000)//2592000为一个月的秒数

{

int t=ceil((s-2592000)/86400);

q->stu.debt=t*0.1;

}

break;} } if(p==NULL)

cout<

break;

case 1:

for(p=headbook;p!=NULL;p=p->next)

{

if(p->book.book_num==s)

{

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

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(s>2592000)//2592000为一个月的秒数

{

int t=ceil((s-2592000)/86400);

q->stu.debt=t*0.1;

}

break;

} } if(p==NULL)cout<

}

void StuManage::paydebt(string s){ StuNode *p;

for(p=headstu;p!=NULL;p=p->next)//查找用户 { if(p->stu.stu_num==s){

p->stu.debt=0;

cout<

stream << result;//将string输入流

stream >> stu_str;//从i中抽取前面插入的string值

return stu_str;}

void savestu(StuNode *p)//保存读者信息到数据库 {

memset((void*)strSQL,0,200);sprintf(strSQL,“insert into reader values(%s,%s,%s,%s,%f,%ld,%ld,%d)”,change_char(p->stu.stu_name),change_char(p->stu.stu_phone),change_char(p->stu.password),change_char(p->stu.stu_num),p->stu.debt,(long)(p->stu.lendbook.lend_time),(long)(p->stu.lendbook.back_time),p->stu.lendbook.count);if(mysql_real_query(&mysql,strSQL,strlen(strSQL))!= 0)

printf(“记录插入失败!n”);}

void savebook(BookNode *p)//保存图书信息到数据库 { memset((void*)strSQL,0,200);sprintf(strSQL,“insert into book values(%s,%s,%s,%s,%d,%d)”,change_char(p->book.book_name),change_char(p->book.book_aut),change_char(p->book.book_pre),change_char(p->book.book_num),p->book.book_mux,p->book.book_con);if(mysql_real_query(&mysql,strSQL,strlen(strSQL))!= 0)

printf(“记录插入失败!n”);

}

void del_sql_stu(StuNode *p)//将读者信息从数据库中删除 {

memset((void*)strSQL,0,200);sprintf(strSQL,“delete from reader where stu_name='%s'”,change_char(p->stu.stu_name));if(mysql_real_query(&mysql,strSQL,strlen(strSQL))!= 0)

printf(“记录删除失败!n”);}

void del_sql_book(BookNode *p)//将图书信息从数据库中删除 { memset((void*)strSQL,0,200);sprintf(strSQL,“delete from book book_name='%s'”,change_char(p->book.book_name));if(mysql_real_query(&mysql,strSQL,strlen(strSQL))!= 0)

printf(“记录删除失败!n”);

} /* void savestu()//保存读者信息文件 { ofstream outfile(“./stu.txt”,ios::out);

if(!outfile){

cerr<<“open error!”<

return;} StuNode *p;

for(p=headstu;p!=NULL;p=p->next)//数据写入文件

{

outfile<

stu.stu_name<<“ ”<

stu.stu_phone;

outfile<<“ ”<

stu.password<<“ ”<

stu.stu_num;

where

outfile<<“ ”<

stu.debt;

outfile<<“ ”<

stu.lendbook.lend_time;

outfile<<“ ”<

stu.lendbook.back_time;

outfile<<“ ”<

stu.lendbook.count;

outfile<<“ ”<

} outfile.close();}

void savebook()//保存图书信息文件 { ofstream outfile(“./book.txt”,ios::out);

if(!outfile){

cerr<<“open error!”<

return;} BookNode *p;

for(p=headbook;p!=NULL;p=p->next)//数据写入文件

{

outfile<

book.book_name<<“ ”<

book.book_num;

outfile<<“ ”<

book.book_pre<<“ ”<

book.book_aut;

outfile<<“ ”<

book.book_mux;

outfile<<“ ”<

book.book_con;

outfile<<“ ”<

void loadstu()//从学生数据数据库reader中读取 { int i = 0;memset((void*)strSQL,0,100);

strcpy(strSQL,“select * from reader”);

mysql_query(&mysql,strSQL);

//查询

results = mysql_store_result(&mysql);

//获取记录

num_fields = mysql_num_fields(results);

//获取字段数

fileds = mysql_fetch_fields(results);

//获取字段数组

while((rows = mysql_fetch_row(results))!= NULL)

//循环显示

{

while(i < num_fields)

{

StuNode *p=new StuNode;

p->stu.stu_name =(rows[i]?rows[i++]:“NULL”);

p->stu.stu_phone =(rows[i]?rows[i++]:“NULL”);

p->stu.password =(rows[i]?rows[i++]:“NULL”);

p->stu.stu_num =(rows[i]?rows[i++]:“NULL”);

p->stu.debt = atof(rows[i]?rows[i++]:“NULL”);

p->stu.lendbook.lend_time =(time_t)(rows[i]?rows[i++]:“NULL”);

p->stu.lendbook.back_time =(time_t)(rows[i]?rows[i++]:“NULL”);

p->stu.lendbook.count = atoi(rows[i]?rows[i++]:“NULL”);

p->next=headstu;//建立用户链表

headstu=p;

}

i = 0;} }

void loadbook()//从书数据库中读取 { int i = 0;memset((void*)strSQL,0,100);

strcpy(strSQL,“select * from book”);

mysql_query(&mysql,strSQL);

//查询

results = mysql_store_result(&mysql);

//获取记录

num_fields = mysql_num_fields(results);

//获取字段数

fileds = mysql_fetch_fields(results);

//获取字段数组

while((rows = mysql_fetch_row(results))!= NULL)

//循环显示

{

while(i < num_fields)

{

BookNode *p=new BookNode;

p->book.book_name =(rows[i]?rows[i++]:“NULL”);

p->book.book_aut =(rows[i]?rows[i++]:“NULL”);

p->book.book_pre =(rows[i]?rows[i++]:“NULL”);

p->book.book_num =(rows[i]?rows[i++]:“NULL”);

p->book.book_mux = atoi(rows[i]?rows[i++]:“NULL”);

p->book.book_con = atoi(rows[i]?rows[i++]:“NULL”);

p->next=headbook;//建立用户链表

headbook=p;

}

i = 0;} }

/* void loadstu()//从学生数据文件读取 { ifstream infile(“./stu.txt”,ios::in);

if(!infile){

cout<

return;} if(infile.eof()){

cout<

infile.close();} else {

while(infile.peek()!=EOF)//数据从文件读出

{

StuNode *p=new StuNode;

infile>>p->stu.stu_name>>p->stu.stu_phone;

infile>>p->stu.password>>p->stu.stu_num;

infile>>p->stu.debt>>p->stu.lendbook.lend_time;

infile>>p->stu.lendbook.back_time>>p->stu.lendbook.count;

if(p->stu.stu_name!=“")

{

p->next=headstu;//建立用户链表

headstu=p;

}

else

delete p;

}

infile.close();} }

void loadbook()//从书数据文件读取 {

ifstream infile(”./book.txt“,ios::in);

if(!infile){

} cout<

while(infile.peek()!=EOF)//数据从文件读出

{

BookNode *p=new BookNode;infile>>p->book.book_name>>p->book.book_num;infile>>p->book.book_pre>>p->book.book_aut;infile>>p->book.book_mux>>p->book.book_con;

if(p->book.book_name!=”“){ p->next=headbook;//建立图书链表

headbook=p;} else delete p;

} } */ } infile.close();/****************************************(*******************************************/

void MenuAdmin(){

4)界面部分 cout<>>>>>>>>>>>>>>>>>>>>>>>>>>>欢迎来到图书管理系统<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<“NONE<

$“NONE<

$“NONE<

$“NONE<

删除书目

$“NONE<

$“NONE<

cout<

借书

$“NONE<

$“NONE<

cout<

还书

$“NONE<

$“NONE<

查询图书

$“NONE<

$“NONE<

$“NONE<

$“NONE<

$“NONE<

$“NONE<

查询用户

$“NONE<

$“NONE<

用户交费

$“NONE<

$“NONE<

$“NONE<

$“NONE<

0 退出

$“NONE<

$“NONE<>>>>>>>>>>>>>>>>>>>>>>>>>[请字)]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<“NONE<

void MenuStu(){

(输

数 cout<>>>>>>>>>>>>>>>>>>>>>>>>>>>欢迎来到图书管理系统<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<“NONE<

cout<

$“NONE<

cout<

借书

$“NONE<

$“NONE<

cout<

还书

$“NONE<

$“NONE<

查询图书

$“NONE<

$“NONE<

个人信息

$“NONE<

$“NONE<

0 退出

$“NONE<

$“NONE<>>>>>>>>>>>>>>>>>>>>>>>>>[请选择(输入相应数字)]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<“NONE<

int getch()//密码不回显函数1 { int c=0;

struct termios org_opts, new_opts;

int res=0;

//-----store old settings-----------

res=tcgetattr(STDIN_FILENO, &org_opts);

assert(res==0);

//----set new terminal parms--------

memcpy(&new_opts, &org_opts, sizeof(new_opts));

new_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL);

tcsetattr(STDIN_FILENO, TCSANOW, &new_opts);

c=getchar();

//------restore old settings---------

res=tcsetattr(STDIN_FILENO, TCSANOW, &org_opts);

assert(res==0);

return c;}

string set_passwd()//密码不回显函数2 { string result;char pd[128];int i;getch();/* 当帐号和密码一起输入,且刚输完帐号后就要输入密码时,set_passwd会把帐号结束时的回车赋‘n’拿过来作为自己的第一个输入,这样容易造成密码输入的错 误,为避免

这种情况的发生,所以就可以在for循环之前假如了getch()把‘n’吸收掉 */

for(i=0;;i++)

{

pd[i]=getch();

if(pd[i]=='n')

{

pd[i]='';

break;

}

if(pd[i]==127)

{

printf(”b b“);

i=i-2;

}

else

printf(”*“);

if(i<0)

pd[0]='';

} stringstream stream;stream << pd;//将char输入流

stream >> result;//从stream中抽取前面插入的char值

return result;}

/****************************************(5)主函数部分*******************************************/

int main(){ mysql_init(&mysql);//数据库初始化

if(!mysql_real_connect(&mysql,strHost,strUser,strPasswd,strDb,0,NULL,0))//连接数据库

{

printf(”连接数据库失败!/n“);

return 0;

} loadstu();loadbook();

mysql_free_result(results);//释放数据库结果集

BookManage bookmanage;StuManage stumanage;

Admin admin;int i;string s;int num,flag;string s1,s2,ss;StuNode *p;system(”clear“);//清理屏幕

cout<

~Welecome to come in~“NONE<>i;

switch(i){

case 0:

break;

case 1:

while(1)

{

cout<<”请输入管理员登录名:“<

cin>>s1;

if(s1==”0“)

return 0;

cout<<”请输入密码:“<

s2=set_passwd();

cout<

if(admin.adm_name==s1)

{

while(1)

{

if(admin.adm_passw==s2)

break;

else

{

cout<

s2=set_passwd();cout<

if(s2==”0“)return 0;

//cin>>s2

}

}

}

if(s1!=admin.adm_name)

cout<

else

break;

}

while(1){ MenuAdmin();int t;cin>>t;switch(t){

”<

“<

case 0: //savestu();savebook();

mysql_close(&mysql);//关闭数据库链接

return 0;break;

case 1:bookmanage.addbook();//增加书本

system(”clear“);break;//清理屏幕

case 2:

cout<<”按书名删除请输入 0 “<

cin>>flag;

if(flag==0)

{cout<<“请输入书名:”;cin>>s;}

else if(flag==1)

{cout<<“请输入书编号:”;cin>>s;}

else

cout<

cout<<“请输入要删除书的数目:”<

cin>>num;

bookmanage.delbook(s,num,flag);//删除书本

system(“clear”);//清理屏幕

break;

case 3:

cout<<“按书名借书请输入 0 ”<

cin>>flag;

if(flag==0)

{cout<<”请输入书名:“;cin>>s;}

else if(flag==1)

{cout<<”请输入书编号:“;cin>>s;}

else

cout<

cout<<”请输入借书人的编号:“<

cin>>ss;

stumanage.lendbook(ss,s,flag);

system(”clear“);//清理屏幕

break;

case 4: cout<<”按书名还书请输入 0 “<

cin>>flag;if(flag==0)

{cout<<”请输入书名:“;cin>>s;} else if(flag==1){cout<<”请输入书编号:“;cin>>s;} else

”<

“<

”<

cout<>ss;stumanage.backbook(ss,s,flag);system(“clear”);//清理屏幕

break;case 5: cout<<“按书名查找请输入 0 ”<>flag;if(flag==0){cout<<”请输入书名:“;cin>>s;} else if(flag==1){cout<<”请输入编号:“;cin>>s;}

else cout<

system(”clear“);//清理屏幕

break;case 7: cout<<”按姓名删除请输入 0 “<>flag;

if(flag==0){cout<<“请输入姓名:”;cin>>s;} else if(flag==1){cout<<“请输入学号:”;cin>>s;} else cout<

system(“clear”);//清理屏幕

break;case 8: cout<<“按姓名查找请输入 0 ”<

cin>>flag;

if(flag==0)

{cout<<”请输入姓名:“;cin>>s;} else if(flag==1)

{cout<<”请输入学号:“;cin>>s;} else cout<

break;case 9:

cout<<”请输入要缴费人的学号!“<>s;

stumanage.paydebt(s);system(”clear“);//清理屏幕

break;case 10: stumanage.mux_stu_book();system(”clear“);//清理屏幕

break;default:

cout<

}

}

break;case 2: while(1){

cout<<”请输入用户登录名[用户编号]:“<

cin>>s1;

if(s1==”0“){return 0;}

cout<<”请输入密码:“<next){ if(p->stu.stu_name==s1){

while(1)

{

if(p->stu.password==s2)

break;

else

0”NONE<

{

if(s2==“0”)return 0;

cout<

”<

“<

s2=set_passwd();

cout<

//cin>>s2

}

}

break;

} } if(p==NULL)cout<

break;}

while(1){ MenuStu();int t;cin>>t;switch(t){

case 0: //savestu();savebook();

mysql_close(&mysql);//关闭数据库链接

return 0;break;

case 1:

cout<<”按书名借书请输入 0 “<

cin>>flag;

if(flag==0)

{cout<<“请输入书名:”;cin>>s;}

else if(flag==1)

{cout<<“请输入书编号:”;cin>>s;}

else

cout<

stumanage.lendbook(s1,s,flag);

system(“clear”);//清理屏幕

break;

case 2: cout<<“按书名还书请输入 0 ”<

cin>>flag;if(flag==0)

{cout<<”请输入书名:“;cin>>s;} else if(flag==1)

{cout<<”请输入书编号:“;cin>>s;} else

cout<

”<

}

system(“clear”);//清理屏幕

break;case 3: cout<<“按书名查找请输入 0 ”<

cin>>flag;if(flag==0)

{cout<<”请输入书名:“;cin>>s;} else if(flag==1)

} {cout<<”请输入编号:“;cin>>s;} else cout<

break;

case 4: stumanage.findstu(s1,1);system(”clear“);//清理屏幕

break;

default: cout<

} break;default: cout<<”输入数字无效!"<

第二篇:连接数据库实现图书管理系统

项目构思

使用JDBC技术连接MySQL数据库,实现对图书管理系统中图书信息的浏览,增加,修改,删除功能。项目设计

1,安装并配置数据库,创建数据库,创建表及添加数据 2程序设计 文件名:index.jsp <%@ page language=“java” import=“java.sql.*” pageEncoding=“gb2312”%> <%@page errorPage=“error.jsp”%>

图书管理系统

添加图书信息

<%

Class.forName(“com.mysql.jdbc.Driver”);

Connection con DriverManager.getConnection(“jdbc:mysql://localhost:3307/school”,“root”,“ylx”);

Statement stmt = con.createStatement();

String s = “Select * FROM book”;

ResultSet rs = stmt.executeQuery(s);

while(rs.next())

{

int id=rs.getInt(1);

out.println(“

”);

}

rs.close();

stmt.close();

con.close();

%>

书名作者价格管理
”+rs.getString(2)+“”+rs.getString(3)+“”+rs.getString(4)+“修改 删除

第三篇:用C++编写的图书管理系统

C++实现图书管理系统 一:功能:

1.需要有个系统管理员和普通读者;

2.对图书库存图书的创建,添加,删除,修改,查询;

3.对读者借阅信息的创建,添加,删除,修改,查询; 4:普通读者只有查询上述两个文件的权利;

5:管理员可对普通读者的创建,添加,修改,删除; 6:管理员拥有上述全部权利;

7:要与文件流进行关联,如:创建,添加,读取,删除,查询;

第四篇:数据库图书管理系统题目

请设计图书管理系统数据库,要求能满足读者的注册、注销、个人信息修改、图书的入库、图书报废、图书的借阅、归还、续约、滞纳金赔偿、损坏赔偿功能

系统中至少包含如下信息:

读者姓名、id、性别、学历(初等、中等、高等)、年龄、职业类别、图书id、图书名称、图书类别(基础类、科技类、文史类、社会科学、自然科学)、图书书龄、所属出版社、图书价格、图书是否完好、图书借阅人、借阅起始时间、图书借阅时长、图书续约(最多可连续续约3次)、图书是否已归还、图书是否已损坏,读者注册级别(分普通读者和vip读者,普通读者同时可以借阅2本书,vip读者可以同时借阅5本书)。

图书系统中,相同的书籍可以不止一本,读者可以同名。一次借阅期限一个月(30天),一次续约延长一个月。过期后每超出一天须缴纳滞纳金一元。图书损毁后就被报废。

1、请用完整、连续的SQL语句设计数据库和表,请根据情理和场景设计各类约束。

2、请查询‘计算机导论’这本书籍的被借阅次数。

3、请查询借书证号为11的读者历年来的借阅次数(不包括续约)。

4、请用一条或者多条语句查询‘计算机导论’这本书籍当前是否可以借阅。

5、请找出最热门的书籍名称(总共借阅次数)。

6、请找出学历中等或中等以上人员关注度比中等以下人员关注度高的书籍。

7、请查询‘王小东’当前可以借阅多少本书。

8、请查询‘王小东’当前共须缴纳多少滞纳金。

9、请统计各职业类别人员的借阅次数。

10、请查阅哪个出版社的书籍借阅频率最高(可以考虑按进行统计)。

11、检索学历比‘王小东’高,年龄比‘王小东’大,而借阅次数比他少的读者id。

12、请查询至少关注过图书类别中3个类别的读者id。

13、请查询‘计算机导论’书籍在各个学历阶层的借阅次数。

14、请将“根据借书证查询所借阅书籍编号和名称”这样的行为以存储过程加以实现。

第五篇:图书管理系统数据库设计

数据库设计.................................................................2 3.1 专门术语的定义...................................................2 3.1.1 系统中常用的术语(或使用频率较高的术语).........................2 3.1.2 表格定义及规范.................................................2 3.1.2.1数据约定.....................................................2 3.1.2.2表和表字段命名规范:.........................................3 3.2 数据设计.........................................................3 3.2.1 数据流程图设计.................................................3 3.2.2实体关系结构设计...............................................4 3.3安全保密设计.....................................................6 3.3.1 逻辑上的安全保密...............................................6 3.3.2 物理上的安全保密...............................................6 3.4 表格与功能模块相关性分析.........................................7 3.5 表格定义.........................................................7 数据库设计

3.1 专门术语的定义

暂无

3.1.1 系统中常用的术语(或使用频率较高的术语)暂无

3.1.2 表格定义及规范 3.1.2.1数据约定

所有数据项都用英文、汉语拼音或缩写表示,数据库名称除外。

所有字段在设计时,除以下数据类型timestamp、image、datetime、smalldatetime、uniqueidentifier、binary、sql_variant、binary、varbinary外,必须有默认值。字符型的默认值为一个空字符值串;数值型的默认值为数值0;逻辑型的默认值为数值0;

其中:系统中所有逻辑型中数值0表示为“假”;数值1表示为“真”。datetime、smalldatetime类型的字段没有默认值,必须为NULL。当字段定义为字符串形时建议使用varchar而不用nvarchar。建议在大多数表中(如报销单,申请单),应都有以下字段: 字段名说明类型默认值 CreatorID创建者int CreatedTime创建时间DatetimeNULL 字符集采用 UTF-8,请注意字符的转换。

所有数据表第一个字段都是系统内部使用自动序列主键列,自增字段,不可空,名称为:id,确保不把此字段暴露给最终用户。

除特别说明外,所有字符串字段都采用varchar(50)类型,(无论汉字还是英文,都算一个字符)。

除特别说明外,所有小数的字段都采用 decimal(18,2)的形式表达。

除特别说明外,所有日期格式都采用 datetime 格式(根据需要提取时间格式); 除特别说明外,所有整形都采用 bigint 格式。除特别说明外,所有字段默认都设置为 null。3.1.2.2表和表字段命名规范:

命名规则约束的范围包括:数据库的命名、表的命名及字段的命名。数据库相关的命名规则采用与通常的编程的变量命名规则原则一致,具体要求如下: 1)字段名及表名为典型的名词结构; 2)中文名称要求语言精练、文法严谨;

3)望文知意、易懂易用,禁止采用如:A002这种命名;

4)主体采用拼音字母的首写字母拼写构成,基于惯常法可适度采用无词义歧义性的英文命名;

5)长度不少于3个字母,不大于12个字母;

6)在对于拼音首字母类似的字段和表,为区别,添加下划线和数字如男性人数:NXRS,女性人数:NXRS_2。

3.2 数据设计

绘制数据流程图的目的是为了方便开发人员与用户的交流,以及为系统的设计提供依据。数据流程图的绘制过程通常采用自顶向下,逐层分解,直到功能细化为止,形成若干层次的数据流程图。3.2.1 数据流程图设计

0层数据流图

1层数据流图

3.2.2实体关系结构设计

图书实体关系

读者实体关系

图书借阅关系实体

用户实体关系

图书类别实体关系

3.3安全保密设计

3.3.1 逻辑上的安全保密

1、系统对非法使用者的安全保密处理措施

2、系统对正常使用者的安全保密处理措施

3、系统对管理员的安全保密 3.3.2 物理上的安全保密

1、数据库系统异常时的还原处理措施

2、设备遭异常毁坏时的安全防护措施

3、数据参数做到及时更新,保证系统正常运行

3.4 表格与功能模块相关性分析

3.5 表格定义

a.图书信息表

b.读者信息表

c.借阅表

d.管理员_书籍

e.管理员_学生

下载用mysql数据库实现的C++图书管理系统word格式文档
下载用mysql数据库实现的C++图书管理系统.doc
将本文档下载到自己电脑,方便修改和收藏,请勿使用迅雷等下载。
点此处下载文档

文档为doc格式


声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:645879355@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。

相关范文推荐

    图书管理系统数据库源代码

    图书管理系统数据库源代码 //创建工程及设计主界面 public class Main extends JFrame { private static final JDesktopPane { DESKTOP_PANE=new JDesktopPane; //桌面......

    C++课程设计(简单图书管理系统)

    课 程 设 计 课程名称C++课程设计 题目名称图书管理系统 2016 年6 月 29 日目录 一.设计内容与要求 .......................................................................

    图书管理系统数据库设计说明书

    图书管理系统数据库设计说明书 设计题目:图书管理系统  学院:计算机学院  班级:08网络工程1班  组员:李忠义200813024016 张巡200813024036 张学理200813024017  指导老师:罗代......

    数据库课程设计 图书管理系统(精选)

    课 程 设 计 软件工程与数据库 课程设计 任务书 学院名称:数学与计算机学院 课程代码:_6014419_ 专业: 年级:一、设计题目 图书管理系统 二、主要内容 一个简单的图书管理系统......

    图书借阅管理系统数据库要求

    图书借阅管理系统设计文档 学号:00,姓名:***,班级:*** 一 系统概述 为学校图书借阅室设计图书管理系统,完成新增图书上架、读者办理图书借阅证、图书查询、借书、还书工作的自动处......

    Oracle数据库 图书管理系统实验报告

    图书管理系统(Oracle) 1、创建表空间student_library 2、(1)创建表Administrator (2)创建表library (3)创建表student (4)创建表lent_library (5)创建表booktype 3、 创建表空间stude......

    图书管理系统数据库设计示例

    图书管理系统数据库设计 一个简单的图书管理系统包括图书馆内书籍的信息、学校在校学生的信息以及学生的借阅信息。此系统功能分为面向学生和面向管理员两部分,其中学生可以......

    图书管理系统的数据库设计

    图书管理系统的数据库设计 摘要:虚拟为某公司建立的图书馆管理系统进行数据库设计,目的在于使该系统的运行能提高该公司的资料管理水平和现代化管理水平。本系统是一个中小型......