C++个人书籍管理系统的设计与实现Word文档格式.docx
- 文档编号:21120281
- 上传时间:2023-01-27
- 格式:DOCX
- 页数:23
- 大小:90KB
C++个人书籍管理系统的设计与实现Word文档格式.docx
《C++个人书籍管理系统的设计与实现Word文档格式.docx》由会员分享,可在线阅读,更多相关《C++个人书籍管理系统的设计与实现Word文档格式.docx(23页珍藏版)》请在冰豆网上搜索。
virtual~DATE();
DATE&
operator=(DATE&
);
//重载时间等于运算符
intoperator<
(DATE&
//重载时间小于运算符
intoperator==(DATE&
//重载时间等于判断运算符
private:
intyear,month,day;
};
----------------------------------------------------------------------------------------------------------
classBook
Book(intt,char*n,char*a,floatp,inty,intm,intd);
Book(){};
virtual~Book();
intf_new();
//新建书籍信息
intf_save();
//保存书籍信息
intf_open();
//打开书籍信息
intdisplay();
//显示书籍信息
inte_delete();
//删除书籍信息
inte_update();
//修改书籍信息
intshowInfo();
//显示个别书籍信息
intsort();
//排序书籍信息
Book&
operator=(Book&
//重载等于运算符
inttype;
//书籍类型
charname[MAX];
//书籍名称
charauthor[MAX];
//作者
floatprice;
//书籍价格
DATEdate;
//购买日期
2、定义数组Bookbooks[200]使用流提取、流插入方式进行数据读取和存储。
3、在排序函数intsort()中使用冒泡算法排序:
for(i=0;
i<
num-1;
i++)
{
for(j=i+1;
books[i].date<
books[j].date||books[i].date==books[j].date;
j++)
{
ex=books[i];
books[i]=books[j];
books[j]=ex;
}
}
四、程序流程图
程序整体的功能模块如下所示:
各个功能模块的含义如下:
1、“主函数”模块main()
此模块循环显示第一级操作命令菜单,接收键盘输入的命令,检查命令是否合法,若合法则调用相应下层函数。
命令菜单中包含“退出系统”命令,当接收到该命令时立即终止整个程序的运行。
2、“新建”模块f_new():
此模块清空books数组;
进入输入状态,接收键盘输入的全部数据保存在books数组中,按“购买日期”顺序输入记录。
3、“打开”模块f_open():
此模块清除books数组中原有数据,从A盘上已经存在的数据文件(books.dat)中读入全部数据到books数组中,并将全部数据按读入顺序显示在屏幕上。
4、“保存”模块f_save():
此模块将books数组中全部有效数据保存到A盘books.dat文件中。
5、“删除”模块e_delele():
此模块接收从键盘输入的一条记录的“购买日期”和“书名”,在books数组中查找,如找到则从books数组中删除该记录,否则显示“未找到”。
6、“更新”模块e_update():
此模块接收键盘输入的一条记录的“购买日期”和“书名”,在books数组中查找,如找到则显示该记录的原数据并提示键盘输入新数据用以替换原有数据,如未找到则显示“未找到”。
7、“显示”模块display():
此模块显示类别名称和编号,提示用户输入类别编号,显示books数组中指定类别的书籍记录,或显示全部书籍记录。
8、“排序”模块sort():
此模块对books数组中所有记录按“购买时间”排序。
五、源程序清单
文件DATE.h:
类DATE的定义
//DATE.h:
interfacefortheDATEclass.
//
//////////////////////////////////////////////////////////////////////
#if!
defined(AFX_DATE_H__6B5CFDD0_60A3_4347_853E_4B83FD47F383__INCLUDED_)
#defineAFX_DATE_H__6B5CFDD0_60A3_4347_853E_4B83FD47F383__INCLUDED_
#if_MSC_VER>
1000
#pragmaonce
#endif//_MSC_VER>
#include<
iostream.h>
#endif//!
----------------------------------------------------------------------------------------------------------------------
DATE.cpp:
类DATE的实现
//DATE.cpp:
implementationoftheDATEclass.
#include"
DATE.h"
//Construction/Destruction
DATE:
:
DATE(inty,intm,intd)
year=y;
month=m;
day=d;
}
~DATE()
ostream&
t)
if(t.month>
0&
&
t.month<
13&
t.day>
t.day<
31)
output<
t.year<
"
-"
endl;
else
日期错误!
returnoutput;
istream&
input>
t.year>
t.month>
t.day;
returninput;
intDATE:
operator<
(DATE&
operand)
if(year<
operand.year)return1;
elseif(year>
operand.year)return0;
elseif(month<
operand.month)return1;
elseif(month>
operand.month)return0;
elseif(day<
operand.day)return1;
elsereturn0;
operator==(DATE&
right)
if(year==right.year&
month==right.month&
day==right.day)
return1;
return0;
DATE&
operator=(DATE&
year=right.year;
month=right.month;
day=right.day;
return*this;
Book.h:
类Book的定义
//Book.h:
interfacefortheBookclass.
defined(AFX_BOOK_H__0541F24F_979E_4421_8EAC_FD9__INCLUDED_)
#defineAFX_BOOK_H__0541F24F_979E_4421_8EAC_FD9__INCLUDED_
string.h>
fstream.h"
stdio.h>
stdlib.h>
conio.h>
#defineMAX12
Book.cpp:
类Book的实现
//Book.cpp:
implementationoftheBookclass.
Book.h"
Bookbooks[200];
//定义200条数组
intnum=0;
//初始化书籍信息条数零
Book:
Book(intt,char*n,char*a,floatp,inty,intm,intd)
date(y,m,d)
type=t;
price=p;
strncpy(name,n,MAX);
name[MAX]=0;
strncpy(author,a,MAX);
author[MAX]=0;
~Book()
intBook:
f_new()
system("
cls"
cout<
1--学习"
"
2--名著"
3--小说"
4--散文"
endl<
请输入书籍类型:
;
cin>
books[num].type;
printf("
请输入书名:
gets(books[num].name);
请输入作者名:
gets(books[num].author);
请输入书籍价格:
books[num].price;
请输入购买日期:
books[num].date;
num++;
return1;
f_save()
ofstreamoutFile("
book.dat"
ios:
out|ios:
binary);
if(!
outFile)
cerr<
Openfileorcreatefileerror."
{
outFile<
num;
outFile.write((char*)&
books,sizeof(books));
outFile.close();
cout<
保存成功!
}
f_open()
inti;
ifstreaminfile("
in|ios:
infile>
if(num==0)
cout<
没有记录!
请先输入书籍信息。
system("
pause"
return1;
for(i=0;
infile.read((char*)&
books[i],sizeof(books));
infile.close();
sort()
charc;
\n---------------------------排序书籍信息-----------------------\n\n"
1----------------按时间顺序排序"
2----------------按书名顺序排序"
c=getch();
switch(c)
case'
1'
system("
inti,j;
Bookex;
printf("
\n-------------------------时间顺序排序书籍信息---------------------\n\n"
books[i].showInfo();
display()
char*s;
char*s1="
学习"
char*s2="
名著"
char*s3="
小说"
char*s4="
散文"
for(;
)
1.显示全部书籍信息。
2.显示指定类别书籍信息。
0.返回上一层。
c=getch();
if(c=='
0'
break;
switch(c)
case'
\n---------------------------全部书籍列表-----------------------\n\n"
类型书名作者价格日期\n\n"
for(inti=0;
switch(books[i].type)
case1:
s=newchar[strlen(s1)+1];
strcpy(s,s1);
break;
case2:
s=newchar[strlen(s2)+1];
strcpy(s,s2);
case3:
s=newchar[strlen(s3)+1];
strcpy(s,s3);
case4:
s=newchar[strlen(s4)+1];
strcpy(s,s4);
printf("
%-15s%-18s%-15s%-15.1f"
s,name,author,price);
cout<
date<
2'
\n---------------------------书籍分类列表-----------------------\n\n"
for(inti=0;
if(books[i].type==1)
cout<
学习类:
books[i].name<
books[i].author<
for(i=0;
if(books[i].type==2)
名著类:
if(books[i].type==3)
小说类:
if(books[i].type==4)
散文类:
showInfo()
switch(type)
case1:
s=newchar[strlen(s1)+1];
strcpy(s,s1);
break;
case2:
s=newchar[strlen(s2)+1];
strcpy(s,s2);
break;
case3:
s=newchar[strlen(s3)+1];
case4:
s=newchar[strlen(s4)+1];
strcpy(s,s4);
e_delete()
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 个人 书籍 管理 系统 设计 实现
![提示](https://static.bdocx.com/images/bang_tan.gif)