圖書管理系統(含代碼)課程設計報告_第1頁
圖書管理系統(含代碼)課程設計報告_第2頁
圖書管理系統(含代碼)課程設計報告_第3頁
圖書管理系統(含代碼)課程設計報告_第4頁
圖書管理系統(含代碼)課程設計報告_第5頁
已閱讀5頁,還剩34頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

中南大學C++課程設計實踐報告題目:學生信息管理系統專業班級:城地1502指導老師:蔣沖姓名:楊帆學號:0202150222完成時間:2023年7月13日中南大學課程設計報告目錄成員設計內容簡介 1第一章系統概述 11.1功能簡介 21.2設計思路 3第二章第二章系統功能的分析和簡要框圖 32.1主函數42.2初始化文件42.3主菜單52.4查詢72.5借書操作82.6還書操作92.7新增圖書102.8刪除圖書112.9新增讀者122.10讀者信息132.11借閱記錄14第三章調試及運行結果 153.1主菜單 153.2查詢圖書信息 163.3歸還圖書 163.4借閱圖書: 173.5讀者注冊: 183.6圖書信息修改 193.7新書采編入庫 193.8刪除圖書信息 203.9借閱記錄 203.10讀者信息: 21總結 214.1遇到的問題及解決方法 214.2收獲和體會 234.3致謝23第五章源代碼235.1book.h235.2head.h235.3addbook.cpp245.4addreader.cpp265.5brbook.cpp285.6checkbr.cpp325.7checkreader.cpp325.8delbook.cpp335.9findbook.cpp355.10main.cpp425.11mainmenu.cpp425.11return.cpp445.11setfile.cpp46前言圖書管理在生活中運用非常廣泛,因此需要用許多的程序來對它們進行管理。此程序包含了圖書信息的錄入、圖書信息的瀏覽、圖書的查詢和排序、圖書信息的刪除與借書,還書等。通過編譯一個C++語言函數,其中包含一個主函數,多個子函數,主函數調用其余的子函數實現人們能夠簡易、快捷的了解并找到自己所想要的信息的功能。該圖書信息管理系統記錄了圖書館中圖書的圖書號、書名、作者姓名、出版社名、圖書的現存量和總庫存量等書籍數據,同時有對書籍數據以及借閱者的信息進行管理,可以實現對書籍和借閱者進行添加和管理。成員設計內容簡介一、題目及要求題目三:圖書管理系統設計圖書管理信息包括:圖書名稱、圖書編號、單價、作者、存在狀態、借書人姓名、性別、學號等功能描述1、新進圖書根本信息的輸入。2、圖書根本信息的查詢。3、對撤消圖書信息的刪除。4、為借書人辦理注冊。5、辦理借書手續。6、辦理還書手續要求:使用二進制文件方式存儲數據,系統以菜單方式工作二、目的與意義《C++語言課程設計》課程設計是計算機科學與技術專業實踐性環節之一,要求明確課程設計的目的,能根據課程設計的要求,查閱相關文獻,為完成設計準備必要的知識;通過課程設計的綜合訓練可以使學生進一步理解和掌握面向對象程序設計課程的根本知識;掌握面向對象程序設計的思路和方法;根本具有利用面向對象的方法以及C++的編程思想來完成系統設計的能力提高學生用高級語言進行程序設計的能力,重點提高用C語言進行文件操作和繪圖應用的編程技術水平。三、小組成員及小組分工小組成員:楊帆、余華龍、姚翔宇楊帆:brkook()findbook()addbook()delbook()姚翔宇:checkreader(),checkbr(),returnbook();mainmenu(),余華龍:頭文件,main(),setfile(),addreader()四、主要參考文獻《C++語言程序設計〔第三版〕》,鄭莉,清華大學出版社,2004《C++PrimerPlus〔第六版〕》,StephenPrata,人民郵電出版社,2023總體設計功能簡介本軟件是一個簡單的圖書管理系統,軟件為win32控制應用臺程序。完成以下功能:1. 新進圖書根本信息的輸入2. 圖書根本信息的查詢3. 對撤銷圖書信息的刪除4. 為借書人辦理注冊5. 辦理借書手續〔非注冊會員不能借書〕6. 辦理還書手續補充要求:使用二進制文件方式存儲數據系統以菜單方式工作1.2設計思路根本功能:主菜單〔1〕新書采編入庫:新購入一種書,登記到圖書信息中去。如果這種書在帳中已有,那么只將總庫存量增加。〔3〕刪除圖書:某種書已無保存價值,將它從圖書帳目中刪除。〔4〕查詢已在圖書庫中的圖書信息。〔5〕對讀者的信息進行管理:新增,查詢。〔6〕查看借閱記錄查詢圖書信息:a)按書名查詢:如查找所有書名為“數據結構〞的圖書。b)按作者姓名查詢:如查找所有“張三〞編寫的圖書。c)按出版社名查詢:如查找所有“機械工業出版社〞出版的圖書。d)按書籍編號查詢:如查找書籍編號為“978-7-115-27946-0〞的圖書。e) 組合查詢:如查找所有“張三〞編寫的、由“機械工業出版社〞出版的圖書。〔2〕借閱:如果一種書的現存量大于零,那么借出一本,登記借閱者的信息,改變該書的現存量。〔3〕歸還:注銷對借閱者的登記,改變該書的現存量。整個程序的主函數由以下局部構成:頭文件head.h、頭文件book.h、setfile、mainmenu1.頭文件head.h、book.h實現兩個類的定義bookdate圖書類,實現對圖書的描述:圖書根本信息如圖書編號、書名、作者、出版社、單價等;圖書的管理信息如查找圖書及新增圖書、刪除圖書〔通過書的現存量、書的總庫存量描述〕等;Readerdata讀者及圖書管理類,公有繼承圖書類,實現對讀者信息的描敘:讀者的個人資料如借閱者姓名、學號、性別、登陸密碼等;讀者借閱信息如借還圖書本數等;類的數據成員和各函數的功能描述classbookdata//數據成員:charbookisn[50]//圖書編號,bookname[50]//書名writer[50]//作者publishing[50]//出版社;、、、nowstore,//書的現存量allstore,書//的總庫存量price//單價classmanagebook數據成員:reader[50]//借閱者姓名,rdID[50]//學號gender[50]//性別password[50]//登陸密碼num//借還圖書本數各個功能函數:voidsetfile();//初始化數據文件voidmainmenu();//主菜單函數voidfindbook(char*file);//查詢圖書voidbrbook(char*file);//借閱圖書voidreturnbook();//歸還圖書voidreturnf(char*file,readerdatap);voidaddbook();//新書采編入庫voidadd(char*file,bookdatap);voiddelbook();//去除庫存,刪除圖書信息voiddel(char*file,bookdatap);voidaddreader();//新增讀者信息voidcheckreader();//查詢讀者信息voidcheckbr();//查看借閱記錄系統功能的分析和簡要框圖算法分析:在本程序中,頭文件定義了兩個類:classbookdata和classmanagebook,以及各個功能函數。運行程序,首先執行voidsetfile();函數,該函數初始化數據文件,將在exe程序所在文件夾生成所有數據文件,假設該文件夾沒有數據文件,那么生成空的數據文件,數據文件記錄圖書館管理系統的所有數據。然后由voidmainmenu();生成主菜單,主菜單運用switch語句區分指令進行執行功能,其他菜單亦雷同形成。1.查詢圖書信息2.歸還圖書3.圖書信息修改4.讀者注冊5.讀者信息6.借閱記錄0.退出系統分別調用相應函數直接在數據文件上對圖書執行相應功能。在讓借閱者執行查詢,借閱,歸還圖書等操作之前,首先要在初始化的數據文件中添加圖書信息,整個圖書館管理系統大體結構就如上所述,大概可分為圖書信息管理和借閱者信息管理2個模塊,外加一個借閱記錄那么構成圖書館管理系統。本程序對數據文件中數據的編輯是通過將數據文件中的數據編輯后轉移至中轉文件中,再將中轉文件的數據復制回清空了的數據文件當中,即可完成編輯。//主函數包含三個局部:建立數據文件setfile();設置背景為紫色字體亮白色//修改窗口名稱2.2setfile.cpp//初始化數據文件初始化數據文件,將在exe程序所在文件夾生成所有數據文件,假設該文件夾沒有數據文件,那么生成空的數據文件,數據文件記錄圖書館管理系統的所有數據。包括:中轉文件.datReaderdata.datrecord.datbookdata.dat中轉文件1.dat通過將數據文件中的數據編輯后轉移至中轉文件中,再將中轉文件的數據復制回清空了的數據文件當中,完成編輯。2.3mainmenu.cpp//主菜單\2.4findbook.cpp//查詢圖書2.5brbook.cpp//借閱圖書是是是否否否是否繼續查詢圖書本數缺乏,請重新輸入成功借閱本此圖書!!!Nowstore<0?是否請輸入要借閱此圖書的本數是k=Y,k=y或k=N,k=n?i=1?該圖書現存量為0,無法借閱按要求輸入讀者信息nowstore=o?輸出圖書信息確定要借閱此書是否否輸入錯誤請重新輸入work=y或work=Y?結束開始是是是否否否是否繼續查詢圖書本數缺乏,請重新輸入成功借閱本此圖書!!!Nowstore<0?是否請輸入要借閱此圖書的本數是k=Y,k=y或k=N,k=n?i=1?該圖書現存量為0,無法借閱按要求輸入讀者信息nowstore=o?輸出圖書信息確定要借閱此書是否否輸入錯誤請重新輸入work=y或work=Y?結束開始bookname;reader;rdID;num;圖書是否存在?bookname;reader;rdID;num;圖書是否存在?修改借閱記錄圖書信息修改借閱記錄圖書信息是否繼續歸還?mainmenuTrueTrueFalseFalse開始結束booknamebooknamewriterpublishingbookisnnowstore是否添加新書?調用addbookname、writer、publishing相同?TrueFalse開始TrueFalse該書籍已存在輸入新增加的本數并通過中傳文件寫入數據文件直接將新書籍信息寫入數據文件繼續添加新書?FalseTruemainmenu結束2.7addbook.cpp//新書采編入庫2.8delbook.cpp\//去除庫存,刪除圖書信息否輸錯請重試結束否K=1?是K=1或k=2?請根據下面提示輸入所要注銷的書籍的信息是是否是否繼續刪除圖書本數缺乏,請重新輸入請輸入注銷本書是否是W=1或w=0?該圖書信息不存在!!!w=o?否輸入錯誤,請重新輸入!!!開始否輸錯請重試結束否K=1?是K=1或k=2?請根據下面提示輸入所要注銷的書籍的信息是是否是否繼續刪除圖書本數缺乏,請重新輸入請輸入注銷本書是否是W=1或w=0?該圖書信息不存在!!!w=o?否輸入錯誤,請重新輸入!!!開始2.9addreader.cpp//新增讀者信息reader;num;讀者信息是否存在?是否要繼續查詢借閱者信息?mainmenuTreader;num;讀者信息是否存在?是否要繼續查詢借閱者信息?mainmenuTrueTrueFalseFalse以讀的方式翻開數據文件進行查詢readergenderrdIDnum;該借閱者信息不存在!!!num;結束開始2.11checkbr.cpp//查看借閱記錄開始開始findbook借閱記錄:bookisnbooknamereaderrdIDnum結束mainmenu從借閱記錄〔record.dat〕中直接讀取第三章調試及運行結果3.1主菜單3.2查詢圖書信息3.3歸還圖書3.4借閱圖書:3.5讀者注冊:3.6圖書信息修改3.7新書采編入庫3.8刪除圖書信息3.9借閱記錄3.10讀者信息:第四章總結4.1遇到的問題及解決方案問題一:常出現沒有與這些操作符匹配的運算符解決方案是:引入適宜的頭文件,并重新輸入#include內容,編譯器的報錯就會消失。問題二:不懂得對數據文件的操作解決方案:通過對模板程序的模仿,并了解自學fstream常用方法的使用。問題三:程序常因錯誤輸入而崩潰解決方案:運用一些可以容錯的語句來防止多余的輸入,并能返回重新輸入。也可以運用提示詞來減少用戶的非法輸入。問題四:運用二進制文件讀寫解決方案:意我們不再使用插入和提取操作符(譯者注:<<和>>操作符).你可以這么做,但它不會用二進制方式讀寫。你必須使用read()和write()方法讀取和寫入二進制文件.創立一個二進制文件,看下一行。ofstreamfout("file.dat",ios::binary);這會以二進制方式翻開文件,而不是默認的ASCII模式。問題五:文件結構的混亂解決方案:在書寫時保持良好的書寫習慣,并在適當的地方增加注釋4.2收獲和體會雖然在這個學期中,我們已經學習了《C++語言程序設計》這門課,但是知識的運用完全是一個更高水平的要求。這次設計,不僅穩固了我以前所學的知識,還讓我對c++語言有了更深一步的了解,掌握了更多的技巧和技能。在這次課程設計中,我們首先對系統的整體功能進行了構思,然后用結構化分析方法進行分析,將整個系統清楚的劃分為幾個模塊,再根據每個模塊的功能編寫代碼。而且盡可能的將模塊細分,最后在進行函數的調用。我們在函數的編寫過程中,我們不僅用到了for循環、while循環和switch語句,還用到了函數之間的調用〔包括遞歸調用〕。編寫一個完整并且有嚴密邏輯,以及抗非法輸入的程序對于初學者來說還是有相當的挑戰性的,我們在編寫的過程中遇到了重重困難,有些克服了進步了。然而更多地是感受到自己知識儲藏的缺乏與實現按想法之間的矛盾。當然,我們的程序還有很多不完善的地方,比方說,我們試圖以二進制的方式保存文件,最終也是心有余而力缺乏沒有做到,程序在調試中不斷的冒出bug,大晚上面對電腦debug到生無可戀。總之,這次設計程序讓我受益良多,我好好珍惜了這種難得的時機,并且在這個過程中深刻認識到了自己的缺乏。4.3致謝為期半個月的課設總算是結束了,特此向在這短時間指導過我們的老師,還有機房和藹可親的管理老師,一起寫報告的同學,深夜debug的自己,道一聲謝謝。第五章源代碼Book.h#pragmaonce#include<iostream>#include"head.h"#include<vector>#include<fstream>#include<windows.h>usingnamespacestd;voidsetfile();//初始化數據文件voidmainmenu();//主菜單函數voidfindbook(char*file);//查詢圖書voidbrbook(char*file,readerdatap);//借閱圖書voidreturnbook();//歸還圖書voidreturnf(char*file,readerdatap);voidaddbook();//新書采編入庫voidadd(char*file,bookdatap);voiddelbook();//去除庫存,刪除圖書信息voiddel(char*file,bookdatap);voidaddreader();//新增讀者信息voidcheckreader();//查詢讀者信息voidcheckbr();//查看借閱記錄Head.h#pragmaonce#include<iostream>#include<string.h>#include<iomanip>#include<fstream>#include<cstdlib>usingnamespacestd;//圖書類classbookdata{public://構造函數 bookdata(char*bn="bookname\0",char*w="writer\0",char*p="publishing\0",char*bisn="bookisn\0",intn=0,inta=0,intpri=0) { strcpy_s(bookname,bn); strcpy_s(writer,w); strcpy_s(publishing,p); strcpy_s(bookisn,bisn); nowstore=n; allstore=a; price=pri; }bookdata*next;//數據成員charbookisn[50],bookname[50],writer[50],publishing[50];//圖書編號、書名、作者、出版社intnowstore,allstore,price;//書的現存量、書的總庫存量、單價};//讀者及圖書管理類,公有繼承圖書類classreaderdata:publicbookdata{public://構造函數 readerdata(char*rn="reader\0",char*id="0202150222\0",char*ge="男\0",char*p="password\0") { strcpy_s(reader,rn); strcpy_s(rdID,id); strcpy_s(gender,ge); strcpy_s(password,p); }charreader[50],rdID[50],gender[50],password[50];//借閱者姓名、學號、性別、登陸密碼intnum;//借還圖書本數};Addbook.cpp#include"head.h"#include"book.h"voidaddbook(){ system("cls");while(1) {bookdatap;charwork; cout<<"\t確定要添加新書?(y/n):"<<endl;while(1) { cin>>work;if(work=='Y'||work=='y')break;elseif(work=='N'||work=='n'){system("cls");return;}else{cout<<"\n\t輸入錯誤,請重新輸入!!!"<<endl;continue;} } system("cls"); cout<<endl<<"\t\t根據下面提示輸入新書籍的信息"<<endl<<endl<<"\t書名:"; cin>>p.bookname; cout<<"\t"; cin>>p.writer; cout<<"\t出版社:"; cin>>p.publishing; cout<<"\t圖書編號:"; cin>>p.bookisn; cout<<"\t單價:"; cin>>p.price; cout<<"\t數量:"; cin>>p.nowstore; add("bookdata.dat",p); system("cls");charch; cout<<"\t添加成功!!!\n\t是否要繼續添加新書?(y/n):"<<endl;while(1) { cin>>ch;if(ch=='Y'||ch=='y') { system("cls");addbook(); }//函數嵌套調用,判斷是否繼續進行添加操作elseif(ch=='N'||ch=='n'){system("cls");return;}else{cout<<"\n\t輸入錯誤,請重新輸入!!!"<<endl;continue;} } }}voidadd(char*file,bookdatap){intc=0;bookdatat;intj=0;//標記書籍是否已經存在ofstreamf("中轉文件.dat",ios::binary|ios::out);f.close();//清空中轉文件ifstreamfa(file,ios::binary|ios::in); f.open("中轉文件.dat",ios::binary|ios::app);while(fa>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if((!strcmp(t.bookname,p.bookname))&&(!strcmp(t.writer,p.writer))&&(!strcmp(t.publishing,p.publishing))) { cout<<"\t該書籍已存在,請輸入新增加的本數:";//判斷新添加的書籍是否已存在 cin>>c; t.nowstore=t.nowstore+c; t.allstore=t.allstore+c;j=1; }//新添加的書籍已存在,那么直接改動現存量和總庫存量 f<<t.bookname<<"\t"<<t.writer<<"\t"<<t.bookisn<<"\t"<<t.price<<"\t"<<t.publishing<<"\t"<<t.nowstore<<"\t"<<t.allstore<<endl; }if(j){ fa.close();f.close(); f.open(file,ios::binary|ios::out);f.close(); fa.open("中轉文件.dat",ios::binary|ios::in); f.open(file,ios::binary|ios::app);while(fa>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) { f<<t.bookname<<"\t"<<t.writer<<"\t"<<t.bookisn<<"\t"<<t.price<<"\t"<<t.publishing<<"\t"<<t.nowstore<<"\t"<<t.allstore<<endl; } fa.close(); f.close(); }else{ fa.close();f.close(); f.open(file,ios::binary|ios::app);p.allstore=p.nowstore;//新添加的書籍尚未存在,那么直接在數據文件中追加 f<<p.bookname<<"\t"<<p.writer<<"\t"<<p.bookisn<<"\t"<<p.price<<"\t"<<p.publishing<<"\t"<<p.nowstore<<"\t"<<p.allstore<<endl; f.close(); }}Addreader.cpp#include"head.h"#include"book.h"voidaddreader(){ system("cls");readerdatap,t;charwork; cout<<"\t確定要添加新的借閱者信息?(y/n):"<<endl;while(1)//詢問添加新的借閱者與否 { cin>>work;if(work=='Y'||work=='y')break;elseif(work=='N'||work=='n'){system("cls");return;}else{cout<<"\n\t輸入錯誤,請重新輸入!!!"<<endl;continue;} } cout<<endl<<"\t\t根據下面提示輸入新的借閱者的信息"<<endl<<endl<<"\t姓名:"; cin>>p.reader; cout<<"\t學號:"; cin>>p.rdID; cout<<"\t性別:"; cin>>p.gender; cout<<"\t密碼:"; cin>>p.password;inti=0;ifstreamf("readerdata.dat",ios::binary|ios::in);while(f>>t.reader>>t.rdID>>t.gender>>t.password) {if((!strcmp(t.reader,p.reader))&&(!strcmp(t.rdID,p.rdID)))//判斷新添加的借閱者是否已存在 { cout<<"\t該借閱者已記錄在案!!!"<<endl;i=1;break; } } f.close();if(!i){ofstreamf1("readerdata.dat",ios::binary|ios::app); f1<<p.reader<<"\t"<<p.rdID<<"\t"<<p.gender<<"\t"<<p.password<<endl;//新添加的借閱者假設不存在,那么進行添加 f1.close(); } system("cls");charch; cout<<"\t添加成功!!!\n是否要繼續添加新的借閱者信息?(y/n):"<<endl;while(1) {//函數嵌套調用,判斷是否繼續進行添加操作 cin>>ch;if(ch=='Y'||ch=='y') { system("cls");addreader(); }elseif(ch=='N'||ch=='n'){system("cls");mainmenu();}else{cout<<"\n\t輸入錯誤,請重新輸入!!!"<<endl;continue;} }}Brbook.cpp#include"head.h"#include"book.h"voidbrbook(char*file,readerdatap){intw=0;readerdatat,q;p.num=0;ofstreamf("中轉文件.dat",ios::binary|ios::out);f.close();ifstreamfa(file,ios::binary|ios::in); f.open("中轉文件.dat",ios::binary|ios::app);while(fa>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if(!strcmp(t.bookisn,p.bookisn)){ cout<<"\t\t================================================="<<endl; cout<<"\t該書信息:"<<endl; cout<<endl; cout<<"\t書名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t圖書號:"<<t.bookisn<<endl; cout<<"\t圖書單價:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t現存量:"<<t.nowstore<<endl; cout<<"\t總庫存量:"<<t.allstore<<endl;chark;while(1) { cout<<"\n\t確定要借閱此圖書?(y/n):"<<endl; cin>>k;if(k!='Y'&&k!='y'&&k!='N'&&k!='n') { cout<<"\t輸入錯誤,請重新輸入!!!"<<endl;continue; }elsebreak; }if(k=='Y'||k=='y') {while(1) {if(t.nowstore==0) { system("cls");cout<<"\t該圖書現存量為0,無法借閱!!!"<<endl;mainmenu(); } system("cls"); cout<<"\t請輸入你的姓名:"; cin>>p.reader; cout<<"\t請輸入你的學號:"; cin>>p.rdID; cout<<"\t請輸入密碼:"; cin>>p.password;inti=0;ifstreamf("readerdata.dat",ios::binary|ios::in);while(f>>t.reader>>t.rdID>>t.gender>>t.password) {if((!strcmp(t.reader,p.reader))&&(!strcmp(t.rdID,p.rdID))) {if((!strcmp(t.password,p.password))) { i=1;break; }else { i=2;break; } }else { i=0; }//i為判斷標志,該借閱者信息存在為1.不存在為0,密碼輸入錯誤為2,其它輸入容錯 } f.close();if(i==0){ system("cls"); cout<<"\n\t該借閱者信息不存在!!!\n"<<endl; brbook("bookdata.dat",p); }elseif(i==2) { system("cls"); cout<<"\n\t密碼輸入錯誤!!!\n"<<endl;brbook("bookdata.bat,",p); }while(1) { system("cls"); cout<<"\t請輸入要借閱此圖書的本數:"<<endl; cin>>p.num; t.nowstore=t.nowstore-p.num;//成功借閱后,對圖書信息的現存量進行修改if(t.nowstore<0)//判斷圖書本數足夠與否 { t.nowstore=t.nowstore+p.num; cout<<"\t圖書本數缺乏,請重新輸入!!!"<<endl;continue; }else{ w=1;//所借閱圖書現存量足夠時,w=1,否那么w=0inta=0;ofstreamf0("中轉文件1.dat",ios::binary|ios::out);f0.close(); f0.open("中轉文件1.dat",ios::binary|ios::app);ifstreamf("record.dat",ios::binary|ios::in);while(f>>q.bookisn>>q.bookname>>q.reader>>q.rdID>>q.num) {if((!strcmp(t.bookisn,q.bookisn))&& (!strcmp(t.bookname,q.bookname))&&(!strcmp(t.reader,q.reader))&& (!strcmp(t.rdID,q.rdID))&&!strcmp(t.password,q.password)) { q.num=q.num+p.num;a=1; }//a為判斷標志,該借閱記錄存在為1.不存在為0 f0<<q.bookisn<<"\t"<<q.bookname<<"\t"<<q.reader<<"\t"<<q.rdID<<"\t"<<q.num<<endl; } f0.close();f.close();if(a){ofstreamf0("record.dat",ios::binary|ios::out);f0.close(); f0.open("record.dat",ios::binary|ios::app);ifstreamf("中轉文件1.dat",ios::binary|ios::in);//借閱記錄存在時,直接修改借閱本數q.numwhile(f>>q.bookisn>>q.bookname>>q.reader>>q.rdID>>q.num) f0<<q.bookisn<<"\t"<<q.bookname<<"\t"<<q.reader<<"\t"<<q.rdID<<"\t"<<q.num<<endl; f0.close();f.close(); }else{ofstreamf1("record.dat",ios::binary|ios::app);//借閱記錄不存在,直接添加新的記錄 f1<<t.bookisn<<"\t"<<t.bookname<<"\t"<<p.reader<<"\t"<<p.rdID<<"\t"<<p.num<<endl; }break; } }break; } }elseif(k=='N'||k=='n')return; } f<<t.bookname<<"\t"<<t.writer<<"\t"<<t.bookisn<<"\t"<<t.price<<"\t"<<t.publishing<<"\t"<<t.nowstore<<"\t"<<t.allstore<<endl; } fa.close();f.close(); f.open(file,ios::binary|ios::out);f.close(); fa.open("中轉文件.dat",ios::binary|ios::in); f.open(file,ios::binary|ios::app);//成功借閱后,對圖書信息的現存量進行修改while(fa>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) { f<<t.bookname<<"\t"<<t.writer<<"\t"<<t.bookisn<<"\t"<<t.price<<"\t"<<t.publishing<<"\t"<<t.nowstore<<"\t"<<t.allstore<<endl; } fa.close(); f.close();if(!w) { cout<<"\t該圖書不存在或庫存缺乏!!!"<<endl; }else{ cout<<"\t成功借閱"<<p.num<<"本此圖書!!!"<<endl; system("pause");return; }}Checkbr.cpp#include"head.h"voidcheckbr(){ system("cls");readerdatat; cout<<"\n\t借閱記錄:\n"<<endl;ifstreamf("record.dat",ios::binary|ios::in);//直接輸出借閱記錄while(f>>t.bookisn>>t.bookname>>t.reader>>t.rdID>>t.num){ cout<<"\t圖書號:"<<t.bookisn<<"\n"<<"\t書名:"<<t.bookname<<"\n"<<"\t借閱者:"<<t.reader<<"\n"<<"\t學號:"<<t.rdID<<"\n"<<"\t借閱數量:"<<t.num<<endl; cout<<"\t============================================"<<endl; } system("pause"); system("cls");}Checkreader.cpp#include"head.h"#include"book.h"voidcheckreader(){ system("cls");readerdatat,p;inti=0; cout<<"\n\t輸入要查詢的借閱者姓名:\n"<<endl; cin>>p.reader;ifstreamf("readerdata.dat",ios::binary|ios::in);//以讀的方式翻開數據文件進行查詢while(f>>t.reader>>t.rdID>>t.gender>>t.password) {if(!strcmp(t.reader,p.reader)) { cout<<"\n\t借閱者:"<<t.reader<<"\t"<<"性別:"<<t.gender<<"\n"<<"\t學號:"<<t.rdID<<endl; cout<<"\t============================================"<<endl; i=1; } }if(!i)cout<<"\t該借閱者信息不存在!!!"<<endl;charch1; cout<<"\n\t是否要繼續查詢借閱者信息?(y/n):"<<endl;while(1)//函數嵌套調用,判斷是否繼續進行查詢操作 { cin>>ch1;if(ch1=='Y'||ch1=='y') checkreader();elseif(ch1=='N'||ch1=='n'){system("cls");return;}else{cout<<"\n\t輸入錯誤,請重新輸入!!!"<<endl;continue;} }}Delbook.cpp#include"head.h"#include"book.h"voiddelbook(){ system("cls");while(1) {bookdatap; cout<<endl<<"\t請根據下面提示輸入所要注銷的書籍的信息"<<endl<<endl<<"\t圖書編號:"; cin>>p.bookisn;//調用刪除函數對圖書信息進行注銷 del("bookdata.dat",p); }}voiddel(char*file,bookdatap){intc=0,w=0;bookdatat;ofstreamf("中轉文件.dat",ios::binary|ios::out);f.close();ifstreamfa(file,ios::binary|ios::in); f.open("中轉文件.dat",ios::binary|ios::app);while(fa>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if((!strcmp(t.bookisn,p.bookisn))) { cout<<"\t該書信息:"<<endl;w=1; cout<<"\t書名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t圖書號:"<<t.bookisn<<endl; cout<<"\t圖書單價:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t現存量:"<<t.nowstore<<endl; cout<<"\t總庫存量:"<<t.allstore<<endl;chark;while(1) { cout<<"\t請選擇:(1.完全刪除此種圖書)(2.只刪除局部此種圖書)"<<endl; cin>>k;if(k=='1'||k=='2')break;else{cout<<"\t輸入錯誤,請重新輸入!!!"<<endl;continue;} }if(k=='1')continue;elseif(k=='2') {while(1) { cout<<"\t請輸入要注銷的本數:"<<endl; cin>>c; t.nowstore=t.nowstore-c;t.allstore=t.allstore-c;if(t.nowstore<0||t.allstore<0) { t.nowstore=t.nowstore+c;t.allstore=t.allstore+c; cout<<"\t輸入錯誤,請重新輸入!!!"<<endl;continue; }elsebreak; } } } f<<t.bookname<<"\t"<<t.writer<<"\t"<<t.bookisn<<"\t"<<t.price<<"\t"<<t.publishing<<"\t"<<t.nowstore<<"\t"<<t.allstore<<endl; } fa.close();f.close(); f.open(file,ios::binary|ios::out);f.close(); fa.open("中轉文件.dat",ios::binary|ios::in);//通過中轉文件進行對圖書信息刪除 f.open(file,ios::binary|ios::app);while(fa>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) { f<<t.bookname<<"\t"<<t.writer<<"\t"<<t.bookisn<<"\t"<<t.price<<"\t"<<t.publishing<<"\t"<<t.nowstore<<"\t"<<t.allstore<<endl; } fa.close(); f.close();if(!w)cout<<"\n\t該圖書信息不存在!!!\n\t是否要繼續刪除圖書?(y/n):"<<endl;elsecout<<"\n\t成功對該圖書進行了注銷!!!\n\t是否要繼續刪除圖書?(y/n):"<<endl;charch;while(1) {//函數嵌套調用,判斷是否繼續進行添加操作 cin>>ch;if(ch=='Y'||ch=='y') { system("cls");delbook(); }elseif(ch=='N'||ch=='n'){system("cls");mainmenu();}else{cout<<"\n\t輸入錯誤,請重新輸入!!!"<<endl;continue;} }}Findbook.cpp#include"head.h"#include"book.h"voidfindbook(char*file){ system("cls");while(1) { cout<<"\n\t\t============================================"<<endl; cout<<"\t\t\t請選擇查詢方式\t"<<endl; cout<<"\t\t\t1.按書名查詢\t"<<endl; cout<<"\t\t\t2.按作者姓名查詢\t"<<endl; cout<<"\t\t\t3.按出版社名查詢\t"<<endl; cout<<"\t\t\t4.按書名與作者(組合)查詢\t"<<endl; cout<<"\t\t\t5.按書名與出版社(組合)查詢\t"<<endl; cout<<"\t\t\t6.按作者與出版社(組合)查詢\t"<<endl; cout<<"\t\t\t7.按圖書編號查詢\t"<<endl; cout<<"\t\t\t8.輸出所有圖書\t"<<endl; cout<<"\t\t\t0.返回上一層菜單\t"<<endl; cout<<"\t\t============================================"<<endl;//菜單chark; cin>>k;if(k=='0'){system("cls");mainmenu();}if(k!='1'&&k!='2'&&k!='3'&&k!='4'&&k!='5'&&k!='6'&&k!='7'&&k!='8'&&k!='0') { system("cls");cout<<"\t輸入錯誤,請重新輸入!!!"<<endl;continue; }//判斷指令輸入的對錯 bookdatap,t; readerdatah;//已查詢的圖書信息保存inttag=0;if(k=='1') { system("cls"); cout<<"\t請輸入要查詢的書名:";cin>>p.bookname; ifstreamf(file,ios::binary|ios::in); cout<<"\t所查詢的圖書信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if(!strcmp(t.bookname,p.bookname)) { tag=1;//tag為判斷標志,該圖書信息存在為1.不存在為0 cout<<"\t書名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t圖書號:"<<t.bookisn<<endl; cout<<"\t圖書單價:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t現存量:"<<t.nowstore<<endl; cout<<"\t總庫存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0){ cout<<"\n\t該書不存在!!!"<<endl; } }elseif(k=='2') { system("cls"); cout<<"\t請輸入要查詢的書籍作者姓名:";cin>>p.writer; ifstreamf(file,ios::binary|ios::in); cout<<"\t所查詢的圖書信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore){if(!strcmp(t.writer,p.writer)) { tag=1; cout<<"\t書名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t圖書號:"<<t.bookisn<<endl; cout<<"\t圖書單價:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t現存量:"<<t.nowstore<<endl; cout<<"\t總庫存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0){ cout<<"\n\t該書不存在!!!"<<endl; } }elseif(k=='3') { system("cls"); cout<<"\t請輸入要查詢的書籍出版社:";cin>>p.publishing; ifstreamf(file,ios::binary|ios::in); cout<<"\t所查詢的圖書信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if(!strcmp(t.publishing,p.publishing)) { tag=1; cout<<"\t書名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t圖書號:"<<t.bookisn<<endl; cout<<"\t圖書單價:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t現存量:"<<t.nowstore<<endl; cout<<"\t總庫存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0){ cout<<"\n\t該書不存在!!!"<<endl; } }elseif(k=='4'){ system("cls"); cout<<"\t請輸入要查詢的書籍書名:"; cin>>p.bookname; cout<<"\t請輸入要查詢的書籍作者姓名:"; cin>>p.writer; ifstreamf(file,ios::binary|ios::in); cout<<"\t所查詢的圖書信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if(!strcmp(t.bookname,p.bookname)&&!strcmp(t.writer,p.writer)) { tag=1; cout<<"\t書名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t圖書號:"<<t.bookisn<<endl; cout<<"\t圖書單價:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t現存量:"<<t.nowstore<<endl; cout<<"\t總庫存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0){ cout<<"\n\t該書不存在!!!"<<endl; } }elseif(k=='5') { system("cls"); cout<<"\t請輸入要查詢的書籍書名:";cin>>p.bookname; cout<<"\t請輸入要查詢的書籍出版社:";cin>>p.publishing; ifstreamf(file,ios::binary|ios::in); cout<<"\t所查詢的圖書信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if(!strcmp(t.bookname,p.bookname)&&!strcmp(t.publishing,p.publishing)) { tag=1; cout<<"\t書名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t圖書號:"<<t.bookisn<<endl; cout<<"\t圖書單價:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t現存量:"<<t.nowstore<<endl; cout<<"\t總庫存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0) { cout<<"\n\t該書不存在!!!"<<endl; } }elseif(k=='6') { system("cls"); cout<<"\t請輸入要查詢的書籍作者姓名:";cin>>p.writer; cout<<"\t請輸入要查詢的書籍出版社:";cin>>p.publishing; ifstreamf(file,ios::binary|ios::in); cout<<"\t所查詢的圖書信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if(!strcmp(t.writer,p.writer)&&!strcmp(t.publishing,p.publishing)) { tag=1; cout<<"\t書名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t圖書號:"<<t.bookisn<<endl; cout<<"\t圖書單價:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t現存量:"<<t.nowstore<<endl; cout<<"\t總庫存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0)cout<<"\n\t該書不存在!!!"<<endl; }elseif(k=='7') { system("cls"); ifstreamf(file,ios::binary|ios::in); cout<<"\t請輸入要查詢的書籍編號:"<<endl; cin>>p.bookisn;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore){if(!strcmp(t.bookisn,p.bookisn)) { tag=1; cout<<"\t書名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t圖書號:"<<t.bookisn<<endl; cout<<"\t圖書單價:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t現存量:"<<t.nowstore<<endl; cout<<"\t總庫存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0)cout<<"\n該書不存在!!!"<<endl; }elseif(k=='8') { system("cls"); ifstreamf(file,ios::binary|ios::in); cout<<"\t所有圖書信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore){ tag=1; cout<<"\t============================================"<<endl; cout<<"\t\t書名:"<<t.bookname<<endl; cout<<"\t\t"<<t.writer<<endl; cout<<"\t\t圖書號:"<<t.bookisn<<endl; cout<<"\t\t圖書單價:"<<t.price<<endl; cout<<"\t\t出版社:"<<t.publishing<<endl; cout<<"\t\t現存量:"<<t.nowstore<<endl; cout<<"\t\t總庫存量:"<<t.allstore<<endl; cout<<"\t============================================"<<endl; }charch1; cout<<"\n\t是否要繼續查詢圖書?(y/n):"<<endl;while(cin>>ch1) {if(ch1=='Y'||ch1=='y') { system("cls");return; }elseif(ch1=='N'||ch1=='n'){ system("cls");mainmenu(); }else{cout<<"\n\t輸入錯誤,請重新輸入!!!"<<endl;continue

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論