📄 zuizhongdezuizhong.doc
字号:
/*
*Copyright (c) 2005 江苏大学电气学院
*All right resewed
*文件名称:图书馆管理系统.cpp
*摘要
*当前版本1.8
*作者:自动化0503-3050502090 张海涛
*完成日期:2008年6月7日
*/
#include <iostream.h>
#include <string.h>
int readerid=0;
int bookid=0;
int borrow();
int back();
int bookinformation(int k);
int readerinformation(int mk);
int readerinformation2(int mk);
int Booknum[6];
char liebiao[6][20];
int i,i1,j1,j2,j3,j4,j5;
class CBook //图书馆存书类
{
private:
char readername[5][20];
char borrowdate[5][20];
int totalnum;
public:
//char readername[5][20];
char bookname[20];
int currentnum;
CBook(char *na="nobook",int num=0)
{
strcpy(bookname,na);
for(int j=0;j<5;j++)
{
strcpy(readername[j],"noname");
strcpy(borrowdate[j],"0000");
};
totalnum=num;
currentnum=num;
}
void displayname()
{
cout<<"书名:"<<bookname;
cout<<" 可借数量:"<<currentnum<<endl;
}
void displayinfo()
{
char *readername1;
char *borrowdate1;
cout<<"书名:"<<bookname;
//cout<<" 可借数量:"<<currentnum<<endl;
for(int j=0;j<totalnum;j++)
{
cout<<"书名:"<<bookname;
readername1=readername[j];
borrowdate1=borrowdate[j];
cout<<readername1<<" 借出日期:"<<borrowdate1<<endl;
};
}
};
class CReader//借阅人类
{
private:
char name[20];
int id;
int books;
public:
char bookname[5][20];
int borrowed;//已借书数量
CReader(char *nam="noname",int book=5):borrowed(5-book),books(book),id(readerid+1)
{
strcpy(name,nam);
for(int j=0;j<5;j++)
strcpy(bookname[j],"nobook");
}
void display()
{
//cout<<"您的姓名为:"<<readername[id]<<endl;
cout<<"您的借书证号为:"<<id<<"号"<<endl;
cout<<"您的借阅情况:"<<endl;
if (borrowed>0)
for(int j=0;j<borrowed;j++)
{
cout<<"已借书籍: "<<bookname[j]<<endl;
};
cout<<"已借:"<<borrowed<<"本书";
cout<<" 还可借:"<<5-borrowed<<"本书"<<endl;
}
};
CBook libbook[5];//本馆最多存5种书(可调)
CReader libperson[5];//本馆最多注册5人(可调)
CReader accout();
CBook newbook();
void hello();
void main()
{ char *option;
char IOBUF[100];
// char IOBUF[1];
int mbuf;
for(int k=1;k<6;k++)
libperson[k].borrowed=0;
option=IOBUF;
hello();
if(IOBUF[1]>0)
cout<<"输入有错"<<endl;
for(;;)
{
cout<<"------------------------系 统 首 页------------------------------------"<<endl<<endl;
cout<<" 0、入库新书 1、开户 2、借书 3、还书 4、库存查询 5、用户查询 6、管理员查询 "<<endl;
cout<<" (请选序号后回车) "<<endl;
cout<<" 图书管理系统正式公测版 "<<endl;
cout<<" 08年6月10日正式发行敬请期待 "<<endl;
cout<<"------------------------------------------------------------------------------"<<endl<<endl<<endl;
cin>>option;
if(IOBUF[1]>0)
cout<<"输入错误,请重新选择序号!"<<endl;
else{
switch (IOBUF[0])
{
case '0':
if (bookid>4)
{
cout<<"书库已满!请通知管理员"<<endl;
break;
}
libbook[bookid]=newbook();
bookid=bookid+1;
break;
case '1':
if (readerid>4)
{
cout<<"用户已满!请通知管理员"<<endl;
break;
}
libperson[readerid]=accout();
readerid=readerid+1;
break;
case '2':
borrow();
break;
case '3':
back();
break;
case '4':
bookinformation(bookid);
break;
case '5':
cout<<"请输入借书证号:"<<endl;
cin>>mbuf;
readerinformation(mbuf);
break;
case '6':
readerinformation2(readerid);
//if(readerid>1) readerinformation(readerid--);
//if(readerid>1) readerinformation(readerid--);
//if(readerid>1) readerinformation(readerid--);
//if(readerid>1) readerinformation(readerid--);
break;
default:
cout<<"输入错误,请重新选择序号!"<<endl;
break;
};}
};
}
CReader accout()//开户
{
char buf[20];
char *xinming=buf;
cout<<"请输入姓名:"<<endl;
cin>>xinming;
CReader someone(xinming);
cout<<"欢迎您 "<<xinming<<" 同学!"<<endl;
someone.display();
i1++;
return someone;
};
CBook newbook()//进新书
{ char aa[20];
char *abookname=aa;
int abooknum;
i++;
cout<<"请输入新书名:";
cin>>abookname;
cout<<"请输入新书数量:";
cin>>abooknum;
strcpy(liebiao[i],abookname);
Booknum[i]=Booknum[i]+abooknum;
Booknum[i]=Booknum[i]<5?Booknum[i]:5;
CBook ABook(abookname,Booknum[i]);
ABook.displayname();
cout<<" --新书入库成功!--"<<endl<<endl;
return ABook;
}
void hello()
{
cout<<" **************************************"<<endl;
cout<<" ** **"<<endl;
cout<<" ** 欢迎进入图书馆管理系统 **"<<endl;
cout<<" ** **"<<endl;
cout<<" **************************************"<<endl;
cout<<" ** 高矮胖瘦倾心打造 **"<<endl<<endl;
cout<<" Copyright@EEI,UJS"<<endl;
cout<<" 测试版:2008-6-7"<<endl<<endl;
}
int borrow()//借书
{
int rid;
char b[20];
char *bookname=b;
cout<<"输入借书证号:"<<endl;
cin>>rid;
if(rid>i1||rid<=0)
cout<<"用户不存在!联系管理员"<<endl;
else
{
readerinformation(rid);
bookinformation(bookid);
if(bookid)
{ cout<<"您要借的书是:"<<endl;
cin>>bookname;
for(int j=1;j<6;j++)
{
if(strcmp(liebiao[j],bookname)==0)
{
switch(rid)
{
case 1:
strcpy(libperson[rid].bookname[libperson[rid].borrowed],bookname);
j1++;
break;
case 2:
strcpy(libperson[rid].bookname[libperson[rid].borrowed],bookname);
j2++;
break;
case 3:
strcpy(libperson[rid].bookname[libperson[rid].borrowed],bookname);
j3++;
break;
case 4:
strcpy(libperson[rid].bookname[libperson[rid].borrowed],bookname);
j4++;
break;
case 5:
strcpy(libperson[rid].bookname[libperson[rid].borrowed],bookname);
j5++;
break;
default:
cout<<"输入错误,请重新选择序号!"<<endl;
break;
};
libbook[bookid]=bookname;
Booknum[j]=Booknum[j]-1;
libperson[rid].borrowed=libperson[rid].borrowed+1;
if((5-libperson[rid].borrowed)<=0||Booknum[j]<0)
{ Booknum[j]=Booknum[j]+1;
libperson[rid].borrowed=libperson[rid].borrowed-1;
cout<<"书均已借出或你的借书限额已到,借阅不成功!"<<endl;
}
else
{
CBook libmass(libbook[bookid]);
libmass.currentnum=Booknum[j];
libmass.displayname();
cout<<"借阅一本已成功!"<<endl;
}
break;
}
else if(j==5)
cout<<"您要借的书不存在,请重新选择"<<endl;
}
} //第一组编程部分
}return 0;
};
int back()//还书
{int b;
int p;
int q=0;
int k;
char bookname[20];
cout<<"请输入借书证号:"<<endl;
cin>>b;
if(b>i1||b<0)
cout<<"用户不存在!有问题联系管理员"<<endl;
else
{ readerinformation(b);
if(bookid)
{ cout<<"您要还的书是:"<<endl;
cin>>bookname;
for(int j=0;j<6;j++)
{
if(strcmp(bookname,liebiao[j])==0)
{
switch(b)
{
case 1:
j1--;
for( k=0;k<5;k++)
{
if(strcmp(libperson[1].bookname[k],bookname)==0)
{
q++;
for(p=k;p<5;p++)
strcpy(libperson[1].bookname[p],libperson[1].bookname[p+1]);
strcpy(libperson[1].bookname[4],"nobook");
}
}
break;
case 2:
j2--;
for( k=0;k<5;k++)
{
if(strcmp(libperson[2].bookname[k],bookname)==0)
{
q++;
for(p=k;p<5;p++)
strcpy(libperson[2].bookname[p],libperson[2].bookname[p+1]);
strcpy(libperson[2].bookname[4],"nobook");
}
}
break;
case 3:
j3--;
for( k=0;k<5;k++)
{
if(strcmp(libperson[3].bookname[k],bookname)==0)
{
q++;
for(p=k;p<5;p++)
strcpy(libperson[3].bookname[p],libperson[3].bookname[p+1]);
strcpy(libperson[3].bookname[4],"nobook");
}
}
break;
case 4:
j4--;
for( k=0;k<5;k++)
{
if(strcmp(libperson[4].bookname[k],bookname)==0)
{
q++;
for(p=k;p<5;p++)
strcpy(libperson[4].bookname[p],libperson[4].bookname[p+1]);
strcpy(libperson[4].bookname[4],"nobook");
}
}
break;
case 5:
j5--;
for( k=0;k<5;k++)
{
if(strcmp(libperson[5].bookname[k],bookname)==0)
{
q++;
for(p=k;p<5;p++)
strcpy(libperson[5].bookname[p],libperson[5].bookname[p+1]);
strcpy(libperson[5].bookname[4],"nobook");
}
}
break;
default:
cout<<"输入错误,请重新选择!"<<endl;
break;
};
if (q==0)
cout<<"您未借此书,请重新输入!"<<endl;
else{
Booknum[j]=Booknum[j]+1;
libperson[b].borrowed=libperson[b].borrowed-1;
libbook[bookid]=bookname;
CBook libmass(libbook[bookid]);
libmass.currentnum=Booknum[j];
libmass.displayname();
cout<<"还书成功!"<<endl;
}
break;
}
if(j==5)
cout<<"您要借的书不存在,请重新选择"<<endl;
}
}
}
//第二组编程部分
return 0;
};
int bookinformation(int k)//书库信息
{
if(k==0)
cout<<"书库暂时无书!有问题联系管理员"<<endl;
else
{cout<<"本馆可借书有:"<<endl;
for(int j=0;j<i;j++)
{ CBook libmass(libbook[j]);
libmass.currentnum=Booknum[j+1];
libmass.displayname();
//libmass.displayinfo();
}
}
//第三组编程部分
return 1;
};
int readerinformation(int mk)//读者信息
{ //int rid;
int dz;
int dd;
if(readerid>=mk)
{ cout<<"用户信息:"<<endl;
dz=mk-1;
CReader readermass(libperson[dz]);
dd=libperson[mk].borrowed;
readermass.borrowed=dd;
for(int j=0;j<5;j++)
strcpy(readermass.bookname[j],libperson[mk].bookname[j]);
readermass.display();
dz=mk-dz+1;
}
else
cout<<"用户不存在!有问题联系管理员"<<endl;
return 0;//第四组编程部分
}
int readerinformation2(int mk)//总读者信息
{ //for(int i=0;i<mk;i++)
int dz;
int dd;
if(readerid>=mk)
for(int i=1;i<=mk;i++)
{
{ cout<<"用户信息:"<<endl;
dz=i-1;
CReader readermass(libperson[dz]);
dd=libperson[i].borrowed;
readermass.borrowed=dd;
for(int j=0;j<5;j++)
strcpy(readermass.bookname[j],libperson[i].bookname[j]);
readermass.display();
}
dz=mk-dz+1;
}
else
cout<<"用户不存在!有问题联系管理员"<<endl;
return 0;//第五组编程部分
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -