




已閱讀5頁,還剩24頁未讀, 繼續(xù)免費閱讀
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
實驗四 圖書管理系統(tǒng)姓名:任子龍 學號: 班級:一.需求分析(1)問題描述有一個小型書庫保管了大量圖書,關于圖書有大量信息需要處理,這些信息包括圖書的分類、書名、作者名、購買日期、價格等?,F(xiàn)要求編寫一個程序以便于對圖書的管理。(2)基本要求:a建立圖書信息。b提供查找功能,按照多種關鍵字查找需要的書籍。例如按書名查找,輸入書名后,將顯示出該圖書的所有信息,或顯示指定信息。c提供排序功能,按照多種關鍵字對所有的書籍進行排序,例如按出版日期進行排序。d提供維護功能,可以對圖書信息進行添加、修改、刪除等功能。(3)數(shù)據(jù)結構與算法分析將每一本書看作是一個基本單元。由于涉及添加、修改操作,這里使用了鏈表作為數(shù)據(jù)存儲結構;同時,考慮到排序功能,嘗試使用雙向鏈表。其中,每本書作為一個結點,數(shù)據(jù)域包含char型變量,指針域含有左右指針left和right。二.概要設計1.抽象數(shù)據(jù)類型的定義為實現(xiàn)上述功能,程序中使用了雙向鏈表,只需要定義一種數(shù)據(jù)類型:typedef struct book char number10;char title20;char author10; char date15;char price10;struct book *right; struct book *left;BK; 注意結點的指針域有l(wèi)eft和right兩個。2. 本程序包含兩個模塊(1) 主程序模塊主函數(shù)只包含了 Menu_select()函數(shù)。目的是進入主菜單界面,進行功能選擇;直到輸入操作碼0,退出系統(tǒng);(2) 雙向鏈表單元模塊實現(xiàn)書籍信息的鏈式存儲的抽象數(shù)據(jù)類型。各函數(shù)之間的調用關系:三.詳細設計1.結點類型typedef struct book char number10;char title20;char author10; char date15;char price10;struct book *right; struct book *left;BK;2. 子函數(shù)(1) 功能菜單調用函數(shù) Menu_select() 使用戶進入主菜單界面,進行功能選擇;先進入無限循環(huán),輸入操作碼進行系統(tǒng)管理工作,直到輸入操作碼0,退出系統(tǒng);(2) 各種功能函數(shù)Initialize()/初始化圖書系統(tǒng)信息;Insert()/添加新的圖書信息;Sort()/對圖書進行排序,本程序可以實現(xiàn)按“圖書編號”、“出版日期”、 “圖書價格”多種關鍵字進行排序; Search()/實現(xiàn)對圖書的查找功能,本程序可以實現(xiàn)按“圖書編號”、“出版日期”、“圖書價格”多種關鍵字進行查找;deletebook()/刪除無效的圖書信息;Print_book()/打印全部圖書信息。3. 主函數(shù)Main函數(shù)十分的簡單,目的只有一個,就是進入功能選擇菜單。 int main() /*主函數(shù)*/ Menu_select(); /*調用主菜單*/ 4. 調試分析1. 為了提高程序的健壯性,在menu函數(shù)中,考慮如果操作碼超出0-7的范圍,進行錯誤提示。2. 剛開始使用的其實是單鏈表,然后很快就發(fā)現(xiàn)了問題,當編寫排序部分的時候,很難再進行下去;考慮過使用順序表,但是由于有刪除、添加的操作,所以也放棄了順序表,最終決定用雙向鏈表,這還是第一次。過程中發(fā)現(xiàn)雙向鏈表用起來很方便!3. 排序函數(shù)sort()中為了保證程序的正確性,使用了自己較為熟練的冒泡排序法,沒有考慮時間復雜度。4. 在編寫的過程中也更加熟悉了switch函數(shù),free函數(shù),goto函數(shù)(當然盡量少用),還有學會了清屏,system(“cls”);五.測試結果1.建立圖書信息及添加功能2. 查找功能A.按編號查找:B.按日期查找3. 修改功能4. 刪除功能5. 排序功能為了說明問題,這里又添加了兩本書簡愛、余罪測試只提供按編號和日期排序A.按編號排序:B.按出版日期排序6、 附錄#include#include #include #includetypedef struct book char number10;char title20;char author10; char date15;char price10;struct book *right; struct book *left;BK; BK *h_book; /*函數(shù)申明*/ void Start() system(cls); printf(nnntt*n); printf(nnnttt歡迎使用圖書管理系統(tǒng)n); printf(nnntt*n); printf(nnntt 按任意鍵進入系統(tǒng).);getch(); system(cls); void Insert()/*新書入庫*/ BK *p,*p0,*p1; p=p1=h_book; printf(n新書入庫模塊.n); printf(n請輸入新書信息.n包括書號、書名、數(shù)量.n); p0=(BK *)malloc(sizeof(BK); printf(圖書編號:); scanf(%s,p0-number); while(strcmp(p0-number,p1-number)!=0&p1-right!=NULL) p1=p1-right; if(strcmp(p0-number,p1-number)=0) /*此處分兩種情況,若圖書編號存在,則直接進庫,只須輸入書的數(shù)量*/ printf(n此編號圖書已存在!直接入庫!n); else/*若不存在,則需要輸入其他的信息,然后在進行插入操作*/ printf(圖書名稱:); scanf(%s,p0-title); printf(圖書作者:); scanf(%s,p0-author); printf(圖書出版日期:); scanf(%s,p0-date); printf(圖書價格:); scanf(%s,p0-price); while(p-right) p=p-right; if(h_book=NULL) h_book=p0; /*此處分兩種情況,鏈表中沒有 數(shù)據(jù),head直接指向p0處*/ else p-right=p0; p0-left=p; /*此處分兩種情況,鏈表中有數(shù)據(jù), 鏈表中最后元素的right指向p0處*/ p0-right=NULL; printf(n新書入庫完畢!按任意鍵繼續(xù)下一步操作.n); getch(); system(cls); void Print_book() /*打印所有圖書信息*/ BK *p; p=h_book; printf(n圖書信息如下:nn); printf(圖書編號t圖書名稱t圖書作者t出版日期t價格n); while(p!=NULL) printf(%stt%stt%stt%st%sn,p-number,p-title,p-author,p-date,p-price); p=p-right; printf(n圖書信息打印完畢!按任意鍵繼續(xù)下一步操作.); getch(); system(cls); void Initialize() /*初始化*/ BK *p0; printf(n圖書初始化開始,請輸入圖書信息.n包括編號.書名.數(shù)量.n); p0=(BK*)malloc(sizeof(BK); h_book=p0; printf(n請輸入圖書信息:n); printf(圖書編號:); /*輸入圖書編號(唯一)*/ scanf(%s,p0-number); printf(圖書名稱:); /*輸入圖書名稱*/ scanf(%s,p0-title); printf(圖書作者:); /*輸入圖書作者*/ scanf(%s,p0-author); printf(圖書出版日期:); /*輸入圖書出版日期*/ scanf(%s,p0-date); printf(圖書價格:); /*輸入圖書價格*/ scanf(%s,p0-price); p0-right=NULL; p0-left=NULL; printf(n圖書信息初始化完畢!按任意鍵繼續(xù)下一步操作.n); getch(); system(cls); void Sort() /*按多種關鍵詞排序*/ BK *p,*front,*rear,*temp; int x; printf(n圖書排序開始.n); printf(n請選擇關鍵字進行排序:n); printf(1.書籍編號n2.出版日期n3.書籍價格n); scanf(%d,&x); temp=(BK*)malloc(sizeof(BK); front=h_book; p=front; while(p-right) p=p-right; rear=p; while(1) if(front=rear) break; else p=front; while(1) if(p=rear) break; switch(x) case 1: if(strcmp(p-number,p-right-number)0) /按編號冒泡排序 strcpy(temp-number,p-number);strcpy(p-number,p-right-number);strcpy(p-right-number,temp-number); strcpy(temp-author,p-author);strcpy(p-author,p-right-author);strcpy(p-right-author,temp-author); strcpy(temp-title, p-title); strcpy(p-title, p-right-title); strcpy(p-right-title, temp-title); strcpy(temp-date, p-date); strcpy(p-date, p-right-date); strcpy(p-right-date, temp-date); strcpy(temp-price, p-price); strcpy(p-price, p-right-price); strcpy(p-right-price, temp-price); break;case 2: if(strcmp(p-date,p-right-date)0) /按出版日期冒泡排序 strcpy(temp-number,p-number);strcpy(p-number,p-right-number);strcpy(p-right-number,temp-number); strcpy(temp-author,p-author);strcpy(p-author,p-right-author);strcpy(p-right-author,temp-author); strcpy(temp-title, p-title); strcpy(p-title, p-right-title); strcpy(p-right-title, temp-title); strcpy(temp-date, p-date); strcpy(p-date, p-right-date); strcpy(p-right-date, temp-date); strcpy(temp-price, p-price); strcpy(p-price, p-right-price); strcpy(p-right-price, temp-price); break;case 3:if(strcmp(p-price,p-right-price)0) /按價格冒泡排序 strcpy(temp-number,p-number);strcpy(p-number,p-right-number);strcpy(p-right-number,temp-number); strcpy(temp-author,p-author);strcpy(p-author,p-right-author);strcpy(p-right-author,temp-author); strcpy(temp-title, p-title); strcpy(p-title, p-right-title); strcpy(p-right-title, temp-title); strcpy(temp-date, p-date); strcpy(p-date, p-right-date); strcpy(p-right-date, temp-date); strcpy(temp-price, p-price); strcpy(p-price, p-right-price); strcpy(p-right-price, temp-price); break;default:break; p=p-right; rear=rear-left; printf(n排序完畢!按任意鍵繼續(xù)下一步操作.n); getch(); system(cls); void Search() /*多種關鍵詞查找*/ BK *p; int x; char t20=0; printf(n圖書查找開始.n); k:printf(n請選擇關鍵字進行查找:n); printf(1.書籍編號n2.出版日期n3.書籍價格n); scanf(%d,&x); printf(n請輸入關鍵字:n); scanf(%s,t); p=h_book; while(p) switch(x) case 1:if(strcmp(p-number,t)=0) printf(%st%st%st%st%sn,p-number,p-title,p-author,p-date,p-price); break; case 2:if(strcmp(p-date,t)=0) printf(%st%st%st%st%sn,p-number,p-title,p-author,p-date,p-price); break; case 3:if(strcmp(p-price,t)=0) printf(%st%st%st%st%sn,p-number,p-title,p-author,p-date,p-price); break; default:printf(請輸入正確的操作碼!n);goto k; p=p-right; printf(n查找完畢!按任意鍵繼續(xù)下一步操作.n); getch(); system(cls); void deletebook()/*刪除圖書信息*/ BK *p; char t20=0; printf(n請輸入需要刪除書籍編號:); scanf(%s,t); p=h_book-right; while(p) if(strcmp(p-number,t)=0) p-left-right=p-right; p-right-left=p-left; free(p);break;p=p-right; printf(n刪除完畢!按任意鍵繼續(xù)下一步操作.n); getch(); system(cls); void Modify()/*修改圖書信息 */ BK *p; char t20=0; printf(n請輸入需要修改書籍編號:); scanf(%s,t); p=h_book; while(p) if(strcmp(p-number,t)=0) break; p=p-right; /*指針p指向需要修改的結點*/ printf(n請重新輸入圖書信息:n); printf(圖書編號:); /*輸入圖書編號(唯一)*/ scanf(%s,p-number); printf(圖書名稱:); /*輸入圖書名稱*/ scanf(%s,p-title); printf(圖書作者:); /*輸入圖書作者*/ scanf(%s,p-author); printf(圖書出版日期:); /*輸入圖書出版日期*/ scanf(%d,&p-date); printf(圖書價格:); /*輸入圖書價格*/ scanf(%d,&p-price); printf(n修改完畢!按任意鍵繼續(xù)下一步操作.n); getch(
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 公司新年企劃活動方案
- 公司百人旅游活動方案
- 公司組織小活動方案
- 公司百家講壇活動方案
- 公司游泳買票活動方案
- 公司組織抓鵝活動方案
- 公司組織集體洗腳活動方案
- 公司盛大年會策劃方案
- 公司活動現(xiàn)場策劃方案
- 公司活動策劃方案
- 電子政務內網機房運維管理制度
- 2025年北京高考化學試卷試題真題及答案詳解(精校打印版)
- 陜西省專業(yè)技術人員繼續(xù)教育2025公需課《黨的二十屆三中全會精神解讀與高質量發(fā)展》20學時題庫及答案
- 福利院財務管理制度
- 2025至2030中國汽車輪轂行業(yè)發(fā)展分析及發(fā)展前景與投資報告
- 郴州市2025年中考第二次模考歷史試卷
- 2025年供應鏈管理考試題及答案
- 2024-2025學年人教版數(shù)學五年級下學期期末試卷(含答案)
- 食用薄荷介紹課件
- 美容院和干洗店合同協(xié)議
- 2025年北師大版七年級數(shù)學下冊專項訓練:整式的混合運算與化簡求值(原卷版+解析)
評論
0/150
提交評論