1、mfc界面的图书管理系统数据结构课程设计图书管理1.设计目的“数据结构”是计算机科学与技术专业一门十分重要的专业技术基础课,计算机科学各领域及有关的应用软件都要使用到各种数据结构。对于从事计算机科学及其应用的科技工作者来说,数据结构与算法是必须透彻地掌握的重要基础。学习数据结构与算法的最终目的是解决实际的应用问题,特别是非数值计算类型的应用问题。课程设计是加强学生实践能力的一个强有力手段。课程设计所安排的题目,在难度和深度方面都大于平时的上机训练,要求同学在完成设计和编写中小型软件的过程中,深化对数据结构与算法课程中基本概念、理论和方法的理解;训练综合运用所学知识处理实际问题的能力,强化面向对
2、象的程序设计理念;使同学的程序设计与调试水平有一个明显的提高。课程设计要求学生在完成程序设计的同时能够撰写比较规的设计报告。严格实施课程设计这一环节,对于学生基本程序设计素养的培养和软件工作者工作作风的训练,将起到显著的促进作用。2.问题描述采用Visual C+编程语言开发工具和MFC,设计并实现图书管理系统。该系统实现了图书管理中的添加,查询,删除,全部查询,退出等功能,以及汇总图书清单,包括对书籍各项信息的汇总。3.需求分析3.1 数据需求图书信息:书名,所属类型,作者,定价,出版日期以及ISBN。3.2 基本功能需求1.汇总图书清单,包括对书籍各项信息的汇总;(各项信息包括书名,所属类
3、型,作者,定价,出版日期以及ISBN。)2.对书籍信息的增、删、查、全部查询等功能。其中删除功能主要依靠第一无二的ISBN,查询功能可以依靠任何一种图书信息(即书名,所属类型,作者,定价,出版日期以及ISBN任意一种)。3.3 非功能性需求用户界面需求:简洁、易用、易懂、友好的用户界面。硬件要求:装有Visual C+6.0的计算机。可靠性需求:保证用户在正常使用本系统时,用户的操作或误操作不会产生数据的丢失。4.概要设计4.1 数据结构用结构struct定义图书信息,用链表实现对图书信息的存储及维护。以文件的形式保存图书信息到硬盘。4.2 系统包含的函数函数原型:void CAddDlg:O
4、nButtonAdd()功能:在链表结尾添加一个结点并将链表信息存入文件“图书管理.txt”函数原型:void CChaxunDlg: OnButtonChaxun()功能: 完成查找用户信息的功能并在编辑框和用户列表中显示出来函数原型:void CDelDlg:OnButton1()功能: 删除链表和用户列表的当前结点函数原型:void CLookDlg:OnButtonDialog()功能: 在编辑框和用户列表中显示全部书籍出来4.3 函数间的关系1.进入程序调用booklist()从硬盘读取数据,并将信息放入链表中。2.用函数CDelDlg:OnButton1()删除链表和用户列表的当前
5、结点。3.可用函数CAddDlg:OnButtonAdd()在链表结尾添加一个结点并在用户列表中显示4.CChaxunDlg: OnButtonChaxun()可实现按不同方式进行图书查询。 5.CLookDlg:OnButtonDialog()在编辑框和用户列表中显示全部书籍出来。按书名按从书类型按作者按出版日期按价格按ISBN图书管理系统添加书目查询书目删除书目查询全部书籍退出系统4.4 系统功能模块图图4-1 系统功能模块图5.详细设计5.1 结构体的详细定义class booklistpublic: CString bookname;/书名 CString congshuname;/丛
6、书种类 CString writer;/作者 CString price;/价格 CString dateyear;/出版年份 CString datemonth;/出版月份 CString ISBN; booklist *next;5.2 系统函数详细介绍增加书籍:void CAddDlg:OnButtonAdd() / TODO: Add your control notification handler code here UpdateData(); extern booklist *head_book; if(m_bookname=|m_congshuname=|m_isbn=|m_m
7、onth=|m_price=|m_writer=|m_year=) MessageBox(请填写完整图书信息); else booklist *p=head_book; booklist *Book=new booklist; Book-next=NULL; Book-bookname=m_bookname; Book-congshuname=m_congshuname; Book-datemonth=m_month; Book-dateyear=m_year; Book-ISBN=m_isbn; Book-price=m_price; Book-writer=m_writer; if(hea
8、d_book=NULL) head_book=Book; else if(p-ISBNm_isbn) Book-next=head_book; head_book=Book; else while(p-next) if(p-next-ISBNm_isbn) Book-next=p-next; p-next=Book; break; p=p-next; if(p-next=NULL) p-next=Book; MessageBox(添加成功); char* pszFileName = .data.txt; CStdioFile myFile; CFileException fileExcepti
9、on; CString str; if(!myFile.Open(pszFileName,CFile:modeCreate|CFile:modeReadWrite,&fileException) MessageBox(打开失败); TRACE(Cannotopenfile%s,error=%un,pszFileName,fileException.m_cause); myFile.SeekToEnd(); myFile.WriteString(书名,丛书名,作者,定价(元),出版年月, ISBN ); myFile.WriteString(n); / extern booklist *head
10、_book; for(p=head_book;p;p=p-next) str.Format(%s,%s,%s,%s,%s.%s,%s,p-bookname,p-congshuname,p-writer,p-price,p-dateyear,p-datemonth,p-ISBN); myFile.SeekToEnd(); myFile.WriteString(str); myFile.WriteString(n); / DestroyWindow(this); CDialog:OnCancel(); BOOL CAddDlg:OnInitDialog() CDialog:OnInitDialog
11、(); / TODO: Add extra initialization here m_isbn=978-7-115-; UpdateData(FALSE); return TRUE; / return TRUE unless you set the focus to /a control / EXCEPTION: OCX Property Pages should /return FALSEvoid CAddDlg:OnCancel2() / TODO: Add your control notification handler code here m_bookname=; m_congsh
12、uname=; m_isbn=; m_month=; m_price=; m_writer=; m_year=; UpdateData(FALSE);查询书籍:BOOL CChaxunDlg:OnInitDialog() CDialog:OnInitDialog(); LONG lStyle; lStyle = GetWindowLong(m_list.m_hWnd, GWL_STYLE);/获/取当前窗口style lStyle &= LVS_TYPEMASK; /清除显示方式位 lStyle |= LVS_REPORT; /设置style SetWindowLong(m_list.m_hW
13、nd, GWL_STYLE, lStyle);/设置/style DWORD dwStyle = m_list.GetExtendedStyle(); dwStyle |= LVS_EX_FULLROWSELECT;/选中某行使整行高亮 /(只适用与report风格的listctrl) dwStyle |= LVS_EX_GRIDLINES;/网格线(只适用与report /风格的listctrl) / dwStyle |= LVS_EX_CHECKBOXES;/item前生成checkbox控件 m_list.SetExtendedStyle(dwStyle); /设置扩展风格 m_list
14、.InsertColumn( 0, 书名, LVCFMT_LEFT, 190 ); /插入列 m_list.InsertColumn( 1, 丛书名, LVCFMT_LEFT, 100 ); m_list.InsertColumn( 2, 作者, LVCFMT_LEFT, 120 ); m_list.InsertColumn( 3, 定价, LVCFMT_LEFT, 50 ); m_list.InsertColumn( 4, 出版日期, LVCFMT_LEFT, 80 ); m_list.InsertColumn( 5, ISBN, LVCFMT_LEFT, 140 ); / TODO: Ad
15、d extra initialization here m_bookname=不限; m_isbn=不限; m_price=不限; m_year=不限; m_month=不限; m_writer=不限; m_congshuname=不限; UpdateData(FALSE); return TRUE; / return TRUE unless you set the focus /to a control / EXCEPTION: OCX Property Pages should return FALSEvoid CChaxunDlg:OnButtonChaxun() / TODO: Add
16、 your control notification handler code here m_list.DeleteAllItems( ); int i=0;/标记查找到的本数 CString str; extern booklist *head_book; / m_ListBox.ResetContent(); UpdateData(); int nRow; for(booklist *p=head_book;p;p=p-next) if(m_bookname=|m_bookname=不限|m_bookname=p-bookname) if(m_congshuname=|m_congshun
17、ame=不限|m_congshuname=p-congshuname) if(m_writer=|m_writer=不限|m_writer=p-writer) if(m_price=|m_price=不限|m_price=p-price) if(m_isbn=|m_isbn=不限|m_isbn=p-ISBN) if(m_year=|m_year=不限|m_year=p-dateyear) if(m_month=|m_month=不限|m_month=p-datemonth|m_month=p-datemonth.Left(2)|(m_month=p-datemonth.Left(1)&p-da
18、temonth.Mid(1,1)=()str.Format(%s,p-bookname);m_ListBox.AddString(str);str.Format(%s.%s,p-dateyear,p-datemonth);nRow = m_list.InsertItem(0, p-bookname);/插入行nRow = m_list.InsertItem(0, sb);/插入行m_list.SetItemText(nRow, 1, p-congshuname);/设置数据m_list.SetItemText(nRow, 2, p-writer);/设置数据m_list.SetItemText
19、(nRow, 3, p-price);/设置数据m_list.SetItemText(nRow, 4, str);/设置数据m_list.SetItemText(nRow, 5, p-ISBN);/设置数据 i+; if(i=0) MessageBox(无此书);删除书籍:void CDelDlg:OnButton1() / TODO: Add your control notification handler code here UpdateData(); int delbooknum=0; CString str; extern booklist *head_book; booklist
20、*q,*p=head_book; /MessageBox(head_book-ISBN); while(p-ISBN=m_isbn) q=p; p=p-next; head_book=p; delbooknum+; delete q; CString str1; if(head_book-next!=NULL) for(booklist *p=head_book;p;p=p-next) if(p-next!=NULL&p-next-ISBN=m_isbn) str1.Format( 书名: %snISBN: %sn,p-next-bookname,p-next-ISBN); p-next=p-
21、next-next; delbooknum+; if(delbooknum=0) MessageBox(无此书,警告); else str.Format(%s %d %s,已删除,delbooknum,本); MessageBox(str1+str); char* pszFileName = .data.txt; CStdioFile myFile; CFileException fileException; if(!myFile.Open(pszFileName,CFile:modeCreate|CFile:modeReadWrite,&fileException) MessageBox(打
22、开失败); TRACE(Can not open file %s,error=%un,pszFileName,fileException.m_cause); myFile.SeekToEnd(); myFile.WriteString(书名,丛书名,作者,定价(元),出版年月, ISBN ); myFile.WriteString(n); / extern booklist *head_book; for(booklist *p=head_book;p;p=p-next) str.Format(%s,%s,%s,%s,%s.%s,%s,p-bookname,p-congshuname,p-wr
23、iter,p-price,p-dateyear,p-datemonth,p-ISBN); myFile.SeekToEnd(); myFile.WriteString(str); myFile.WriteString(n); CDialog:OnCancel(); void CDelDlg:OnCancel() / TODO: Add extra cleanup here CDialog:OnCancel(); BOOL CDelDlg:OnInitDialog() CDialog:OnInitDialog(); / TODO: Add extra initialization here m_
24、isbn=978-7-115-; UpdateData(FALSE); return TRUE; / return TRUE unless you set the focus to a control / EXCEPTION: OCX Property Pages should /return FALSE查询全部书籍:BOOL CLookDlg:OnInitDialog() CDialog:OnInitDialog(); LONG lStyle; lStyle = GetWindowLong(m_list.m_hWnd, GWL_STYLE); /获取当前窗口style lStyle &= L
25、VS_TYPEMASK; /清除显示方式位 lStyle |= LVS_REPORT; /设置style SetWindowLong(m_list.m_hWnd, GWL_STYLE, lStyle); /设置style DWORD dwStyle = m_list.GetExtendedStyle(); dwStyle |= LVS_EX_FULLROWSELECT;/选中某行使整行高/亮(只适用与report风格的listctrl) dwStyle |= LVS_EX_GRIDLINES;/网格线(只适用与/report风格的listctrl) / dwStyle |= LVS_EX_CH
26、ECKBOXES;/item前生成checkbox控件 m_list.SetExtendedStyle(dwStyle); /设置扩展风格 / TODO: Add extra initialization here extern booklist *head_book; int booknum=0; extern length; CString str;m_list.InsertColumn( 0, 书名, LVCFMT_LEFT, 190 );/插入列m_list.InsertColumn( 1, 丛书名, LVCFMT_LEFT, 100 );m_list.InsertColumn( 2,
27、 作者, LVCFMT_LEFT, 120 );m_list.InsertColumn( 3, 定价, LVCFMT_LEFT, 50 );m_list.InsertColumn( 4, 出版日期, LVCFMT_LEFT, 90 );m_list.InsertColumn( 5, ISBN, LVCFMT_LEFT, ); int nRow; for(booklist *q=head_book;q;q=q-next) str.Format(%s.%s,q-dateyear,q-datemonth); nRow = m_list.InsertItem(0, q-bookname);/插入行 /
28、nRow = m_list.InsertItem(0, sb);/插入行 m_list.SetItemText(nRow, 1, q-congshuname);/设置数据 m_list.SetItemText(nRow, 2, q-writer);/设置数据 m_list.SetItemText(nRow, 3, q-price);/设置数据 m_list.SetItemText(nRow, 4, str);/设置数据 m_list.SetItemText(nRow, 5, q-ISBN);/设置数据 booknum+; length=booknum; m_booknum=length; UpdateData(FALSE); return TRUE; / return TRUE unless you set the focus to /a control / EXCEPTION: OCX Property Pages should /return FALSEvoid CLookDlg:OnButton1() / TODO: Add yo
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1