当前位置:网站首页>图书管理系统(山东农业大学课程设计)
图书管理系统(山东农业大学课程设计)
2022-07-02 12:59:00 【20岁扶墙码农】
代码如图:
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cstdlib>
#include <windows.h>
const int INC=20;
using namespace std;
class Date{
public:
int day;
int month;
int year;
Date(int d=1,int m=1,int y=2012){
//判断日期的合法性
if(d>0&&d<32)day=d;else day=1;
if(m>0&&m<13)month=m;else m=1;
if(y>0)year=y;else year=2012;
}
void setDay(int d){day=d;}
void setMonth(int m){month=m;}
void setYear(int y){year=y;}
int getDay(){return day;}
int getMonth(){return month;}
int getYear(){return year;}
void disp(){cout<<year<<"/"<<month<<"/"<<day;}
Date operator+(int dtmp);
bool isLeapYear(int yy);
};
bool Date::isLeapYear(int yy){
if(yy%400==0)
return true;
else if(yy%100!=0&&yy%4==0)
return true;
else return false;
}
Date Date::operator+(int dtmp){
//bool Date::isLeapYear(int yy);
int yy=year,mm=month,dd=day,mtmp,m2;
bool flag;
while(dtmp>=0){
if(isLeapYear(yy)){
dtmp-=366;
flag=true;
}
else {
dtmp-=365;
flag=false;
}
yy++;
}
if(flag)
dtmp+=366;
else dtmp+=365;
yy--;
if(isLeapYear(yy)){
m2=29;
}
else {
m2=28;
}
mtmp=dtmp+dd;
int m_day[]={0,31,m2,31,30,31,30,31,31,30,31,30,31};
for(;mtmp>m_day[mm];){
mtmp-=m_day[mm];
if(mm==12){
mm=0;
yy++;
}
mm++;
}
dd=mtmp;
Date dt(yy,mm,dd);
return dt;
}
class Book{
//书号、书名、作者、出版社、出版日期、出版定价、存馆数量
private:
string num;
string title;
string author;
string publisher;
Date publishdate;
float price;
int howmany;
public:
Book(string num0="24416-5",string title0="数据结构",string author0="王红梅,胡明,王涛",
string pub0="清华大学出版社",int bd=1,int bm=1,int by=2012,float pr=29.0,int ct=10):publishdate((bd,bm,by)){
num=num0;title=title0;author=author0;publisher=pub0;price=pr;howmany=ct;}
void setNum(string num0){num=num0;}
void setTitle(string title0){title=title0;}
void setAuthor(string author0){author=author0;}
void setPublisher(string publisher0){publisher=publisher0;}
void setPublishdate(int bd,int bm,int by){Date d(bd,bm,by);publishdate=d;}
void setHowmany(int ct){howmany=ct;}
void setPrice(float pr){price=pr;}
string getNum(){return num;}
string getTitle(){return title;}
string getAuthor(){return author;}
string getPublisher(){return publisher;}
Date getPublishdate(){return publishdate;}
int getHowmany(){return howmany;}
float getPrice(){return price;}
void dispABook(){
cout <<num<< '\t'<<title<< '\t'<<author<< '\t'<<publisher<< '\t';
getPublishdate().disp();
cout<< '\t'<<price<< '\t'<<howmany << '\n' ;
}
friend class InBook;
friend class ReaderBorrowBook;
};
class Reader{
//学号、姓名、学院、专业班级
private:
string num;
string name;
string college;
string classno;
public:
Reader(string num0="20150000",string name0="NoName",string college0="信息学院",string clsn="网络工程15-1"){
num=num0;name=name0;college=college0; classno=clsn;}
void setNum(string num0){num=num0;}
void setName(string name0){name=name0;}
void setCollege(string college0){college=college0;}
void setClassno(string clsn){classno=clsn;}
string getNum(){return num;}
string getName(){return name;}
string getCollege(){return college;}
string getClassno(){return classno;}
void dispAReader(){
cout <<num<< "\t"<<name<< "\t"<<college<< "\t"<<classno<< "\n";
}
friend class Inreader;
friend class ReaderBorrowBook;
};
class BorrowBook{
//学号、姓名、书号、书名、借阅日期、应还日期、归还日期
private:
string num;
string name;
string college;
string booknum;
string title;
Date borrowdate;
Date toreturndate;
Date returndate;
BorrowBook(string num0="20150000",string name0="NoName",string college0="信息学院",string booknum0="24416-5",
string title0="数据结构",int bd=1,int bm=1,int by=2012,int td=1,int tm=5,int ty=2012,int rd=1,int rm=3,int ry=2012)
:borrowdate(bd,bm,by),toreturndate(td,tm,ty),returndate(rd,rm,ry){
num=num0;name=name0;college=college0; booknum=booknum0;title=title0;
}
void setNum(string num0){num=num0;}
void setName(string name0){name=name0;}
void setBookNum(string num0){booknum=num0;}
void setTitle(string title0){title=title0;}
void setBorrowdate(int bd,int bm,int by){Date d(bd,bm,by);borrowdate=d;}
void setToreturndate(int td,int tm,int ty){Date d(td,tm,ty);toreturndate=d;}
void setReturndate(int rd,int rm,int ry){Date d(rd,rm,ry);returndate=d;}
string getNum(){return num;}
string getName(){return name;}
string getBookNum(){return booknum;}
string getTitle(){return title;}
Date getBorrowdate(){return borrowdate;}
Date getReturndate(){return returndate;}
Date getToreturndate(){return toreturndate;}
void dispBorrowBook(){
cout <<num<< "\t"<<name<< "\t"<< "\t"<<booknum<< "\t"<<title<< "\t";
borrowdate.disp();cout<<"\t";
toreturndate.disp();cout<<"\t";
returndate.disp();cout<< "\n";
}
friend class InBorrowBook;
friend class ReaderBorrowBook;
};
void string2date(string pdates,int d[]){
int k=0,by,bm,bd;
while((pdates[k]<'0'||pdates[k]>'9')&&k<pdates.length())k++;
by=0;
for(;pdates[k]!='/'&&k<pdates.length();k++)
by=by*10+pdates[k]-'0';
k++;bm=0;
for(;pdates[k]!='/'&&k<pdates.length();k++)
bm=bm*10+pdates[k]-'0';
if(pdates[k]=='/'){
k++;bd=0;
for(;k<pdates.length();k++)
bd=bd*10+pdates[k]-'0';
}
else bd=1;
d[0]=by;d[1]=bm;d[2]=bd;
}
class InBook{
public:
Book *book;int bookcount;
void write2Bookfile(){
string num,title,author,publisher,pdates;
Date pdate;
int i,bd,bm,by,ct;
float price;
ofstream outf( "book.txt", ios::out ) ;
//写入的文件名应该与读出的文件名相同;调试时可以取不同的文件名,以免覆盖掉原文件
if ( !outf )
{ cerr << "File could not be open." << endl ; }
outf<<"图书信息\n";
for(int i=0;i<bookcount;i++)
{
Date pd=book[i].getPublishdate();
outf<<book[i].getNum()<< '\t'<<book[i].getTitle()<< '\t';
outf<<book[i].getAuthor()<< '\t'<<book[i].getPublisher()<< '\t';
outf<<pd.getYear()<<"/"<<pd.getMonth()<<"/"<<pd.getDay();
outf<< '\t'<<book[i].getPrice()<< '\t'<<book[i].getHowmany()<< '\n' ;
}
outf.close() ;
}
int inbookFile( char * fileName, int delLine)
{
string num,title,author,publisher,pdates;
Date pdate;
int i,bd,bm,by,ct;
float price;
ifstream inf( fileName, ios::in ) ;
if ( !inf )
{ cerr << "File could not be open." << endl ; return 1; }
char s[80];
for ( i=1; i <= delLine; i++ )
inf.getline( s, 80 ) ;
i=0;
while( !inf.eof() ) //{ inf.getline( s, 80 ) ; cout << s << endl ; }
{
inf.getline( s, 80,'\t' ) ;//num=s;
inf.getline( s, 80,'\t' ) ;title=s;
inf.getline( s, 80,'\t' ) ;//author=s;
inf.getline( s, 80,'\t' ) ;//publisher=s;
inf.getline( s, 80,'\t' ) ;//pdates=s;
inf>>price>>ct;
if(title.length()>0) i++;
}
bookcount=i;
cout<<bookcount<<endl;
inf.clear();
inf.seekg(0,ios::beg);
for ( i=1; i <= delLine; i++ )
inf.getline( s, 80 ) ;
book=new Book[bookcount+INC];
for ( i=0; i <bookcount; i++ )
{
inf.getline( s, 80,'\t' ) ;num=s;
inf.getline( s, 80,'\t' ) ;title=s;
inf.getline( s, 80,'\t' ) ;author=s;
inf.getline( s, 80,'\t' ) ;publisher=s;
inf.getline( s, 80,'\t' ) ;pdates=s;
inf>>price>>ct;//inf.getchar();
if(title.length()>0){
int d[3];
if(num[0]==10)num=num.substr(1);
string2date(pdates,d);
by=d[0];bm=d[1];bd=d[2];
book[i]=Book();
book[i].setNum(num);
book[i].setTitle(title);
book[i].setAuthor(author);
book[i].setPublisher(publisher);
book[i].setPrice(price);
book[i].setHowmany(ct);
book[i].setPublishdate(bd,bm,by);
}
}
inf.close() ;
return bookcount;
}
friend class ReaderBorrowBook;
int addbook(string num,string title,string author,string publisher,int bd,int bm,int by,float price,int ct){
int i=bookcount;
book[i]=Book();
book[i].setNum(num);
book[i].setTitle(title);
book[i].setAuthor(author);
book[i].setPublisher(publisher);
book[i].setPrice(price);
book[i].setHowmany(ct);
book[i].setPublishdate(bd,bm,by);
++bookcount;
return bookcount;
}
void searchbookbytitle(string title){
bool found=false;
for(int i=0;i<bookcount;i++)
if((book[i].getTitle()).find(title)!= string::npos) {
//cout<<book[i].getTitle()<< book[i].getTitle().find(title)<<endl;
cout<<i<<"\t";
book[i].dispABook();
found=true;
//return i;
}
if(!found)cout<<"book title:"<<title<<" not found."<<endl;
//return -1;
}
int searchbookbytitlep(string title){
for(int i=0;i<bookcount;i++)
if(book[i].getTitle()==title) {
//cout<<book[i].getTitle()<< book[i].getTitle().find(title)<<endl;
cout<<i<<"\t";
book[i].dispABook();
return i;
}
cout<<"book title:"<<title<<" not found."<<endl;
return -1;
}
void searchbookbyauthor(string author){
bool found=false;
for(int i=0;i<bookcount;i++)
if((book[i].getAuthor()).find(author)!= string::npos) {
//cout<<book[i].getTitle()<< book[i].getTitle().find(title)<<endl;
cout<<i<<"\t";
book[i].dispABook();
found=true;
//return i;
}
if(!found)cout<<"book author:"<<author<<" not found."<<endl;
//return -1;
}
int searchbookbyauthorp(string author){
for(int i=0;i<bookcount;i++)
if(book[i].getAuthor()==author) {
//cout<<book[i].getTitle()<< book[i].getTitle().find(title)<<endl;
cout<<i<<"\t";
book[i].dispABook();
return i;
}
cout<<"book author:"<<author<<" not found."<<endl;
return -1;
}
void searchbookbypub(string pub){
bool found=false;
for(int i=0;i<bookcount;i++)
if((book[i].getPublisher()).find(pub)!= string::npos) {
//cout<<book[i].getTitle()<< book[i].getTitle().find(title)<<endl;
cout<<i<<"\t";
book[i].dispABook();
found=true;
//return i;
}
if(!found)cout<<"book publisher:"<<pub<<" not found."<<endl;
//return -1;
}
int searchbookbypubp(string pub){
for(int i=0;i<bookcount;i++)
if(book[i].getPublisher()==pub) {
//cout<<book[i].getTitle()<< book[i].getTitle().find(title)<<endl;
cout<<i<<"\t";
book[i].dispABook();
return i;
}
return -1;
}
void searchbookbynum(string num){//模糊查找包含num的串
bool found=false;
for(int i=0;i<bookcount;i++)
if((book[i].getNum()).find(num)!= string::npos) {
//cout<<book[i].getTitle()<< book[i].getTitle().find(title)<<endl;
cout<<i<<"\t";
book[i].dispABook();
found=true;
// return i;
}
if(!found)cout<<"book num:"<<num<<" not found."<<endl;
// return -1;
}
int searchbookbynump(string num){//精确查找等于num的串
for(int i=0;i<bookcount;i++)
if((book[i].getNum())==num) {
//cout<<book[i].getTitle()<< book[i].getTitle().find(title)<<endl;
cout<<i<<"\t";
book[i].dispABook();
return i;
}
return -1;
}
void sortbookbynum(){
for(int i=0;i<bookcount;i++){
int k=i;
for(int j=i+1;j<bookcount;j++)
if(book[j].getNum()<book[k].getNum()) k=j;
//cout<<k<<" k&i "<<i<<" :"<<book[i].getNum()<<"---"<<book[k].getNum()<<endl;
if(k!=i){
Book t=book[i];book[i]=book[k];book[k]=t;
}
}
}
void sortbookbytitle(){
for(int i=0;i<bookcount;i++){
int k=i;
for(int j=i+1;j<bookcount;j++)
if(book[j].getTitle()<book[k].getTitle()) k=j;
if(k!=i){
Book t=book[i];book[i]=book[k];book[k]=t;
}
}
}
void changebookbynum(string oldnum,string newnum){
int k=searchbookbynump(oldnum);
if(k>=0) {
book[k].setNum(newnum);
cout<<"changebookbynum successed:"<<endl;
book[k].dispABook();
}
else cout<<"changebook failed. No book of num="<<oldnum<<endl;
}
void deletebookbynum(string num){
int k=searchbookbynump(num);
if(k>=0) {
cout<<"Book to be deleted :"<<endl;
book[k].dispABook();
book[k]=book[bookcount-1];
cout<<"deletebookbynum successed:"<<endl;
bookcount--;
//return bookcount;
}
else cout<<"deletebook failed. No book of num="<<num<<endl;
}
void changebookbytitle(string oldtitle,string newtitle){
int k=searchbookbytitlep(oldtitle);
if(k>=0) {
book[k].setTitle(newtitle);
cout<<"changebookbytitle successed:"<<endl;
book[k].dispABook();
}
else cout<<"changebook failed. No book of title="<<oldtitle<<endl;
}
void deletebookbytitle(string title){
int k=searchbookbytitlep(title);
if(k>=0) {
cout<<"Book to be deleted :"<<endl;
book[k].dispABook();
book[k]=book[bookcount-1];
cout<<"deletebookbytitle successed:"<<endl;
bookcount--;
//return bookcount;
}
else cout<<"deletebook failed. No book of title="<<title<<endl;
}
};
class InReader{
public:
Reader *reader;int readercount;
string a[100];
void write2Readerfile(){
}
int inreaderFile( char * fileName, int delLine)
{
string num,name,college,classno;
int i;
ifstream inf( fileName, ios::in ) ;
if ( !inf )
{ cerr << "File could not be open." << endl ; return 1; }
char s[80];
for ( i=1; i <= delLine; i++ )
inf.getline( s, 80 ) ;
i=0;
while( !inf.eof() )// { inf.getline( s, 80 ) ; cout << s << endl ; }
{
inf.getline( s, 80,'\t' ) ;//num=s;
inf.getline( s, 80,'\t' ) ;name=s;
inf.getline( s, 80,'\t' ) ;//college=s;
inf.getline( s, 80 ) ;//classno=s;
if(name.length()>0) i++;
}
readercount=i;
cout<<readercount<<endl;
inf.clear();
inf.seekg(0,ios::beg);
for ( i=1; i <= delLine; i++ )
inf.getline( s, 80 ) ;
reader=new Reader[readercount+INC];
for ( i=0; i <readercount; i++ )
{
inf.getline( s, 80,'\t' ) ;num=s;
inf.getline( s, 80,'\t' ) ;name=s;
inf.getline( s, 80,'\t' ) ;college=s;
inf.getline( s, 80 ) ;classno=s;
if(name.length()>0){
if(num[0]==10)num=num.substr(1);
reader[i]=Reader();
reader[i].setNum(num);
reader[i].setName(name);
reader[i].setCollege(college);
reader[i].setClassno(classno);
}
}
inf.close() ;
return readercount;
}
int addreader(string num,string name,string college,string classno){
int i=readercount;
reader[i]=Reader();
reader[i].setNum(num);
reader[i].setName(name);
reader[i].setCollege(college);
reader[i].setClassno(classno);
++readercount;
return readercount;
}
//通过学号查询读者信息
void searchreaderbynum(string num){
bool found=false;
for(int i=0;i<readercount;i++)
if((reader[i].getNum()).find(num)!= string::npos) {
cout<<i<<"\t";
reader[i].dispAReader();
found=true;
//return i;
}
if(!found)cout<<"reader of num: "<<num<<" not found"<<endl;
//return -1;
}
int searchreaderbynump(string num){
for(int i=0;i<readercount;i++)
if(reader[i].getNum()==num) {
cout<<i<<"\t";
reader[i].dispAReader();
return i;
}
return -1;
}
//通过姓名查询读者信息
void searchreaderbyname(string name){
bool found=false;
for(int i=0;i<readercount;i++)
if((reader[i].getName()).find(name)!= string::npos) {
//cout<<reader[i].getName()<< reader[i].getName().find(name)<<endl;
cout<<i<<"\t";
reader[i].dispAReader();
found=true;
//return i;
}
if(!found)cout<<"reader name:"<<name<<" not found."<<endl;
//return -1;
}
int searchreaderbynamep(string name){
for(int i=0;i<readercount;i++)
if(reader[i].getName()==name) {
//cout<<reader[i].getName()<< reader[i].getName().find(Name)<<endl;
cout<<i<<"\t";
reader[i].dispAReader();
return i;
}
cout<<"reader name:"<<name<<" not found."<<endl;
return -1;
}
//通过专业班级查询读者信息
void searchreaderbyclassno(string classno){
bool found=false;
for(int i=0;i<readercount;i++)
if((reader[i].getClassno()).find(classno)!= string::npos) {
cout<<i<<"\t";
reader[i].dispAReader();
found=true;
//return i;
}
if(!found)cout<<"reader of classno: "<<classno<<" not found"<<endl;
//return -1;
}
int searchreaderbyclassnop(string classno){
for(int i=0;i<readercount;i++)
if(reader[i].getClassno()==classno) {
cout<<i<<"\t";
reader[i].dispAReader();
return i;
}
return -1;
}
//通过学号升序排序读者信息
void sortreaderbynum(){
for(int i=0;i<readercount;i++){
int k=i;
for(int j=i+1;j<readercount;j++)
if(reader[j].getNum()<reader[k].getNum()) k=j;
//cout<<k<<" k&i "<<i<<" :"<<reader[i].getNum()<<"---"<<reader[k].getNum()<<endl;
if(k!=i){
Reader t=reader[i];reader[i]=reader[k];reader[k]=t;
}
}
}
//通过学院升序排序读者信息
void sortreaderbycollege(){
for(int i=0;i<readercount;i++){
int k=i;
for(int j=i+1;j<readercount;j++)
if(reader[j].getCollege()<reader[k].getCollege()) k=j;
if(k!=i){
Reader t=reader[i];reader[i]=reader[k];reader[k]=t;
}
}
}
//通过学号+姓名修改读者信息
void changereaderbynumname(string oldnum,string oldname,string newnum,string newname){
int k=searchreaderbynump(oldnum);
int j=searchreaderbynamep(oldname);
if(k>=0&&j>=0) {
reader[k].setNum(newnum);
reader[j].setName(newname);
cout<<"changereaderbynum+name successed:"<<endl;
reader[k].dispAReader();
}
else cout<<"changereader failed. No reader of num+name="<<oldnum<<" "<<oldname<<endl;
}
//通过学号+姓名删除读者信息
void deletereaderbynumname(string num,string name){
int k=searchreaderbynump(num);
int j=searchreaderbynamep(name);
if(k>=0&&j>=0) {
cout<<"Reader to be deleted :"<<endl;
reader[j].dispAReader();
reader[j]=reader[readercount-1];
cout<<"deletereaderbynumname successed:"<<endl;
readercount--;
//return readercount;
}
}
friend class ReaderBorrowBook;
};
class InBorrowBook{
public:
BorrowBook *borrowbook;int borrowbookcount;
void write2BorrowBookfile(){
}
int inborrowbookFile( char * fileName, int delLine)
{
string num,name,college,booknum,title;
string borrowdates;
string toreturndates;
string returndates;
int i;
ifstream inf( fileName, ios::in ) ;
if ( !inf )
{ cerr << "File could not be open." << endl ; return 1; }
char s[80];
for ( i=1; i <= delLine; i++ )
inf.getline( s, 80 ) ;
i=0;
while( !inf.eof() )
{
inf.getline( s, 80,'\t') ;
inf.getline( s, 80,'\t' ) ;
inf.getline( s, 80,'\t' ) ;
inf.getline( s, 80 ) ;
if(strlen(s)>1) i++;
}
borrowbookcount=i;
cout<<borrowbookcount<<endl;
inf.clear();
inf.seekg(0,ios::beg);
for ( i=1; i <= delLine; i++ )
inf.getline( s, 80 ) ;
borrowbook=new BorrowBook[borrowbookcount+INC];
for ( i=0; i <borrowbookcount; i++ )
{
inf.getline( s, 80,'\t' ) ;num=s;
inf.getline( s, 80,'\t' ) ;name=s;
inf.getline( s, 80,'\t' ) ;booknum=s;
inf.getline( s, 80,'\t' ) ;title=s;
inf.getline( s, 80,'\t' ) ;borrowdates=s;
inf.getline( s, 80,'\t' ) ;toreturndates=s;
inf.getline( s, 80,'\n' ) ;returndates=s;
if(name.length()>0){
if(num[0]==10)num=num.substr(1);
borrowbook[i]=BorrowBook();
int d[3];
string2date(borrowdates,d);
int by=d[0],bm=d[1],bd=d[2];
borrowbook[i].setBorrowdate(bd,bm,by);
string2date(toreturndates,d);
by=d[0];bm=d[1];bd=d[2];
borrowbook[i].setToreturndate(bd,bm,by);
string2date(returndates,d);
by=d[0];bm=d[1];bd=d[2];
borrowbook[i].setReturndate(bd,bm,by);
borrowbook[i].setNum(num);
borrowbook[i].setName(name);
borrowbook[i].setBookNum(booknum);
borrowbook[i].setTitle(title);
}
}
inf.close() ;
return borrowbookcount;
}
friend class ReaderBorrowBook;
int searchbyreaderbook(string readernum,string booknum){
for(int i=0;i<borrowbookcount;i++)
if((borrowbook[i].getNum())==readernum&&(borrowbook[i].getBookNum())==booknum) {
cout<<i<<"\t";
borrowbook[i].dispBorrowBook();
return i;
}
return -1;
}
//通过学号进行图书借阅查询
void searchbynum(string num){
bool found=false;
for(int i=0;i<borrowbookcount;i++)
if((borrowbook[i].getNum()).find(num)!= string::npos) {
//cout<<borrowbook[i].getNum()<< borrowbook[i].getNum().find(num)<<endl;
cout<<i<<"\t";
borrowbook[i].dispBorrowBook();
found=true;
//return i;
}
if(!found)cout<<"borrowbook num:"<<num<<" not found."<<endl;
//return -1;
}
int searchbynump(string num){
for(int i=0;i<borrowbookcount;i++)
if(borrowbook[i].getNum()==num) {
//cout<<borrowbook[i].getNum()<< borrowbook[i].getNum().find(num)<<endl;
cout<<i<<"\t";
borrowbook[i].dispBorrowBook();
return i;
}
//cout<<"borrowbook num:"<<num<<" not found."<<endl;
//return -1;
}
//通过书名进行图书借阅查询
void searchbytitle(string title){
bool found=false;
for(int i=0;i<borrowbookcount;i++)
if((borrowbook[i].getTitle()).find(title)!= string::npos) {
//cout<<borrowbook[i].getTitle()<< borrowbook[i].getTitle().find(title)<<endl;
cout<<i<<"\t";
borrowbook[i].dispBorrowBook();
found=true;
//return i;
}
if(!found)cout<<"borrowbook title:"<<title<<" not found."<<endl;
//return -1;
}
int searchbytitlep(string title){
for(int i=0;i<borrowbookcount;i++)
if(borrowbook[i].getTitle()==title) {
//cout<<borrowbook[i].getTitle()<< borrowbook[i].getTitle().find(title)<<endl;
cout<<i<<"\t";
borrowbook[i].dispBorrowBook();
return i;
}
cout<<"borrowbook title:"<<title<<" not found."<<endl;
return -1;
}
//通过学院进行图书借阅查询
void searchbycollege(string college){
int i,k;
InReader b;
b.inreaderFile("reader.txt",1);
int j=0;
for(i=0;i<b.readercount;i++){
if((b.reader[i].getCollege()).find(college)!= string::npos) {
b.a[j]=b.reader[i].getNum();
j++;
}
}
if(j==0)
cout<<"该学院学生无借书记录"<<endl;
for(int k=0;k<j;k++)
searchbynum(b.a[k]);
}
int searchbycollegep(string college){
int i,k;
InReader b;
int j=0;
bool found=false;
for(i=0;i<b.readercount;i++){
if((b.reader[i].getCollege()).find(college)!= string::npos) {
cout<<i<<"\t";
b.a[j]=b.reader[i].getNum();
j++;
found=true;
}
if(!found)cout<<"reader of college: "<<college<<" not found"<<endl;
//return -1;
}
}
};
class ReaderBorrowBook{
InBook bk;
InReader rd;
InBorrowBook bb;
public:
void write2file(){
bk.write2Bookfile();
rd.write2Readerfile();
bb.write2BorrowBookfile();
}
void init(){
bk.inbookFile( "book.txt", 1);
rd.inreaderFile( "reader.txt", 1);
bb.inborrowbookFile( "borrowbook.txt", 1);
}
void dispBook(){
for ( int i=0; i <bk.bookcount; i++ )
{cout <<i<<":";
bk.book[i].dispABook();}
}
void dispReader(){
for ( int i=0; i <rd.readercount; i++ )
{cout <<i<<":";rd.reader[i].dispAReader();}
}
void dispBorrowbook(){
for ( int i=0; i <bb.borrowbookcount; i++ )
{cout <<i<<":";bb.borrowbook[i].dispBorrowBook();}
}
void dispCount(){
cout<<bk.bookcount<<endl;cout<<rd.readercount<<endl;cout<<bb.borrowbookcount<<endl;
}
void addbook(){
string num,title,author,publisher;
char num0[80],tit[80],auth[80],pub[80];
int pd,pm,py,howmany;
float price;
Date publishdate;
cout<<"书号、书名、作者、出版社、出版日期(yyyy mm dd)、定价、存馆数量"<<endl;
string num1="24416-5",title0="数据结构",author0="王红梅,胡明,王涛",pub0="清华大学出版社";
int pd0=1,pm0=1,py0=2012;
float price0=29.0;
int howmany0=10;
//bookcount=
bk.addbook(num1,title0,author0,pub0,pd0,pm0,py0,price0,howmany0);
int i=bk.bookcount-1;
cout <<i<<":";
bk.book[i].dispABook();
}
void addreader(){
string num,name,college,classno;
char num0[80],nam[80],coll[80],clas[80];
cout<<"学号\t姓名\t学院\t专业班级:"<<endl;
string num1="20151000",name0="王涛",college0="computer",class0="network class 1";
rd.addreader(num1,name0,college0,class0);
int i=rd.readercount-1;
cout <<i<<":";
rd.reader[i].dispAReader();
}
void searchbook(){
cout<<"2.图书信息查询:分别按书名, 按作者名, 按出版社进行查询。"<<endl;
char tit[80];
string title="数据结构",author="胡明",pub="机械工业";
int i,j,k,select;
while(1){
cout<<"图书信息查询:"<<endl;
cout<<"1.按书名查询"<<endl;
cout<<"2.按作者名查询"<<endl;
cout<<"3.按出版社查询"<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<"书名:";
getline(cin,title,'\n');
bk.searchbookbytitle(title);
break;
case 2:
cout<<"作者名:";
getline(cin,author,'\n');
bk.searchbookbyauthor(author);
break;
case 3:
cout<<"出版社:";
getline(cin,pub,'\n');
bk.searchbookbypub(pub);break;
case 0:return;
}
}
}
void sortbook(){
int select;
cout<<"3.图书信息排序:按书号、书名等按升序进行排序。"<<endl;
cout<<"图书信息排序:"<<endl;
cout<<"1.按书号排序"<<endl;
cout<<"2.按书名排序"<<endl;
cout<<"0. return"<<endl;
cin>>select;
switch(select){
case 1:
cout<<"书号:";
bk.sortbookbynum();
dispBook();
break;
case 2:
cout<<"书名:";
bk.sortbookbytitle();
dispBook();
break;
case 0:return;
}
}
void editbook(){
string oldtitle="VisualBasic 程序设计教程",newtitle="VisualBasic 程序设计教程-C",oldnum="40667",newnum="40667-C";
int select;
cout<<"4.图书信息的修改、删除:按书号或书名进行图书的修改和删除。"<<endl;
while(1){
cout<<"图书信息的修改、删除:"<<endl;
cout<<"1.按书号修改"<<endl;
cout<<"2.按书号删除"<<endl;
cout<<"3.按书名修改"<<endl;
cout<<"4.按书名删除"<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<"old书号:";
getline(cin,oldnum,'\n');
cout<<"new书号:";
getline(cin,newnum,'\n');
cout<<"changebookbynum: "<<oldnum<<" to "<<newnum<<endl;
bk.changebookbynum(oldnum,newnum);
//dispBook();
break;
case 2:
cout<<"delete书号:";
getline(cin,oldnum,'\n');
cout<<"delete书号:"<<oldnum<<endl;
bk.deletebookbynum(oldnum);
//dispBook();
break;
case 3:
cout<<"old书名:";
getline(cin,oldtitle,'\n');
cout<<"new书名:";
getline(cin,newtitle,'\n');
cout<<"changebookbytitle: "<<oldtitle<<" to "<<newtitle<<endl;
bk.changebookbytitle(oldtitle,newtitle);
//dispBook();
break;
case 4:
cout<<"delete书名:";
getline(cin,oldtitle,'\n');
cout<<"deletebookbytitle: "<<oldtitle<<endl;
bk.deletebookbytitle(oldtitle);
//dispBook();
break;
case 0:return;
}
}
}
void searchreader(){
cout<<"6.读者信息查询:分别按学号、姓名、专业班级等进行查询。"<<endl;
char tit[80];
string num="20150000",name="NoName",classno="网络工程15-1";
int i,j,k,select;
while(1){
cout<<"读者信息查询:"<<endl;
cout<<"1.按学号查询"<<endl;
cout<<"2.按姓名查询"<<endl;
cout<<"3.按专业班级查询"<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<"学号:";
getline(cin,num,'\n');
rd.searchreaderbynum(num);
break;
case 2:
cout<<"姓名:";
getline(cin,name,'\n');
rd.searchreaderbyname(name);
break;
case 3:
cout<<"专业班级:";
getline(cin,classno,'\n');
rd.searchreaderbyclassno(classno);break;
case 0:return;
}
}
}
void sortreader(){
int select;
cout<<"7.读者信息排序:按学号、学院等按升序进行排序。"<<endl;
cout<<"读者信息排序:"<<endl;
cout<<"1.按学号排序"<<endl;
cout<<"2.按学院排序"<<endl;
cout<<"0. return"<<endl;
cin>>select;
switch(select){
case 1:
cout<<"学号:";
rd.sortreaderbynum();
dispReader();
break;
case 2:
cout<<"学院:";
rd.sortreaderbycollege();
dispReader();
break;
case 0:return;
}
}
void editreader(){
string oldnum="2015000000",newnum="20076954",oldname="Noname",newname="汤武";
int select;
cout<<"8.读者信息的修改、删除:按学号+姓名进行读者信息的修改和删除。"<<endl;
while(1){
cout<<"读者信息的修改、删除:"<<endl;
cout<<"1.按学号+姓名修改"<<endl;
cout<<"2.按学号+姓名删除"<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<"old学号+姓名:";
getline(cin,oldnum,'\n');
getline(cin,oldname,'\n');
cout<<"new学号+姓名:";
getline(cin,newnum,'\n');
getline(cin,newname,'\n');
cout<<"changereaderbynumname: "<<oldnum<<" "<<oldname<<" to "<<newnum<<" "<<newname<<endl;
rd.changereaderbynumname(oldnum,oldname,newnum,newname);
//dispReader();
break;
case 2:
cout<<"delete学号+姓名:";
getline(cin,oldnum,'\n');
getline(cin,oldname,'\n');
cout<<"delete学号+姓名:"<<oldnum<<" "<<oldname<<endl;
rd.deletereaderbynumname(oldnum,oldname);
//dispReader();
break;
case 0:return;
}
}
}
void readerborrowabook(){
cout<<"9.图书借阅:输入学号+书号,如果该书图书信息表中的存馆数量大于0,则可以借出,"<<endl;
string rdnum="20061709",booknum="33071",name,title;
int select,rdpos,bookpos,y,m,d;
while(1){
cout<<"图书借阅:"<<endl;
cout<<"1.借书"<<endl;
cout<<"0.return"<<endl;
cin>>select;
cin.get();
if(select==0)return;
cout<<"borrow学号:";
getline(cin,rdnum,'\n');
cout<<"borrow书号:";
getline(cin,booknum,'\n');
bookpos=bk.searchbookbynump(booknum);
rdpos=rd.searchreaderbynump(rdnum);
if(bookpos>0&&rdpos>0){
int hm=bk.book[bookpos].getHowmany();
if(hm>0){
name=rd.reader[rdpos].getName();
title=bk.book[bookpos].getTitle();
bk.book[bookpos].setHowmany(hm-1); //修改图书信息表中的存馆数量
bb.borrowbook[bb.borrowbookcount].setNum(rdnum);
bb.borrowbook[bb.borrowbookcount].setBookNum(booknum);
bb.borrowbook[bb.borrowbookcount].setName(name);
bb.borrowbook[bb.borrowbookcount].setTitle(title);
SYSTEMTIME ct;
GetLocalTime(&ct);//取系统时间,如果用GetSystemTime(&ct);那么获取的是格林尼治标准时间
y=ct.wYear;
m=ct.wMonth;
d=ct.wDay;
Date toret=Date(d,m,y)+60;
bb.borrowbook[bb.borrowbookcount].setBorrowdate(d,m,y);
bb.borrowbook[bb.borrowbookcount].setToreturndate(toret.getDay(),toret.getMonth(),toret.getYear());
bb.borrowbook[bb.borrowbookcount].setReturndate(1,1,1);
bb.borrowbookcount++;
}
else cout<<booknum<<" 存馆数量=0"<<". can't be borrowed. "<<endl;
}
else{
if(bookpos<0)cout<<"No book "<<booknum<<". can't borrow!"<<endl;
if(rdpos<0)cout<<"No reader "<<rdnum<<". can't borrow!"<<endl;
}
}
}
void readerreturnabook(){
cout<<"10.图书归还:输入学号+书名,修改图书信息表中的存馆数量,图书借阅表中记录该同学的归还日期。"<<endl;
char tit[80];
string rdnum="20061709",booknum="33071",name,title;
int select,rdpos,bookpos,y,m,d;
while(1){
cout<<"图书归还:"<<endl;
cout<<"1.还书"<<endl;
cout<<"0.return"<<endl;
cin>>select;
cin.get();
if(select==0)return;
cout<<"borrow学号:";
getline(cin,rdnum,'\n');
cout<<"borrow书号:";
getline(cin,booknum,'\n');
booknum=tit;
bookpos=bk.searchbookbynump(booknum);
rdpos=rd.searchreaderbynump(rdnum);
if(bookpos>0&&rdpos>0){
bk.book[bookpos].setHowmany(bk.book[bookpos].getHowmany()+1);
SYSTEMTIME ct;
GetLocalTime(&ct);//取系统时间
y=ct.wYear;
m=ct.wMonth;
d=ct.wDay;
bb.borrowbook[bb.borrowbookcount].setReturndate(d,m,y);
}
else{
if(bookpos<0)cout<<"No book "<<booknum<<". can't return!"<<endl;
if(rdpos<0)cout<<"No reader "<<rdnum<<". can't return!"<<endl;
}
}
}
void searchreaderborrowbook(){
cout<<"11.图书借阅查询:分别按学号、书名、学院等进行查询。"<<endl;
char tit[80];
string num="20150000",title="数据结构",college="信息学院";
int i,j,k,select;
while(1){
cout<<"图书借阅查询:"<<endl;
cout<<"1.按学号查询"<<endl;
cout<<"2.按书名查询"<<endl;
cout<<"3. 按学院查询"<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<"学号:";
getline(cin,num,'\n');
bb.searchbynum(num);
break;
case 2:
cout<<"书名:";
getline(cin,title,'\n');
bb.searchbytitle(title);
break;
case 3:
cout<<"学院:";
getline(cin,college,'\n');
bb.searchbycollege(college);
break;
case 0:return;
}
}
}
};
int main(){
ReaderBorrowBook rbb;
rbb.init();
rbb.dispBook();
rbb.dispReader();
rbb.dispBorrowbook();
rbb.dispCount();
int select;
while(1){
cout<<"菜单选择功能:"<<endl;
cout<<"1.图书信息添加功能:包括书号、书名、作者、出版社名称、存馆数量、定价等"<<endl;
cout<<"2.图书信息查询:分别按书名, 按作者名, 按出版单位等进行查询。"<<endl;
cout<<"3.图书信息排序:按书号、书名等按升序进行排序。"<<endl;
cout<<"4.图书信息的修改、删除:按书号或书名进行图书的修改和删除。"<<endl;
cout<<"5.读者信息添加功能:包括学号、姓名、学院、专业班级等。"<<endl;
cout<<"6.读者信息查询:分别按学号、姓名、班级等进行查询。"<<endl;
cout<<"7.读者信息排序:按学号、学院等按升序进行排序。"<<endl;
cout<<"8.读者信息的修改、删除:按学号+姓名进行读者信息的修改和删除。"<<endl;
cout<<"9.图书借阅:输入学号+书号,如果该书图书信息表中的存馆数量大于0,则可以借出,"<<endl;
cout<<"借出相应数量后修改图书信息表中的存馆数量,在图书借阅表添加该同学的借阅。"<<endl;
cout<<"10.图书归还:输入学号+书名,修改图书信息表中的存馆数量,在图书借阅表中记录该同学的归还时间。"<<endl;
cout<<"11.图书借阅查询:分别按学号、书名、学院等进行查询。"<<endl;
cout<<"0. exit"<<endl;
cin>>select;
switch(select){
case 1:rbb.addbook(); rbb.dispCount();break;
case 2:rbb.searchbook();break;
case 3:rbb.sortbook();break;
case 4:rbb.editbook();break;
case 5:rbb.addreader(); rbb.dispCount();break;
case 6:rbb.searchreader();break;
case 7:rbb.sortreader();break;
case 8:rbb.editreader();break;
case 9:rbb.readerborrowabook();break;
case 10:rbb.readerreturnabook();break;
case 11:rbb.searchreaderborrowbook();break;
case 0:rbb.write2file();exit(0);
}
}
return 0;
}
边栏推荐
- Crawl the information of national colleges and universities in 1 minute and make it into a large screen for visualization!
- 构建多架构镜像的最佳实践
- 处理gzip: stdin: not in gzip formattar: Child returned status 1tar: Error is not recoverable: exitin
- 历史上的今天:支付宝推出条码支付;分时系统之父诞生;世界上第一支电视广告...
- IDEA中设置背景图片(超详细)
- Idea jar package conflict troubleshooting
- Today in history: Alipay launched barcode payment; The father of time-sharing system was born; The first TV advertisement in the world
- idea jar包冲突排查
- Yyds dry inventory company stipulates that all interfaces use post requests. Why?
- After the win10 system is upgraded for a period of time, the memory occupation is too high
猜你喜欢

Practice of constructing ten billion relationship knowledge map based on Nebula graph

PyC file decompile

历史上的今天:支付宝推出条码支付;分时系统之父诞生;世界上第一支电视广告...

Mathematical analysis_ Notes_ Chapter 6: Riemann integral of univariate function

Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus

Yyds dry goods inventory hands-on teaching you to carry out the packaging and release of mofish Library (fishing Library)

Sim2real environment configuration tutorial

Summary | three coordinate systems in machine vision and their relationships

去除router-link中的下划线

注册成为harmonyos开发者并安装DevEco Studio 3.0 Beta2 for HarmonyOS
随机推荐
Introduction to database system Chapter 1 short answer questions - how was the final exam?
Summary of monthly report | list of major events of moonbeam in June
Leetcode -- number of palindromes
sim2real环境配置教程
Kubernetes family container housekeeper pod online Q & A?
由ASP.NET Core根据路径下载文件异常引发的探究
Invalid bound statement (not found) solution summary
云原生的 CICD 框架:Tekton
Song of cactus - throwing stones to ask the way (3)
Flink real-time data warehouse (7): Flink realizes the full pull module to extract data in MySQL
分析超700万个研发需求发现,这8门编程语言才是行业最需要的!
去除router-link中的下划线
dried food! Understand the structural vulnerability of graph convolution networks
曆史上的今天:支付寶推出條碼支付;分時系統之父誕生;世界上第一支電視廣告...
OSPF - route aggregation [(summary) including configuration commands] | address summary calculation method - detailed explanation
(practice C language every day) the sum of the nearest three numbers
What is Amazon keyword index? The consequences of not indexing are serious
头条 | 亚控科技产品入选中纺联《纺织服装行业数字化转型解决方案重点推广名录》
Foreign enterprise executives, continuous entrepreneurs, yoga and skiing masters, and a program life of continuous iteration and reconstruction
day4