当前位置:网站首页>Library management system (Shandong Agricultural University Curriculum Design)
Library management system (Shandong Agricultural University Curriculum Design)
2022-07-02 16:27:00 【20-year-old wall supporting farmer】
Code as shown :
#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){
// Judge the validity of the date
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{
// Book number 、 Title 、 author 、 Press. 、 Publication date 、 Publishing pricing 、 Number of Libraries
private:
string num;
string title;
string author;
string publisher;
Date publishdate;
float price;
int howmany;
public:
Book(string num0="24416-5",string title0=" data structure ",string author0=" Wang Hongmei , Hu Ming , Wang Tao ",
string pub0=" tsinghua university press ",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{
// Student number 、 full name 、 college 、 Professional class
private:
string num;
string name;
string college;
string classno;
public:
Reader(string num0="20150000",string name0="NoName",string college0=" School of information ",string clsn=" Network engineering 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{
// Student number 、 full name 、 Book number 、 Title 、 Borrowing date 、 Due date 、 Return date
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=" School of information ",string booknum0="24416-5",
string title0=" data structure ",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 ) ;
// The file name written should be the same as the file name read ; When debugging, you can take different file names , To avoid overwriting the original file
if ( !outf )
{ cerr << "File could not be open." << endl ; }
outf<<" Book information \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){// Fuzzy Lookup contains num String of
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){// Exact search equals num String of
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;
}
// Query reader information through student number
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;
}
// Query reader information by name
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;
}
// Query reader information through professional classes
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;
}
// Sort reader information in ascending order by student number
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;
}
}
}
// Sort reader information in ascending order by College
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;
}
}
}
// By student number + Name changes reader information
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;
}
// By student number + Name delete reader information
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;
}
// Carry out book borrowing inquiry through student number
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;
}
// Carry out book borrowing query through book title
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;
}
// Carry out book borrowing and inquiry through the College
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<<" The college students have no record of borrowing books "<<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<<" Book number 、 Title 、 author 、 Press. 、 Publication date (yyyy mm dd)、 pricing 、 Number of Libraries "<<endl;
string num1="24416-5",title0=" data structure ",author0=" Wang Hongmei , Hu Ming , Wang Tao ",pub0=" tsinghua university press ";
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<<" Student number \t full name \t college \t Professional class :"<<endl;
string num1="20151000",name0=" Wang Tao ",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. Book information inquiry : According to the book title , By author's name , Query by publishing house ."<<endl;
char tit[80];
string title=" data structure ",author=" Hu Ming ",pub=" The machinery industry ";
int i,j,k,select;
while(1){
cout<<" Book information inquiry :"<<endl;
cout<<"1. Search by title "<<endl;
cout<<"2. Search by author name "<<endl;
cout<<"3. Query by publishing house "<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<" Title :";
getline(cin,title,'\n');
bk.searchbookbytitle(title);
break;
case 2:
cout<<" The author's name :";
getline(cin,author,'\n');
bk.searchbookbyauthor(author);
break;
case 3:
cout<<" Press. :";
getline(cin,pub,'\n');
bk.searchbookbypub(pub);break;
case 0:return;
}
}
}
void sortbook(){
int select;
cout<<"3. Book information sorting : By book number 、 Book titles are sorted in ascending order ."<<endl;
cout<<" Book information sorting :"<<endl;
cout<<"1. Sort by book number "<<endl;
cout<<"2. Sort by title "<<endl;
cout<<"0. return"<<endl;
cin>>select;
switch(select){
case 1:
cout<<" Book number :";
bk.sortbookbynum();
dispBook();
break;
case 2:
cout<<" Title :";
bk.sortbookbytitle();
dispBook();
break;
case 0:return;
}
}
void editbook(){
string oldtitle="VisualBasic Programming tutorial ",newtitle="VisualBasic Programming tutorial -C",oldnum="40667",newnum="40667-C";
int select;
cout<<"4. Modification of book information 、 Delete : Modify and delete books by book number or title ."<<endl;
while(1){
cout<<" Modification of book information 、 Delete :"<<endl;
cout<<"1. Modify according to the book number "<<endl;
cout<<"2. Delete by book number "<<endl;
cout<<"3. Revise according to the title "<<endl;
cout<<"4. Delete by title "<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<"old Book number :";
getline(cin,oldnum,'\n');
cout<<"new Book number :";
getline(cin,newnum,'\n');
cout<<"changebookbynum: "<<oldnum<<" to "<<newnum<<endl;
bk.changebookbynum(oldnum,newnum);
//dispBook();
break;
case 2:
cout<<"delete Book number :";
getline(cin,oldnum,'\n');
cout<<"delete Book number :"<<oldnum<<endl;
bk.deletebookbynum(oldnum);
//dispBook();
break;
case 3:
cout<<"old Title :";
getline(cin,oldtitle,'\n');
cout<<"new Title :";
getline(cin,newtitle,'\n');
cout<<"changebookbytitle: "<<oldtitle<<" to "<<newtitle<<endl;
bk.changebookbytitle(oldtitle,newtitle);
//dispBook();
break;
case 4:
cout<<"delete Title :";
getline(cin,oldtitle,'\n');
cout<<"deletebookbytitle: "<<oldtitle<<endl;
bk.deletebookbytitle(oldtitle);
//dispBook();
break;
case 0:return;
}
}
}
void searchreader(){
cout<<"6. Reader information query : By student number 、 full name 、 Professional classes, etc ."<<endl;
char tit[80];
string num="20150000",name="NoName",classno=" Network engineering 15-1";
int i,j,k,select;
while(1){
cout<<" Reader information query :"<<endl;
cout<<"1. By student number "<<endl;
cout<<"2. Search by name "<<endl;
cout<<"3. Query by professional class "<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<" Student number :";
getline(cin,num,'\n');
rd.searchreaderbynum(num);
break;
case 2:
cout<<" full name :";
getline(cin,name,'\n');
rd.searchreaderbyname(name);
break;
case 3:
cout<<" Professional class :";
getline(cin,classno,'\n');
rd.searchreaderbyclassno(classno);break;
case 0:return;
}
}
}
void sortreader(){
int select;
cout<<"7. Reader information sorting : According to the student id 、 Colleges, etc. are sorted in ascending order ."<<endl;
cout<<" Reader information sorting :"<<endl;
cout<<"1. Sort by student number "<<endl;
cout<<"2. Sort by College "<<endl;
cout<<"0. return"<<endl;
cin>>select;
switch(select){
case 1:
cout<<" Student number :";
rd.sortreaderbynum();
dispReader();
break;
case 2:
cout<<" college :";
rd.sortreaderbycollege();
dispReader();
break;
case 0:return;
}
}
void editreader(){
string oldnum="2015000000",newnum="20076954",oldname="Noname",newname=" Tang Wu ";
int select;
cout<<"8. Modification of reader information 、 Delete : According to the student id + Name to modify and delete reader information ."<<endl;
while(1){
cout<<" Modification of reader information 、 Delete :"<<endl;
cout<<"1. According to the student id + Name change "<<endl;
cout<<"2. According to the student id + Name delete "<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<"old Student number + full name :";
getline(cin,oldnum,'\n');
getline(cin,oldname,'\n');
cout<<"new Student number + full name :";
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 Student number + full name :";
getline(cin,oldnum,'\n');
getline(cin,oldname,'\n');
cout<<"delete Student number + full name :"<<oldnum<<" "<<oldname<<endl;
rd.deletereaderbynumname(oldnum,oldname);
//dispReader();
break;
case 0:return;
}
}
}
void readerborrowabook(){
cout<<"9. Book borrowing : Enter the student id + Book number , If the number of Libraries in the book information table of the book is greater than 0, You can lend ,"<<endl;
string rdnum="20061709",booknum="33071",name,title;
int select,rdpos,bookpos,y,m,d;
while(1){
cout<<" Book borrowing :"<<endl;
cout<<"1. Borrow books "<<endl;
cout<<"0.return"<<endl;
cin>>select;
cin.get();
if(select==0)return;
cout<<"borrow Student number :";
getline(cin,rdnum,'\n');
cout<<"borrow Book number :";
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); // Modify the number of Libraries in the book information table
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);// Take the system time , If you use GetSystemTime(&ct); So what you get is Greenwich mean time
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<<" Number of Libraries =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. Book return : Enter the student id + Title , Modify the number of Libraries in the book information table , Record the return date of the student in the book borrowing form ."<<endl;
char tit[80];
string rdnum="20061709",booknum="33071",name,title;
int select,rdpos,bookpos,y,m,d;
while(1){
cout<<" Book return :"<<endl;
cout<<"1. Return books "<<endl;
cout<<"0.return"<<endl;
cin>>select;
cin.get();
if(select==0)return;
cout<<"borrow Student number :";
getline(cin,rdnum,'\n');
cout<<"borrow Book number :";
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);// Take the system time
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. Book borrowing inquiry : By student number 、 Title 、 Colleges and so on ."<<endl;
char tit[80];
string num="20150000",title=" data structure ",college=" School of information ";
int i,j,k,select;
while(1){
cout<<" Book borrowing inquiry :"<<endl;
cout<<"1. By student number "<<endl;
cout<<"2. Search by title "<<endl;
cout<<"3. Query by College "<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<" Student number :";
getline(cin,num,'\n');
bb.searchbynum(num);
break;
case 2:
cout<<" Title :";
getline(cin,title,'\n');
bb.searchbytitle(title);
break;
case 3:
cout<<" college :";
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<<" Menu selection function :"<<endl;
cout<<"1. Book information adding function : Including book number 、 Title 、 author 、 Publisher name 、 Number of Libraries 、 Pricing, etc "<<endl;
cout<<"2. Book information inquiry : According to the book title , By author's name , Query by publishing unit ."<<endl;
cout<<"3. Book information sorting : By book number 、 Book titles are sorted in ascending order ."<<endl;
cout<<"4. Modification of book information 、 Delete : Modify and delete books by book number or title ."<<endl;
cout<<"5. Reader information adding function : Including student ID 、 full name 、 college 、 Professional classes, etc ."<<endl;
cout<<"6. Reader information query : By student number 、 full name 、 Class, etc ."<<endl;
cout<<"7. Reader information sorting : According to the student id 、 Colleges, etc. are sorted in ascending order ."<<endl;
cout<<"8. Modification of reader information 、 Delete : According to the student id + Name to modify and delete reader information ."<<endl;
cout<<"9. Book borrowing : Enter the student id + Book number , If the number of Libraries in the book information table of the book is greater than 0, You can lend ,"<<endl;
cout<<" Modify the library quantity in the book information table after lending the corresponding quantity , Add the student's borrowing in the book borrowing form ."<<endl;
cout<<"10. Book return : Enter the student id + Title , Modify the number of Libraries in the book information table , Record the return time of the student in the book borrowing form ."<<endl;
cout<<"11. Book borrowing inquiry : By student number 、 Title 、 Colleges and so on ."<<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;
}
边栏推荐
- JS learning notes - data types
- 数仓中的维度表与事实表
- [fluent] dart data type string type (string definition | string splicing | string API call)
- 头条 | 亚控科技产品入选中纺联《纺织服装行业数字化转型解决方案重点推广名录》
- 手机app通达信添加自定义公式(分时T+0)为例子讲解
- MySQL min() finds the minimum value under certain conditions, and there are multiple results
- Aujourd'hui dans l'histoire: Alipay lance le paiement par code à barres; La naissance du père du système de partage du temps; La première publicité télévisée au monde...
- 请问怎么在oracle视图中使用stustr函数
- Yyds dry inventory company stipulates that all interfaces use post requests. Why?
- Summary | three coordinate systems in machine vision and their relationships
猜你喜欢
Boot 事务使用
2022 the latest and most detailed will successfully set the background image in vscade and solve unsupported problems at the same time
sql解决连续登录问题变形-节假日过滤
SSM integration exception handler and project exception handling scheme
电脑管理员权限在哪里可以打开
Storage, reading and writing of blood relationship data of Nepal Graph & Data Warehouse
中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
Does bone conduction earphone have external sound? Advantages of bone conduction earphones
After the win10 system is upgraded for a period of time, the memory occupation is too high
数学分析_笔记_第6章:一元函数的Riemann积分
随机推荐
去除router-link中的下划线
Summary | three coordinate systems in machine vision and their relationships
Summary of multithreading and thread synchronization knowledge
Sim2real environment configuration tutorial
Boot connection to impala database
Add user-defined formula (time sharing t+0) to mobile app access as an example
JS learning notes - first acquaintance
Practice of constructing ten billion relationship knowledge map based on Nebula graph
请问怎么在oracle视图中使用stustr函数
Maui learning road (III) -- in depth discussion of winui3
分析超700万个研发需求发现,这8门编程语言才是行业最需要的!
[solution] educational codeforces round 82
unity Hub 登录框变得很窄 无法登录
数仓中的维度表与事实表
云原生的 CICD 框架:Tekton
Mobile web development learning notes - Layout
Invalid bound statement (not found)解决方法总结
How to use stustr function in Oracle view
潘多拉 IOT 开发板学习(RT-Thread)—— 实验2 RGB LED 实验(学习笔记)
绝对真理和相对真理思考