C++課程設(shè)計(jì)(簡(jiǎn)單圖書管理系統(tǒng))_第1頁
C++課程設(shè)計(jì)(簡(jiǎn)單圖書管理系統(tǒng))_第2頁
C++課程設(shè)計(jì)(簡(jiǎn)單圖書管理系統(tǒng))_第3頁
C++課程設(shè)計(jì)(簡(jiǎn)單圖書管理系統(tǒng))_第4頁
C++課程設(shè)計(jì)(簡(jiǎn)單圖書管理系統(tǒng))_第5頁
已閱讀5頁,還剩12頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上課 程 設(shè) 計(jì) 課程名稱 C+課程設(shè)計(jì)題目名稱 圖書管理系統(tǒng) 2016 年 6 月 29 日目錄一設(shè)計(jì)內(nèi)容與要求(1)、設(shè)計(jì)一個(gè)圖書管理系統(tǒng),能夠?qū)崿F(xiàn)用戶信息管理,圖書信息的錄入、查詢、刪除等功能。(2)、實(shí)現(xiàn)用戶管理,系統(tǒng)具有用戶注冊(cè)功能。管理員的賬號(hào)和密碼由系統(tǒng)指定,登錄后可進(jìn)行修改。一般用戶注冊(cè)后才能登錄使用系統(tǒng)。管理員具有錄入、查詢、刪除圖書信息及一般用戶的功能。一般用戶只有圖書查詢功能。 (3)、登錄功能,只有注冊(cè)了的用戶才能進(jìn)入系統(tǒng),沒有注冊(cè)的則有提示信息出現(xiàn)。(4)、圖書管理功能,管理員能夠錄入、查詢、刪除圖書信息。(5)、圖書查詢功能,管理員及一般用戶

2、能夠通過圖書的基本信息,如圖書作者、書名、出版社、出版日期等等,進(jìn)行查詢。提示:上述為基本功能,可參考實(shí)際的系統(tǒng)進(jìn)行擴(kuò)展。二設(shè)計(jì)思路:為了實(shí)現(xiàn)用戶信息以及圖書信息的管理,建立一個(gè)用戶CUser類與圖書信息CBoodata類,其中CUser類應(yīng)該包含用戶賬號(hào)以及密碼,CBookdata類應(yīng)該包含圖書作者,書名,出版社,出版日期。同時(shí)應(yīng)該建立兩個(gè)dat文件,一個(gè)為存儲(chǔ)用戶信息,一個(gè)用來儲(chǔ)存圖書信息。程序主要分為4個(gè)頁面:(1) 登錄頁面,由Cdialog類派生出CMyprojectDlg類,用來處理賬號(hào)注冊(cè)與用戶登錄。(2) 圖書查詢頁面。由Cdialog類派生出CSearch類。包含讀取所有圖書

3、數(shù)據(jù)響應(yīng)函數(shù),以及根據(jù)作者姓名或者書名來查詢圖書響應(yīng)函數(shù)。(3) 管理員圖書管理頁面。由Cdialog類派生出CBookdata類。包含讀取所有圖書響應(yīng)函數(shù),添加圖書響應(yīng)函數(shù),修改圖書響應(yīng)函數(shù),刪除圖書響應(yīng)函數(shù)。(4) 用戶信息管理頁面,由Cdialog類派生出CUserdata類。包含讀取所有用戶信息響應(yīng)函數(shù),刪除用戶響應(yīng)函數(shù)、添加用戶響應(yīng)函數(shù)、修改用戶信息響應(yīng)函數(shù)。因?yàn)楸救四芰τ邢?,而且自己是根?jù)老師給的教程以及結(jié)合書本內(nèi)容來完成課程設(shè)計(jì),于是我第一想到的就是應(yīng)數(shù)組來存儲(chǔ)信息,而不是用鏈表,所以,對(duì)于文件數(shù)據(jù)的刪除與修改,難免會(huì)過于乏力。 三關(guān)鍵模塊實(shí)現(xiàn)及主要代碼(1)自己建立的類1.用戶

4、類:class CUserpublic:int num;char password20;2.圖書信息類:class Book /圖書類public: char author10; /設(shè)置作者姓名char bname20; /設(shè)置圖書書名char pub_name20; /設(shè)置出版社名稱int pub_date; /設(shè)置出版年月;(2)登錄頁面,由Cdialog類派生出CMyprojectDlg類,用來處理賬號(hào)注冊(cè)與用戶登錄。1.用戶注冊(cè)處理響應(yīng)函數(shù):void CMyprojectDlg:OnButton3() /用戶注冊(cè)/ TODO: Add your control notification

5、 handler code here /以下代碼主要還是把這條記錄寫入文件,注意寫入的格式:文件的前四個(gè)字節(jié)是保持用戶記錄數(shù),/后面依次保持用戶記錄注意,寫用戶的每個(gè)信息的順序要與讀取時(shí)的順序一致。 UpdateData(TRUE);CUser user;int n_user=0; /用戶的個(gè)數(shù),管理員默認(rèn)為第一個(gè)。自己輸入為賬號(hào):1111,密碼:0000。int size=0;fstream file("user.dat",ios:in|ios:out); / 建立一個(gè)文件類,關(guān)于其用法,請(qǐng)baidu。file.seekg(ios:beg); /將文件指針指向文件頭。fi

6、le.read(char*)&n_user,sizeof(n_user); /讀取用戶數(shù)。 n_user+=1;file.seekp(ios:beg);file.write(char*)&n_user,sizeof(n_user);/寫學(xué)生記錄個(gè)數(shù)user.num=m_num; /之前定義user.password為string,導(dǎo)致密碼匹配時(shí)有錯(cuò)誤。memcpy(user.password,m_password.GetBuffer(m_password.GetLength(),m_password.GetLength(); / 把類CString對(duì)象的內(nèi)容賦值到字符數(shù)組中us

7、er.passwordm_password.GetLength()='0' /在數(shù)組末尾加結(jié)束符號(hào)/在文件末尾,把新的記錄寫入。file.seekp(4+(n_user-1)*sizeof(CUser),ios:beg); /這里出錯(cuò)file.write(char*)&user.num,sizeof(user.num);file.write(char*)&user.password,sizeof(user.password); file.close();/用消息框提示CString str;str.Format("成功注冊(cè),成為第 %d 個(gè)注冊(cè)用戶,請(qǐng)

8、按確定返回重新登錄.",n_user-1); /因?yàn)榈谝粋€(gè)為管理員,不算為用戶人數(shù)。AfxMessageBox(str);2.用戶登錄處理響應(yīng)函數(shù)。其中包含判斷是管理員,還是普通用戶。void CMyprojectDlg:OnButton2() /用戶登錄/ TODO: Add your control notification handler code here UpdateData(TRUE); CUser m_user100;int i;int size;int n_user=0; /文件中用戶的個(gè)數(shù)/讀取文件中的用戶記錄,注意讀取順序與寫入的順序要一致,文件最開始的4個(gè)字節(jié)是

9、表示記錄個(gè)數(shù)。/根據(jù)記錄個(gè)數(shù),依次讀取用戶記錄 放在成員變量m_st數(shù)組中(已在類體中聲明了) CFile file;file.Open("user.dat",CFile:modeReadWrite);size=GetFileSize(void*)file.m_hFile,NULL); /讀取文件大小,size=0表示是空文件if(size>0)file.SeekToBegin();file.Read(&n_user,sizeof(n_user);if(n_user>0 && n_user<99) /實(shí)驗(yàn)中限定為0100個(gè)用戶記錄f

10、or( i=0;i<n_user;i+) /請(qǐng)注意與寫入數(shù)據(jù)的順序要保持一樣,否則會(huì)讀錯(cuò)數(shù)據(jù)。file.Read(&(m_useri.num),sizeof(m_useri.num);file.Read(&(m_useri.password),sizeof(m_useri.password);file.Close();/if(m_num=1111&&m_password="0000") /管理員進(jìn)入管理員頁面 CAdministrators administrators; administrators.DoModal();CString

11、 str_password;for(i=0;i<n_user;i+) /普通用戶,進(jìn)入圖書查詢頁面str_password=m_useri.password;if(m_useri.num=m_num)if(str_password=m_password) CSearch search;search.DoModal(); else CString str; str.Format("密碼或者賬號(hào)錯(cuò)誤,請(qǐng)重新輸入!"); AfxMessageBox(str); (3)圖書查詢頁面。包含讀取所有圖書數(shù)據(jù),以及根據(jù)作者姓名或者書名來查詢圖書。1.讀取所有圖書響應(yīng)函數(shù)。void

12、CSearch:OnButton5() /顯示出所有圖書/ TODO: Add your control notification handler code hereint i;int size;int n_book=0; /文件book的本數(shù) /讀取文件中的書本記錄,注意讀取順序與寫入的順序要一致,文件最開始的4個(gè)字節(jié)是表示記錄個(gè)數(shù)。/根據(jù)記錄個(gè)數(shù),依次讀取書籍記錄 放在成員變量m_user_book數(shù)組中(已在類體中聲明了) CFile file;file.Open("book.dat",CFile:modeReadWrite);size=GetFileSize(voi

13、d*)file.m_hFile,NULL); /讀取文件大小,size=0表示是空文件if(size>0)file.SeekToBegin();file.Read(&n_book,sizeof(n_book);if(n_book>0 && n_book<99) /實(shí)驗(yàn)中限定為0100個(gè)書本記錄m_num_book=n_book;for( i=0;i<n_book;i+) /請(qǐng)注意與寫入數(shù)據(jù)的順序要保持一樣,否則會(huì)讀錯(cuò)數(shù)據(jù)。file.Read(&(m_user_booki.author),sizeof(m_user_booki.author

14、);file.Read(&(m_user_booki.bname),sizeof(m_user_booki.bname);file.Read(&(m_user_booki.pub_name),sizeof(m_user_booki.pub_name);file.Read(&(m_user_booki.pub_date),sizeof(m_user_booki.pub_date);file.Close();/在列表控件中顯示所有條記錄/插入每列的表頭;m_list.InsertColumn(0,"作者",LVCFMT_LEFT,100,1); m_li

15、st.InsertColumn(1,"書名",LVCFMT_LEFT,100,1);m_list.InsertColumn(2,"出版社",LVCFMT_LEFT,100,1);m_list.InsertColumn(3,"出版日期",LVCFMT_LEFT,100,1);/每一行插入一條書本記錄for(i=0;i<n_book;i+)CString str;str=m_user_booki.author;m_list.InsertItem(i,str); /InsertItem向CListCtr控件申請(qǐng)一行用來存放數(shù)據(jù),同時(shí)寫

16、入一行的頭名稱(即編號(hào)為0列的數(shù)據(jù))str=m_user_booki.bname;m_list.SetItemText(i,1,str);/設(shè)置第i行第1列的的數(shù)據(jù)為書名str=m_user_booki.pub_name;m_list.SetItemText(i,2,str);/設(shè)置第i行第2列的的數(shù)據(jù)為出版社str.Format("%d",m_user_booki.pub_date); /整型變?yōu)樽址?,便于在控件顯示m_list.SetItemText(i,3,str);/設(shè)置第i行第3列的的數(shù)據(jù)為出版日期2.圖書查詢響應(yīng)函數(shù)。void CSearch:OnButton

17、4() /查詢圖書/ TODO: Add your control notification handler code here UpdateData(TRUE);m_list.DeleteAllItems();int num=0; /表示查找結(jié)果的個(gè)數(shù)int i; for(i=0;i<m_num_book;i+) / 注意:m_num_book是類的數(shù)據(jù)成員,相當(dāng)于類中的全局變量,所以這里也可以用。CString str;int ret1=0,ret2=0;str=m_user_booki.author;ret1=str.Find(m_author,0); /ret1>=0, 表

18、示str中包含了m_author的字段str=m_user_booki.bname;ret2=str.Find(m_bname,0); /ret2>=0, 表示str中包含了m_bname的字段if(ret1>=0) /按作者查詢str=m_user_booki.author;m_list.InsertItem(num,str); /InsertItem向CListCtr控件申請(qǐng)一行用來存放數(shù)據(jù),同時(shí)寫入一行的頭名稱(即編號(hào)為0列的數(shù)據(jù))str=m_user_booki.bname;m_list.SetItemText(num,1,str);/設(shè)置第i行第1列的的數(shù)據(jù)為書名str=

19、m_user_booki.pub_name;m_list.SetItemText(num,2,str);/設(shè)置第i行第2列的的數(shù)據(jù)為出版社str.Format("%d",m_user_booki.pub_date); /整型變?yōu)樽址?,便于在控件顯示m_list.SetItemText(num,3,str);/設(shè)置第i行第3列的的數(shù)據(jù)為出版日期num+=1; /結(jié)果+1; (4)管理員圖書管理頁面。包含讀取所有圖書,添加圖書,修改圖書,刪除圖書的功能。1.讀取所有圖書功能實(shí)現(xiàn)與(3)的實(shí)現(xiàn)一樣。2.添加圖書響應(yīng)函數(shù)。void CBookdata:OnButton7() /添

20、加圖書UpdateData(TRUE);Book book;int n_book=0; /書本的個(gè)數(shù)int size=0;fstream file("book.dat",ios:in|ios:out); / 建立一個(gè)文件類,關(guān)于其用法,請(qǐng)baidu。file.seekg(ios:beg); /將文件指針指向文件頭。file.read(char*)&n_book,sizeof(n_book); /讀取書籍?dāng)?shù)。/以下代碼主要還是把這條記錄寫入文件,注意寫入的格式:文件的前四個(gè)字節(jié)是保持書本記錄數(shù),/后面依次保持書本記錄注意,寫學(xué)生的每個(gè)信息的順序要與讀取時(shí)的順序一致。

21、n_book+=1;file.seekp(ios:beg);file.write(char*)&n_book,sizeof(n_book);/寫學(xué)生記錄個(gè)數(shù)memcpy(book.author,m_add_author.GetBuffer(m_add_author.GetLength(),m_add_author.GetLength(); / 把類CString對(duì)象的內(nèi)容賦值到字符數(shù)組中book.authorm_add_author.GetLength()='0' /在數(shù)組末尾加結(jié)束符號(hào)memcpy(book.bname,m_add_bname.GetBuffer(m_

22、add_bname.GetLength(),m_add_bname.GetLength(); / 把類CString對(duì)象的內(nèi)容賦值到字符數(shù)組中book.bnamem_add_bname.GetLength()='0' /在數(shù)組末尾加結(jié)束符號(hào)memcpy(book.pub_name,m_add_pub_name.GetBuffer(m_add_pub_name.GetLength(),m_add_pub_name.GetLength(); / 把類CString對(duì)象的內(nèi)容賦值到字符數(shù)組中book.pub_namem_add_pub_name.GetLength()='0&

23、#39; /在數(shù)組末尾加結(jié)束符號(hào)book.pub_date=m_add_pub_date;/在文件末尾,把新的記錄寫入。file.seekp(4+(n_book-1)*54,ios:beg); file.write(char*)&book.author,sizeof(book.author);file.write(char*)&book.bname,sizeof(book.bname);file.write(char*)&book.pub_name,sizeof(book.pub_name);file.write(char*)&book.pub_date,siz

24、eof(book.pub_date);file.close();/用消息框提示CString str;str.Format("文件中已有 %d 本書籍記錄.",n_book);AfxMessageBox(str);3.修改圖書響應(yīng)函數(shù)。void CBookdata:OnButton5() /修改圖書,必須先讀取圖書才能修改圖書。/ TODO: Add your control notification handler code hereUpdateData(TRUE);m_list.DeleteAllItems();m_list.InsertColumn(0,"作

25、者",LVCFMT_LEFT,100,1); m_list.InsertColumn(1,"書名",LVCFMT_LEFT,100,1);m_list.InsertColumn(2,"出版社",LVCFMT_LEFT,100,1);m_list.InsertColumn(3,"出版日期",LVCFMT_LEFT,100,1); CString str_author,str_bname,str_pub_name,str; /將book類的字符串?dāng)?shù)組賦值為字符串變量,方便比較。 CFile file; / 建立一個(gè)文件類,關(guān)于其

26、用法,請(qǐng)baidu。 file.Open("book.dat",CFile:modeReadWrite); /打開文件file.SeekToBegin(); file.Write(&m_num_book,sizeof(m_num_book);/寫書本記錄本數(shù) for(int i=0;i<m_num_book;i+) str_author=m_booki.author; str_bname=m_booki.bname; str_pub_name=m_booki.pub_name; if(str_author=m_author|str_bname=m_bname|

27、str_pub_name=m_pub_name|m_booki.pub_date=m_pub_date) memcpy(m_booki.author,m_modify_author.GetBuffer(m_modify_author.GetLength(),m_modify_author.GetLength(); / 把類CString對(duì)象的內(nèi)容賦值到字符數(shù)組中 m_booki.authorm_modify_author.GetLength()='0' /在數(shù)組末尾加結(jié)束符號(hào)memcpy(m_booki.bname,m_modify_bname.GetBuffer(m_modi

28、fy_bname.GetLength(),m_modify_bname.GetLength(); / 把類CString對(duì)象的內(nèi)容賦值到字符數(shù)組中 m_booki.bnamem_modify_bname.GetLength()='0' /在數(shù)組末尾加結(jié)束符號(hào)memcpy(m_booki.pub_name,m_modify_pub_name.GetBuffer(m_modify_pub_name.GetLength(),m_modify_pub_name.GetLength(); / 把類CString對(duì)象的內(nèi)容賦值到字符數(shù)組中 m_booki.pub_namem_modify_

29、pub_name.GetLength()='0' /在數(shù)組末尾加結(jié)束符號(hào) m_booki.pub_date=m_modify_pub_date; /以下代碼主要還是把這條記錄寫入文件,注意寫入的格式:文件的前四個(gè)字節(jié)是保持學(xué)生記錄數(shù),/后面依次保持學(xué)生記錄注意,寫學(xué)生的每個(gè)信息的順序要與讀取時(shí)的順序一致。 file.Write(&m_booki.author,sizeof(m_booki.author); file.Write(&m_booki.bname,sizeof(m_booki.bname); file.Write(&m_booki.pub_na

30、me,sizeof(m_booki.pub_name); file.Write(&m_booki.pub_date,sizeof(m_booki.pub_date); /在列表控件中顯示所有條記錄 str=m_booki.author;m_list.InsertItem(i,str); /InsertItem向CListCtr控件申請(qǐng)一行用來存放數(shù)據(jù),同時(shí)寫入一行的頭名稱(即編號(hào)為0列的數(shù)據(jù))str=m_booki.bname;m_list.SetItemText(i,1,str);/設(shè)置第i行第1列的的數(shù)據(jù)為書名str=m_booki.pub_name;m_list.SetItemT

31、ext(i,2,str);/設(shè)置第i行第2列的的數(shù)據(jù)為出版社str.Format("%d",m_booki.pub_date); /整型變?yōu)樽址?,便于在控件顯示m_list.SetItemText(i,3,str);/設(shè)置第i行第3列的的數(shù)據(jù)為出版日期 file.Close(); /用消息框提示str.Format("成功修改書籍記錄.");AfxMessageBox(str);4.刪除圖書響應(yīng)函數(shù)。void CBookdata:OnButton6() /刪除圖書,讀取了圖書數(shù)據(jù)后才能刪除圖書/ TODO: Add your control notif

32、ication handler code hereUpdateData(TRUE);m_list.DeleteAllItems();m_list.InsertColumn(0,"作者",LVCFMT_LEFT,100,1); m_list.InsertColumn(1,"書名",LVCFMT_LEFT,100,1);m_list.InsertColumn(2,"出版社",LVCFMT_LEFT,100,1);m_list.InsertColumn(3,"出版日期",LVCFMT_LEFT,100,1);CStrin

33、g str_author,str_bname,str_pub_name,str; /將book類的字符串?dāng)?shù)組賦值為字符串變量,方便比較。int n_book,n_flag=0; / n_flag為刪除標(biāo)志,1為有元素刪除了 CFile file; / 建立一個(gè)文件類,關(guān)于其用法,請(qǐng)baidu。 file.Open("book.dat",CFile:modeReadWrite); /新建一個(gè)文件并且打開文件file.SeekToBegin(); file.Write(&m_num_book,sizeof(m_num_book);/寫書本記錄本數(shù),先填入本來的書本數(shù)。

34、for(int i=0;i<m_num_book;i+) str_author=m_booki.author; str_bname=m_booki.bname; str_pub_name=m_booki.pub_name; if(str_author=m_del_author|str_bname=m_del_bname|str_pub_name=m_del_pub_name|m_booki.pub_date=m_del_pub_date) n_flag=1; /刪除標(biāo)志置1 i+=1; /第i個(gè)元素為要?jiǎng)h除元素,跳過 /以下代碼主要還是把這條記錄寫入文件,注意寫入的格式:文件的前四個(gè)字節(jié)

35、是保持學(xué)生記錄數(shù),/后面依次保持學(xué)生記錄注意,寫學(xué)生的每個(gè)信息的順序要與讀取時(shí)的順序一致。 file.Write(&m_booki.author,sizeof(m_booki.author); file.Write(&m_booki.bname,sizeof(m_booki.bname); file.Write(&m_booki.pub_name,sizeof(m_booki.pub_name); file.Write(&m_booki.pub_date,sizeof(m_booki.pub_date); if(n_flag=1)n_book=m_num_book-1; /表示刪除了一本書,則將文件的書本數(shù)減1。 file.SeekToBegin(); file.Write(&n_book,sizeof(n_book);/寫書本記錄本數(shù),先填入本來的書本數(shù)。 /用消息框提示 str.Format("成功刪除書籍記錄."); AfxMessageBox(str);else /用消息框提示 str.Format("沒有這一本書的記錄,不能刪除."); AfxMessageBox(str); file.Close();(5)、用戶信息管理頁面,包含讀取所有用戶信息,

溫馨提示

  • 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. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論