<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
C++編寫的一個圖書管理系統,供大家參考,具體內容如下
2018大一的課設,搬到這紀念一下,共1200多行程式碼
為圖書管理人員編寫一個圖書管理系統,圖書管理系統的設計主要是實現對圖書的管理和相關操作,包括3個表:
圖書資訊表——儲存圖書的基本資訊,包括書號、書名、作者、出版社、出版日期、存館數量、定價等。
讀者資訊表——儲存讀者的基本資訊,包括學號、姓名、學院、專業班級等。
圖書借閱表——儲存讀者借書的相關資訊,包括學號、姓名、書號、書名、借閱日期、應還日期、歸還日期等。
用選單選擇方式完成了以下功能:
1、圖書資訊新增功能:包括書號、書名、作者、出版社、出版日期、存館數量、定價等。
2、圖書資訊查詢:分別按書名, 按作者名,
按出版單位等進行查詢。
3、圖書資訊排序:按書號、書名等按升序進行排序。
4、圖書資訊的修改、刪除:按書號或書名進行圖書的修改和刪除。
5、讀者資訊新增功能:包括學號、姓名、學院、專業、班級等。
6、讀者資訊查詢:分別按學號、姓名、班級等進行查詢。
7、讀者資訊排序:按學號、學院等按升序進行排序。
8、讀者資訊的修改、刪除:按學號+姓名進行讀者資訊的修改和刪除
9、圖書借閱:輸入學號+書號,如果該書圖書資訊表中的存館數量大於0,則可以借出,借出相應數量後修改圖書資訊表中的存館數量,在圖書借閱表新增該同學的借閱。
10、圖書歸還:輸入學號+書號,修改圖書資訊表中的存館數量,在圖書借閱表中記錄該同學的歸還時間。
11、圖書借閱查詢:分別按學號、書名、學院等進行查詢。
#include <iostream> #include <string> #include <cstring> #include <fstream> #include <cstdlib> #include <windows.h> #include <winbase.h> const int INC=20; using namespace std; class Date{ //Date類 :日期類 public: int day; //日 int month; //月 int year; //年 Date(int d=1,int m=1,int y=2012){ //建構函式 預設初始日期2012.1.1 //判斷日期的合法性 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; //年份yy 月份mm 日dd 借閱天數 dtmp 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; //s書號 string title; //標題 string author; //作者 string publisher; //出版社 Date publishdate; //Date類:出版日期 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'; //獲取Book資訊 :書號標題 作者 出版社 日期 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 booknum; string title; Date borrowdate; Date toreturndate; Date returndate; BorrowBook(string num0="20150000",string name0="NoName",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; 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"<<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; //book[n],很多本書 int bookcount; //記數 void write2Bookfile() { string num,title,author,publisher,pdates; Date pdate; int i,bd,bm,by,ct; //多餘變數吧 float price; ofstream outf( "d:\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) //獲取圖書資訊 {cout<<1<<endl; 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; //reader[n],讀者總數 void write2Readerfile() //寫入讀者資訊 { string a1,b1,c1,d1; ofstream fout( "d:\reader.txt", ios::out ); if ( !fout ) { cerr << "File could not be open." << endl ; } fout<<"讀者資訊n"; for(int i=0;i<readercount;i++) fout<<reader[i].getNum()<<'t'<<reader[i].getName()<<'t'<<reader[i].getCollege()<<'t'<<reader[i].getClassno()<<endl; fout.close(); } int inreaderFile( char * fileName, int delLine) //獲取讀者資訊 {cout<<1<<endl; 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 nnname) //按名字查詢讀者 { for(int i=0;i<readercount;i++) if(reader[i].getName()==nnname) { cout<<i<<"t"; reader[i].dispAReader(); // return i; } // return -1; } int searchreaderbynamep(string nnname){//模糊查詢 for(int i=0;i<readercount;i++) if(reader[i].getName()==nnname) { cout<<i<<"t"; reader[i].dispAReader(); return i; } return -1; } void searchreaderbyzybj(string zzy) //按學院查詢 { for(int i=0;i<readercount;i++) if(reader[i].getCollege()==zzy) { cout<<i<<"t"; reader[i].dispAReader(); // return i; } // return -1; } int searchreaderbyzybjp(string zzy){ //精確查詢 for(int i=0;i<readercount;i++) if(reader[i].getCollege()==zzy) { cout<<i<<"t"; reader[i].dispAReader(); return i; } return -1; } int searchreaderbyzybjjp(string bbj){ //按專業班級查詢 for(int i=0;i<readercount;i++) if(reader[i].getClassno()==bbj) { cout<<i<<"t"; reader[i].dispAReader(); return i; } return -1; } void searchreaderbyzybjj(string bbj) //模糊查詢 { for(int i=0;i<readercount;i++) if(reader[i].getClassno()==bbj) { cout<<i<<"t"; reader[i].dispAReader(); // return i; } // return -1; } void deletereaderbyxuehao(string xxhh){ //按學號刪除讀者 int k=searchreaderbynump(xxhh); if(k>=0) { cout<<"reader to be deleted :"<<endl; reader[k].dispAReader(); reader[k]=reader[readercount-1]; cout<<"deletereaderbyxuehao successed:"<<endl; readercount--; //return bookcount; } else cout<<"deletereader failed. No reader of xuehao="<<xxhh<<endl; } void deletereaderbyxingming(string xxh1h){ //按姓名刪除讀者 int k=searchreaderbynamep(xxh1h); if(k>=0) { cout<<"reader to be deleted :"<<endl; reader[k].dispAReader(); reader[k]=reader[readercount-1]; cout<<"deletereaderbyxingming successed:"<<endl; readercount--; //return bookcount; } else cout<<"deletereader failed. No reader of xingming="<<xxh1h<<endl; } void sortreaderbyxuahao() //按學號排序 { 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; if(k!=i){ Reader t=reader[i];reader[i]=reader[k];reader[k]=t; } } } void sortreaderbyxueyuan() //按學院排序 { 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 changereaderbyxuehao(string old,string news) //修改學號 { int k=searchreaderbynump(old); if(k>=0) { reader[k].setNum(news); cout<<"changereaderbyxuehao successed:"<<endl; reader[k].dispAReader(); } else cout<<"changereader failed. No reader of num="<<old<<endl; } void changereaderbyxingming(string old,string news) //修改姓名 { int k=searchreaderbynamep(old); if(k>=0) { reader[k].setName(news); cout<<"changereaderbyxuehao successed:"<<endl; reader[k].dispAReader(); } else cout<<"changereader failed. No reader of num="<<old<<endl; } void changereaderbyxueyuan(string old,string news) //修改學院 { int k=searchreaderbyzybjp(old); if(k>=0) { reader[k].setCollege(news); cout<<"changereaderbyxuehao successed:"<<endl; reader[k].dispAReader(); } else cout<<"changereader failed. No reader of num="<<old<<endl; } void changereaderbyzybj(string old,string news) //修改專業班級 { int k=searchreaderbyzybjjp(old); if(k>=0) { reader[k].setClassno(news); cout<<"changereaderbyxuehao successed:"<<endl; reader[k].dispAReader(); } else cout<<"changereader failed. No reader of num="<<old<<endl; } friend class ReaderBorrowBook; }; class InBorrowBook{ public: friend class ReaderBorrowBook; BorrowBook *borrowbook;int borrowbookcount; //borrowbook[n],借書總數 void searchborrowbookbyxuehao(string b) { for(int i=0;i<borrowbookcount;i++) if(borrowbook[i].getNum()==b) { cout<<i<<"t"; borrowbook[i].dispBorrowBook(); // return i; } // return -1; } void searchborrowbookbysm(string b) //按書名查詢借閱書 { for(int i=0;i<borrowbookcount;i++) if(borrowbook[i].getTitle()==b) { cout<<i<<"t"; borrowbook[i].dispBorrowBook(); // return i; } // return -1; } void write2BorrowBookfile() //寫入借書檔案 { ofstream ffout( "d:\borrowbook.txt", ios::out ); if ( !ffout ) { cerr << "File could not be open." << endl ; } ffout<<"借閱資訊n"; for(int i=0;i<borrowbookcount;i++) { Date bbb=borrowbook[i].getBorrowdate(); Date ddd=borrowbook[i].getToreturndate(); Date ccc=borrowbook[i].getReturndate(); ffout<<borrowbook[i].getNum()<<'t'<<borrowbook[i].getName()<<'t'<<borrowbook[i].getBookNum()<<'t'<<borrowbook[i].getTitle()<<'t'<<bbb.getYear()<<"/"<<bbb.getMonth()<<"/" <<bbb.getDay()<<'t'<<ddd.getYear()<<"/"<<ddd.getMonth()<<"/" <<ddd.getDay()<<'t'<<ccc.getYear()<<"/"<<ccc.getMonth()<<"/" <<ccc.getDay()<<endl; } } int inborrowbookFile( char * fileName, int delLine) //獲取借閱圖書資訊 {cout<<1<<endl; string num,name,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; } }; class ReaderBorrowBook{ InBook bk; //宣告三個類 InReader rd; InBorrowBook bb; public: void write2file(){ bk.write2Bookfile(); //寫入檔案儲存資訊 rd.write2Readerfile(); bb.write2BorrowBookfile(); } void init(){ //開啟三個檔案 bk.inbookFile( "d:\book.txt", 1); rd.inreaderFile( "d:\reader.txt", 1); bb.inborrowbookFile( "d:\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= cin>>num1>>title0>>author0>>pub0>>pd0>>pm0>>py0>>price0>>howmany0; bk.addbook(num1,title0,author0,pub0,pd0,pm0,py0,price0,howmany0); bk.write2Bookfile(); 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"; cin>>num1>>name0>>college0>>class0; rd.addreader(num1,name0,college0,class0); rd.write2Readerfile(); 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: bk.write2Bookfile(); cout<<"修改成功"<<endl; 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 selectttt,rdpos,bookpos,y,m,d; while(1){ cout<<"圖書歸還:"<<endl; cout<<"1.還書"<<endl; cout<<"0.return"<<endl; cin>>selectttt; cin.get(); if(selectttt==0) {return;} cout<<"return學號:"<<endl; getline(cin,rdnum,'n'); cout<<"return書號:"; getline(cin,booknum,'n'); bookpos=bk.searchbookbynump(booknum); rdpos=rd.searchreaderbynump(rdnum); int k; k=bb.searchbyreaderbook(rdnum,booknum); if(k>=0){ 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[k].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; }} else cout<<"No borrowbook "<<endl; } } void searchreader() { string xuehao ,xingming,zzy,bbj; cout<<"6.讀者資訊查詢:分別按學號、姓名、班級等進行查詢。"<<endl; int selectt; while(1){ cout<<"讀者資訊查詢:"<<endl; cout<<"1.按學號查詢"<<endl; cout<<"2.按姓名查詢"<<endl; cout<<"3. 按學院查詢"<<endl; cout<<"4. 按專業班級查詢"<<endl; cout<<"0. return"<<endl; cin>>selectt; cin.get(); switch(selectt) { case 1: cout<<"學號:"<<endl; getline(cin,xuehao,'n'); cout<<1<<endl; rd.searchreaderbynum(xuehao); break; case 2:cout<<"姓名:"<<endl; getline(cin,xingming,'n'); rd.searchreaderbyname(xingming); break; case 3:cout<<"學院: "<<endl; getline(cin,zzy,'n'); rd.searchreaderbyzybj(zzy); break; case 4:cout<<"專業班級: "<<endl; getline(cin,bbj,'n'); rd.searchreaderbyzybjj(bbj); break; case 0: return; } } } void sortreader() { int selectt1; cout<<"7:讀者資訊排序:按學號、學院等按升序進行排序。"<<endl; cout<<"讀者資訊排序:"<<endl; cout<<"1.按學號排序"<<endl; cout<<"2.按學院排序"<<endl; cout<<"0. return"<<endl; cin>>selectt1; switch(selectt1){ case 1: cout<<"學號:"; rd.sortreaderbyxuahao(); dispReader(); break; case 2: cout<<"學院:"; rd.sortreaderbyxueyuan(); dispReader(); break; case 0:return; } } void editreader() { string xh,xm,xy,bj,newxh,newxm,newxy,newbj; int select2; cout<<"8.學生資訊的修改、刪除:。"<<endl; while(1){ cout<<"學生資訊的修改、刪除:"<<endl; cout<<"1.按學號修改"<<endl; cout<<"2.按學號刪除"<<endl; cout<<"3.按姓名修改"<<endl; cout<<"4.按姓名刪除"<<endl; cout<<"0. return"<<endl; cin>>select2; cin.get(); switch(select2) { case 1:cout<<"要修改學生的學號為:"<<endl; cin>>xh; cout<<"請輸入新學號"<<endl; cin>>newxh; rd.changereaderbyxuehao(xh,newxh); break; case 2:cout<<"要刪除的學生學號為:"<<endl; cin>>xh; rd.deletereaderbyxuehao(xh); break; case 3:cout<<"修改的學生姓名為:"<<endl; cin>>xm; cout<<"請輸入修改後的姓名:"<<endl; cin>>newxm; rd.changereaderbyxingming(xm,newxm); break; case 4:cout<<"要刪除的學生姓名為:"<<endl; cin>>xm; rd.deletereaderbyxingming(xm); break; case 0: rd.write2Readerfile(); cout<<"修改成功"; return; } } } void searchreaderborrowbook() { int bz; string xxh,ssm; while(1) {cout<<"11.圖書借閱查詢:分別按學號、書名、學院等進行查詢。"<<endl; cout<<"1.按學號查詢"<<endl; cout<<"2.按書名查詢"<<endl; cout<<"0.return"<<endl; cin>>bz; switch(bz) { case 1:cout<<"請輸入學號"<<endl; cin>>xxh; bb.searchborrowbookbyxuehao(xxh);break; case 2:cout<<"請輸入書名"<<endl; cin>>ssm;bb.searchborrowbookbysm(ssm);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; }
部分截圖
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援it145.com。
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45