当前位置:文档之家› 用mysql数据库实现的C++图书管理系统

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

.#include<fstream>#include<iostream>#include<stdlib.h>#include<ctime>#include<cmath>#include<termios.h>#include <sstream>#include<string.h>#include<assert.h>#include<mysql/mysql.h>//改变字体颜色#define NONE "\033[m"#define RED "\033[0;32;31m"#define GREEN "\033[0;32;32m"#define BLUE "\033[0;32;34m"#define YELLOW "\033[1;33m"#define LIGHT_RED "\033[1;31m"#define LIGHT_GREEN "\033[1;32m"#define LIGHT_BLUE "\033[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<<"书名:"<<book_name<<endl;cout<<"出版社:"<<book_pre<<endl;cout<<"此书的作者:"<<book_aut<<endl;cout<<"ISBN编号:"<<book_num<<endl;cout<<"此书共有"<<book_mux<<"本"<<endl;cout<<"还有"<<book_con<<"本书未借出!"<<endl;}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"<<endl; cin>>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<<"请输入书名:"<<endl;cin>>na;p->book.book_name=na;cout<<"请输入ISBN编号:"<<endl;cin>>nu;p->book.book_num=nu;cout<<"请输入出版社:"<<endl;cin>>p1;p->book.book_pre=p1;cout<<"请输入此书的作者:"<<endl;cin>>aut;p->book.book_aut=aut;cout<<"请输入此书共有几本:"<<endl;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"<<endl;cin>>h;}elsecout<<YELLOW"输入字符无效!"NONE<<endl;}elsecout<<YELLOW"输入字符无效!"NONE<<endl;}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<<YELLOW"此书不存在!"NONE<<endl;}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<<YELLOW"此书不存在!"NONE<<endl;}break;default:cout<<YELLOW"输入数字无效!"NONE<<endl;break;}}}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<<YELLOW"此书不存在!"NONE<<endl;for(p=headbook;p!=NULL;p=p->next)//查看名为s的图书共有几本{if(p->book.book_name==s)h++;}if(h>0)cout<<GREEN"这种名字的书共有"<<h<<"本"NONE<<endl;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<<YELLOW"该书已全被借出!"NONE<<endl;cout<<endl;}}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<<YELLOW"该书已全被借出!"NONE<<endl;break;}}if(NULL==p)cout<<YELLOW"此书不存在!"NONE<<endl;break;default:cout<<YELLOW"输入数字无效!"NONE<<endl;break;}}/****************************************(2)用户管理*******************************************/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;string stu_phone;//联系方式string stu_num;//学号(登录帐号)string password;//密码float debt;//欠费额LendBook lendbook;//用户借书信息public:void show_stu();//把此人所有信息(包括借书)显示出来};void Stu::show_stu(){cout<<"姓名:"<<stu_name<<endl;cout<<"联系电话:"<<stu_phone<<endl;cout<<"ID:"<<stu_num<<endl;cout<<"欠费额:"<<debt<<endl;cout<<"已借书"<<lendbook.count<<"本"<<endl;}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"<<endl;cin>>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<<"请输入姓名:"<<endl;cin>>na;p->stu.stu_name=na;cout<<"请输入联系电话:"<<endl;cin>>p1;p->stu.stu_phone=p1;cout<<"请输入ID:"<<endl;cin>>num;p->stu.stu_num=num;p->stu.lendbook.lend_time=0;p->stu.lendbook.back_time=0;while(1){cout<<"请输入六位密码:"<<endl;cin>>pa1;cout<<"请确认六位密码:"<<endl;cin>>pa2;if(pa1==pa2){pa=pa2;p->stu.password=pa;break;}elsecout<<YELLOW"两次密码不一样,请重行输入!"NONE<<endl;}p->stu.debt=0;p->next=headstu;headstu=p;savestu(p);//保存至数据库(StuManage::totolstu)++;//用户总数加一cout<<"继续添加输入0,取消添加输入-1"<<endl;cin>>h;}elsecout<<YELLOW"输入字符无效!"NONE<<endl;}elsecout<<YELLOW"输入字符无效!"NONE<<endl;}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<<YELLOW"此用户不存在!"NONE<<endl;}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<<YELLOW"此用户不存在!"NONE<<endl;}break;default:cout<<YELLOW"输入数字无效!"NONE<<endl;break;}}}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<<YELLOW"此用户不存在!"NONE<<endl;for(p=headstu;p!=NULL;p=p->next){if(p->stu.stu_name==s)h++;}if(h>0)cout<<GREEN"这种名字的用户共有"<<h<<"个"NONE<<endl;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<<YELLOW"sorry,您已借满3本书,不能再借了!!!"NONE<<endl;int i=p->stu.lendbook.count;if(i>0)cout<<"所借书的名字为:"<<endl;//输出用户所借书的名字while(i){cout<<"\t("<<m++<<"):"<<p->stu.lendbook.bookname[i-1]<<endl;i--;}cout<<endl;}else{int i=p->stu.lendbook.count;if(i>0)cout<<"所借书的名字为:"<<endl;//输出用户所借书的名字while(i){cout<<"\t("<<m++<<"):"<<p->stu.lendbook.bookname[i-1]<<endl;i--;}cout<<"您已借了"<<p->stu.lendbook.count<<"本书!"<<endl;cout<<"您还可以借"<<3-p->stu.lendbook.count<<"本书!"<<endl;cout<<endl;}}}break;case 1: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<<YELLOW"sorry,您已借满3本书,不能再借了!!!"NONE<<endl;int i=p->stu.lendbook.count;cout<<"所借书的名字为:"<<endl;//输出用户所借书的名字while(i){ //输出用户所借书的名字cout<<"\t("<<m++<<"):"<<p->stu.lendbook.bookname[i-1]<<endl;i--;}cout<<endl;}else{int i=p->stu.lendbook.count;cout<<"所借书的名字为:"<<endl;//输出用户所借书的名字while(i){ //输出用户所借书的名字cout<<"\t("<<m++<<"):"<<p->stu.lendbook.bookname[i-1]<<endl;i--;}cout<<"您已借了"<<p->stu.lendbook.count<<"本书!"<<endl;cout<<"您还可以借"<<3-p->stu.lendbook.count<<"本书!"NONE<<endl;cout<<endl;}break;}}if(p==NULL)cout<<YELLOW"此用户不存在!"NONE<<endl;break;default:cout<<YELLOW"输入数字无效!"NONE<<endl;break;}}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<<"当前图书馆注册用户数为:"<<i<<endl;for(q=headbook;q!=NULL;q=q->next){h+=q->book.book_mux;j+=q->book.book_con;}cout<<"当前图书馆库存的总书数为:"<<j<<endl;cout<<"已借出图书总数为:"<<h-j<<endl;}void StuManage::lendbook(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<<YELLOW"此用户不存在!"NONE<<endl;return;}switch(flag){case 0:for(p=headbook;p!=NULL;p=p->next){if(p->book.book_name==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<<YELLOW"对不起,您借书已超过3本,不能再借!"NONE<<endl;}if((i<3)&&(q->stu.debt>0)){cout<<YELLOW"对不起,您因为所借图书超期已欠费,请速交清欠费再借!"NONE<<endl;}if((i>=3)&&(q->stu.debt>0)){cout<<YELLOW"对不起,您借书已超过3本且有欠费,不能再借!"NONE<<endl;}}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<<YELLOW"此书不存在!"NONE<<endl;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<<YELLOW"对不起,您借书已超过3本,不能再借!"NONE<<endl;}if((i<3)&&(q->stu.debt>0)){cout<<YELLOW"对不起,您因为所借图书超期已欠费,请速交清欠费再借!"NONE<<endl;}if((i>=3)&&(q->stu.debt>0)){cout<<YELLOW"对不起,您借书已超过3本且有欠费,不能再借!"NONE<<endl;}}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<<YELLOW"此书不存在!"NONE<<endl;break;default:cout<<YELLOW"输入数字无效!"NONE<<endl;break;}savestu(q);savebook(p);}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<<YELLOW"此用户不存在!"NONE<<endl;return;}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_ts=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<<YELLOW"此书不存在!"NONE<<endl;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_ts=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<<YELLOW"此书不存在!"NONE<<endl;break;default:cout<<YELLOW"输入数字无效!"NONE<<endl;break;}savestu(q);savebook(p);}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<<RED"缴费成功!"NONE<<endl;break;}}if(p==NULL)cout<<YELLOW"该用户不存在!"NONE<<endl;}/****************************************(3)数据保存与下载*******************************************/char stu_str[50];char *change_char(string result){stringstream stream;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_nu m),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 where 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!"<<endl;return;}StuNode *p;for(p=headstu;p!=NULL;p=p->next)//数据写入文件{outfile<<p->stu.stu_name<<" "<<p->stu.stu_phone;outfile<<" "<<p->stu.password<<" "<<p->stu.stu_num;outfile<<" "<<p->stu.debt;outfile<<" "<<p->stu.lendbook.lend_time;outfile<<" "<<p->stu.lendbook.back_time;outfile<<" "<<p->stu.lendbook.count;outfile<<" "<<endl;}outfile.close();}void savebook()//保存图书信息文件{ofstream outfile("./book.txt",ios::out);if(!outfile){cerr<<"open error!"<<endl;return;}BookNode *p;for(p=headbook;p!=NULL;p=p->next)//数据写入文件{outfile<<p->book.book_name<<" "<<p->book.book_num;outfile<<" "<<p->book.book_pre<<" "<<p->book.book_aut;outfile<<" "<<p->book.book_mux;outfile<<" "<<p->book.book_con;outfile<<" "<<endl;}outfile.close();}*/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<<YELLOW"数据文件不存在,请先建立该文件"NONE<<endl;return;}if(infile.eof()){cout<<YELLOW"数据库为空,请添加数据"NONE<<endl;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;}elsedelete p;}infile.close();}}void loadbook()//从书数据文件读取{ifstream infile("./book.txt",ios::in);if(!infile){cout<<YELLOW"数据文件不存在,请先建立该文件"NONE<<endl;return;}if(infile.eof()){cout<<YELLOW"数据库为空,请添加数据"NONE<<endl;infile.close();}else{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;}elsedelete p;}infile.close();}}*//****************************************(4)界面部分*******************************************/void MenuAdmin(){cout<<GREEN">>>>>>>>>>>>>>>>>>>>>>>>>>>>欢迎来到图书管理系统<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 1 增加新书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 2 删除书目$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 3 借书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 4 还书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 5 查询图书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 6 增加读者$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 7 删除读者$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 8 查询用户$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 9 用户交费$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 10 查询用户总数与图书总数$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 0 退出$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN">>>>>>>>>>>>>>>>>>>>>>>>>>[请选择(输入相应数字)]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"NONE<<endl;}void MenuStu(){cout<<GREEN">>>>>>>>>>>>>>>>>>>>>>>>>>>>欢迎来到图书管理系统<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 1 借书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 2 还书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 3 查询图书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 4 个人信息$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 0 退出$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN">>>>>>>>>>>>>>>>>>>>>>>>>>[请选择(输入相应数字)]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"NONE<<endl;}int getch()//密码不回显函数1{int c=0;struct termios org_opts, new_opts;int res=0;//----- store old settings -----------。

相关主题