




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、#include#include#include#include/using namespace std;const int Maxb=10000; /最多的圖書const int Maxr=100; /最多的讀者const int Maxbor=5; /每位讀者最多借五本書/-class Book /圖書類 int tag; /刪除標(biāo)記 1:已刪 0:未刪 int no; /圖書編號(hào) char name20; /書名 char author10; /作者名 char no210; /輸入分類號(hào) char dan20; /輸入出版單位 char time20; /出版時(shí)間 int price;
2、 /價(jià)格 int onshelf; /是否在架1:在架0:已借public: Book() char *getname()return name; /獲取書名 int getno()return no; /獲取圖書編號(hào) int gettag()return tag; /獲取刪除標(biāo)記 char *getauthor()return author; /獲取作者名 char *getno2()return no2; /獲取分類號(hào) char *getdan()return dan; /獲取出版單位 char *gettime()return time; /獲取出版時(shí)間 int getprice()re
3、turn price; /獲取圖書價(jià)格 void setname(char na)strcpy(name,na); /設(shè)置書名 void setauthor(char au)strcpy(author,au); /設(shè)置作者名 void setno2(char n)strcpy(no2,n); /設(shè)置分類號(hào) void setdan(char d)strcpy(dan,d); /設(shè)置出版單位 void settime(char t)strcpy(time,t); /設(shè)置出版時(shí)間void setprice(int p)price=p; void delbook()tag=1; /刪除圖書 1:已刪
4、0:未刪 void addbook(int n,char*na,char*au,char*n2,char*da,char*ti,int pr)/增加圖書 tag=0; no=n; price=pr; strcpy(name,na); strcpy(author,au); strcpy(no2,n2); strcpy(dan,da); strcpy(time,ti); onshelf=1; int borrowbook() /借書操作 if(onshelf=1) onshelf=0; return 1; return 0; void retbook()onshelf=1; /還書操作 void
5、disp() /輸出圖書 coutsetw(10)nosetw(10)namesetw(10)setw(10) authorsetw(10)no2setw(10)dansetw(10)time setw(10)price; if(onshelf=1)coutsetw(10)在架; else coutsetw(10)已借出endl; ;/-class BDatabase /圖書庫類 int top; /圖書數(shù)量記錄指針 Book bookMaxb; /圖書記錄public: BDatabase() /構(gòu)造函數(shù),將book.txt讀到book中 Book b; top=-1; fstream fi
6、le(book.txt,ios:in); while(1) file.read(char*)&b,sizeof(b); if(!file)break; top+; booktop=b; file.close(); void clear()top=-1; /全刪 int addbook(int n,char*na,char*au,char*n2,char*da,char*ti,int pr)/增加圖書 Book *p=query(n);/調(diào)用函數(shù) if(p=NULL) top+; booktop.addbook(n,na,au,n2,da,ti,pr); return 1; return 0;
7、Book *query(int bookid) /查找圖書 for(int i=0;i=top;i+) if(booki.getno()=bookid&booki.gettag()=0) return &booki; return NULL; Book *query2(int bookid,char *name)/按書名查找圖書 for(int i=0;i=top;i+) if(strcmp(booki.getname(),name)=0) bookid=booki.getno(); return &booki; return NULL; Book *query3(int bookid,cha
8、r *author) /按作者查找圖書 for(int i=0;i=top;i+) if(strcmp(booki.getauthor(),author)=0) bookid=booki.getno(); return &booki; return NULL; void bookdata(); /圖書庫維護(hù) void disp() /輸出圖書 coutsetw(10)圖書編號(hào)setw(10)圖書名字 setw(10)圖書作者setw(10)圖書分類 setw(10)出版單位setw(10)出版時(shí)間 setw(10)價(jià)格setw(10)借還信息endl; for(int i=0;i=top;i+
9、) if(booki.gettag()=0) booki.disp(); BDatabase() /析構(gòu)函數(shù),將book寫入book.txt文件中 fstream file(book.txt,ios:out); for(int i=0;i=top;i+) if(booki.gettag()=0) file.write(char*)&booki,sizeof(booki); file.close(); ;void BDatabase:bookdata() int bookid; /圖書編號(hào)char bname40; /圖書名char bauthor10; /圖書作者char bno220; /圖
10、書分類char bdan20; /出版單位char btime20; /出版時(shí)間int bprice; /圖書價(jià)格Book *b; int choice=1;int choice2=1;int choice3=1; while(choice!=0) coutttt圖書信息維護(hù)n; coutttt1.添加信息n; coutttt2.修改信息n; coutttt3.刪除信息n; coutttt4.信息查詢n; coutttt5.顯示信息n; coutttt6.全部刪除n; coutttt0.退出圖書信息維護(hù)n; coutchoice; switch(choice) case 1: cout添加圖書
11、操作:n; coutbookid; coutbname; coutbauthor; coutbno2; coutbdan; coutbtime; coutbprice; addbook(bookid,bname,bauthor,bno2,bdan,btime,bprice); cout圖書編號(hào)bookid添加成功n; break; case 2: cout修改圖書信息操作:n; coutbookid; b=query(bookid); if(b=NULL) cout圖書不存在,無法修改n; break; coutchoice2; switch(choice2) case 1: coutbnam
12、e; b-setname(bname); cout修改書名成功n; break; case 2: coutbauthor; b-setauthor(bauthor); cout修改作者名成功n; break; case 3: coutbno2; b-setno2(bno2); cout修改分類成功n; break; case 4: coutbdan; b-setdan(bdan); cout修改出版單位成功n; break; case 5: coutbtime; b-settime(btime); cout修改出版時(shí)間成功n; break; case 6: coutbprice; b-setprice(bprice); cout修改圖書價(jià)格成功n; break; break; case 3: cout刪除圖書操作:n; coutbookid; b=query(bookid); if(b=NULL)coutdelbook(); cout刪除圖書成功n; break; case 4: cout圖書信息查詢操作:n; cout1.按圖書編號(hào)查詢 2.按圖書作者查詢 3.按圖書名字查詢n; coutchoice3; switch(choice3) case 1: coutbookid; b=query(bookid); if(b=NULL)coutdisp(); break
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- Module7 Unit2 Pandas love bamboo(教學(xué)設(shè)計(jì))-2024-2025學(xué)年外研版(三起)英語六年級(jí)上冊(cè)
- 桂林航天工業(yè)學(xué)院《機(jī)械設(shè)計(jì)基礎(chǔ)2》2023-2024學(xué)年第二學(xué)期期末試卷
- 武夷學(xué)院《辦公軟件操作實(shí)訓(xùn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 上海財(cái)經(jīng)大學(xué)《情報(bào)檢索3》2023-2024學(xué)年第二學(xué)期期末試卷
- 大理護(hù)理職業(yè)學(xué)院《新媒體發(fā)展前沿》2023-2024學(xué)年第二學(xué)期期末試卷
- 黑龍江科技大學(xué)《計(jì)量經(jīng)濟(jì)學(xué)B》2023-2024學(xué)年第二學(xué)期期末試卷
- 常熟理工學(xué)院《臨床流行病學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 荊州學(xué)院《西方法律思想史》2023-2024學(xué)年第二學(xué)期期末試卷
- 武漢東湖學(xué)院《嵌入式系統(tǒng)技術(shù)及應(yīng)用》2023-2024學(xué)年第二學(xué)期期末試卷
- 牡丹江大學(xué)《P路由與交換技術(shù)》2023-2024學(xué)年第二學(xué)期期末試卷
- 水利站工作計(jì)劃
- 五年級(jí)下冊(cè)音樂課程綱要
- 食材配送、包裝、運(yùn)輸、驗(yàn)收、售后服務(wù)方案應(yīng)急預(yù)案
- 萬千教育學(xué)前讀懂兒童的思維:支持自主游戲中的圖式探索
- 產(chǎn)品外觀檢驗(yàn)標(biāo)準(zhǔn)通用
- 中石化YC分公司易捷便利店市場(chǎng)營(yíng)銷策略研究
- 醫(yī)院護(hù)理培訓(xùn)課件:《病區(qū)環(huán)境管理查房》
- 《小羊和蝴蝶》繪本故事
- 鋼筋工理論考試題庫及答案
- 大數(shù)據(jù)技術(shù)基礎(chǔ)及應(yīng)用教程(Linux+Hadoop+Spark) 習(xí)題答案
- 高等數(shù)學(xué)(新標(biāo)準(zhǔn)教材)高職PPT完整全套教學(xué)課件
評(píng)論
0/150
提交評(píng)論