C语言图书管理系统实验报告书.docx

上传人:b****5 文档编号:4364046 上传时间:2022-11-30 格式:DOCX 页数:17 大小:49.06KB
下载 相关 举报
C语言图书管理系统实验报告书.docx_第1页
第1页 / 共17页
C语言图书管理系统实验报告书.docx_第2页
第2页 / 共17页
C语言图书管理系统实验报告书.docx_第3页
第3页 / 共17页
C语言图书管理系统实验报告书.docx_第4页
第4页 / 共17页
C语言图书管理系统实验报告书.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

C语言图书管理系统实验报告书.docx

《C语言图书管理系统实验报告书.docx》由会员分享,可在线阅读,更多相关《C语言图书管理系统实验报告书.docx(17页珍藏版)》请在冰豆网上搜索。

C语言图书管理系统实验报告书.docx

C语言图书管理系统实验报告书

高级语言(C语言)课程设计说明书

 

起止日期:

2012年07月2日至2012年07月14日

 

题目

图书管理系统

学生姓名

班级

学号

成绩

 

通信与信息工程学院

说明书撰写提纲

一、课程设计要求

具体要求如下:

1.在程序中需要实现图书信息录入,浏览,查询,删除和修改等功能的操作;

2.程序主菜单如下:

"**************MENU*************",/*菜单的标题行*/

1.图书信息录入/*输入数据*/

2.显示图书信息/*显示所有记录*/

3.图书信息查询/*要求采用书名、作者名进行查询*/

4.图书信息的修改/*实现图书信息的修改和删除*/

5.退出

二、程序的功能设计

这部分主要对程序进行系统设计,给出总体的设计框图。

三、程序的数据结构

这部分主要写本设计所使用的数据结构,比如结构体的定义,单向链表,以及数据输入输出形式(如采用文件的方式读入或保存数据)

四、//自定义枚举类型fi_type,用来表示图书信息

typedefenum_fi_type

{

news=1,//图书信息

}fi_type;

//图书信息结构体

structfi_info

{

charname[11];//书名

charwriter[21];//作者

charshuhao[10];//书号

charfenlei[10];//分类

charchuban[20];//出版社

intchubantime;//出版时间

floatprice;//价格

fi_typetype;

structfi_info*next;//结构体的指针域,用于存放链表的下个结点的地址

五、};

六、程序的函数设计

1.函数的功能描述

structfi_info*head=NULL,*head_=NULL;//将图书信息写成链表,头指针分别为空

intBook_num;//图书信息的统计数

voidmenu();

intReadinfoFromFile();//读入数据

//函数申明

intchuangjian();//创建新的图书信息

voidchazhao();//查找图书

voidshanchu();//删除图书

voidxiugai();//修改图书

voidshow();//查看图书

voidpaixu();//图书排序

voidquit();//退出

2.函数的调用关系

调用关系为主函数调用各功能函数。

七、源程序代码

#include

#include

#include

#include

 

//自定义枚举类型fi_type,用来表示图书信息

typedefenum_fi_type

{

news=1,//图书信息

}fi_type;

//图书信息结构体

structfi_info

{

charname[11];//书名

charwriter[21];//作者

charshuhao[10];//书号

charfenlei[10];//分类

charchuban[20];//出版社

intchubantime;//出版时间

floatprice;//价格

fi_typetype;

structfi_info*next;//结构体的指针域,用于存放链表的下个结点的地址

};

 

structfi_info*head=NULL,*head_=NULL;//将图书信息写成链表,头指针分别为空

intBook_num;//图书信息的统计数

intReadinfoFromFile();//读入数据

//函数申明

intchuangjian();//创建新的图书信息

voidchazhao();//查找图书

voidshanchu();//删除图书

voidxiugai();//修改图书

voidshow();//查看图书

voidpaixu();//图书排序

voidXG();

 

voidmain()

{//inti;

charch='1';

ReadinfoFromFile();

system("cls");

system("cls");

while(ch!

='5')

{printf("\n\n\n\n\n");

printf("\t\t图书管理系统\n\n\n");

printf("\t\t**************MENU*************\n");/*菜单的标题行*/

printf("\t\t1----------------图书信息录入\n");/*输入数据*/

printf("\t\t2----------------显示图书信息\n");/*显示所有记录*/

printf("\t\t3----------------图书信息的查询\n");/*要求采用书名、作者名进行查询*/

printf("\t\t4----------------图书信息的修改\n");/*实现图书信息的修改和删除*/

//printf("\t\t5----------------系统初始化\n");

printf("\t\t5-----------------退出\n");

printf("\n\n");

printf("\t请输入你的选择:

");

scanf("%c",&ch);

switch(ch)

{

case'1':

chuangjian();

break;

case'2':

paixu();

show();

break;

case'3':

chazhao();

break;

case'4':

XG();

break;

default:

break;

}

 

system("cls");

}

system("cls");

printf("\n\n\n\n\n\n\n\n\n\t\t\t\t谢谢使用!

");

getch();

}

 

intReadinfoFromFile()//读入数据

{

FILE*fp=NULL;//文件指针

structfi_info*p=NULL;//结构体指针

inti;

if((fp=fopen("sun.txt","r+"))==NULL)

{

printf("文件不存在!

\n");

fp=fopen("sun.txt","w");//为输出打开一个文件

printf("文件建立成功!

\n");

}

fscanf(fp,"%d",&Book_num);////从文件中分别读入图书信息统计数,以便于下面for循环的条件控制

for(i=0;i

p=(structfi_info*)malloc(sizeof(structfi_info));//P为动作指针,申请内存空间

fscanf(fp,"%s",p->name);

fscanf(fp,"%s",p->writer);

fscanf(fp,"%s",p->shuhao);

fscanf(fp,"%s",&p->fenlei);

fscanf(fp,"%s",p->chuban);

fscanf(fp,"%d",&p->chubantime);

fscanf(fp,"%.2f",&p->price);

fscanf(fp,"%d",&p->type);

if(p->type==1)

{

if(head==NULL){

head=p;

p->next=NULL;

}

else{

p->next=head;

head=p;

}

}

else{

if(head_==NULL){

head_=p;

p->next=NULL;

}

else{

p->next=head_;

head_=p;

}

}

 

fclose(fp);

return0;

}

fclose(fp);

return0;

}

intchuangjian()//创建图书信息

{

structfi_info*p=NULL;

p=(structfi_info*)malloc(sizeof(structfi_info));

printf("请输入书名:

");

scanf("%s",p->name);

printf("请输入作者名:

");

scanf("%s",p->writer);

printf("请输入书号:

");

scanf("%s",p->shuhao);

printf("请输入分类:

");

scanf("%s",&p->fenlei);

printf("请输入出版社:

");

scanf("%s",p->chuban);

printf("请输入出版时间:

");

scanf("%d",&p->chubantime);

printf("请输入价格:

");

scanf("%f",&p->price);

p->type=news;

Book_num+=1;

p->next=head;

head=p;

return0;

}

voidchazhao()//查找图书信息

{

structfi_info*p=NULL;

charname[10],writer[21];

intprice;

intb=1,i;

printf("按书名查找请按1.\n按作者名查找请按2.\n按组合查询请按3.\n");

scanf("%d",&i);

if(i==1)

{

printf("请输入要查找的书名:

");

scanf("%s",name);

for(p=head;p!

=NULL;p=p->next)//一个链表指针p的遍历,直到结尾p==NULL

{

if(strcmp(name,p->name)==0)//字符串的比较函数,若前后相等则等于0

{b=0;//若存在,则b=0

printf("找到要查找的图书信息:

\n");

printf("图书名称%s\n",p->name);

printf("图书作者%s\n",p->writer);

printf("图书书号%s\n",p->shuhao);

printf("图书分类%s\n",p->fenlei);

printf("出版社%s\n",p->chuban);

printf("出版时间%d\n",p->chubantime);

printf("图书价格%.2f\n",p->price);

}

}

if(head==NULL)printf("<查无此书>\n");

if(b)printf("<查找的图书信息不存在!

>\n");//若b=1,则不存在

}

elseif(i==2)

{

printf("请输入要查找的作者名:

");

scanf("%s",writer);

for(p=head;p!

=NULL;p=p->next)//一个链表指针p的遍历,直到结尾p==NULL

{

if(strcmp(writer,p->writer)==0)//字符串的比较函数,若前后相等则等于0

{b=0;//若存在,则b=0

printf("找到要查找的图书信息:

\n");

printf("图书名称%s\n",p->name);

printf("图书作者%s\n",p->writer);

printf("图书书号%s\n",p->shuhao);

printf("图书分类%s\n",p->fenlei);

printf("出版社%s\n",p->chuban);

printf("出版时间%d\n",p->chubantime);

printf("图书价格%.2f\n",p->price);

}

}

if(head==NULL)printf("<查无此书>\n");

if(b)printf("<查找的图书信息不存在!

>\n");//若b=1,则不存在

}

elseif(i==3)

{

printf("请输入要查找的书名价格\n:

");

scanf("%s%d",name,&price);

for(p=head;p!

=NULL;p=p->next)//一个链表指针p的遍历,直到结尾p==NULL

{

if(strcmp(name,p->name)==0&&price==p->price)//字符串的比较函数,若前后相等则等于0

{b=0;//若存在,则b=0

printf("找到要查找的图书信息:

\n");

printf("图书名称%s\n",p->name);

printf("图书作者%s\n",p->writer);

printf("图书书号%s\n",p->shuhao);

printf("图书分类%s\n",p->fenlei);

printf("出版社%s\n",p->chuban);

printf("出版时间%d\n",p->chubantime);

printf("图书价格%.2f\n",p->price);

}

}

if(head==NULL)printf("查无此书\n");

if(b)printf("<查找的图书信息不存在!

>\n");//若b=1,则不存在

}elseprintf("<没有该项功能,请重新选择:

>\n");

system("PAUSE");//暂停

}

voidshanchu()//删除图书信息

{

structfi_info*p=NULL;//定义两个结构体指针

structfi_info*q=NULL;

charname[10];

intb=1;

inta;

printf("请输入要删除的书名:

\n");

scanf("%s",name);

for(p=head,q=head;p!

=NULL;p=p->next)

{

if(strcmp(name,p->name)==0)

{

b=0;

printf("确定删除?

0(是)or1(否)\n");

scanf("%d",&a);

if(a==0)

{

if(p==head)

head=head->next;

else

q->next=p->next;

printf("删除成功!

\n");

}

}

elseq=p;

}

if(b)printf("<提示:

查无此书!

.\n");

system("PAUSE");

}

voidxiugai()//修改图书信息

{

structfi_info*p=NULL;

inta,b=1;

charname[10];

printf("请输入书名:

\n\n");

scanf("%s",name);

for(p=head;p!

=NULL;p=p->next)

{

if(strcmp(p->name,name)==0){

b=0;

printf("图书名称%s\n",p->name);

printf("图书作者%s\n",p->writer);

printf("图书书号%s\n",p->shuhao);

printf("图书分类%s\n",p->fenlei);

printf("出版社%s\n",p->chuban);

printf("出版时间%d\n",p->chubantime);

printf("图书价格%.2f\n",p->price);

printf("<是否确定修改?

0(是)or1(否)>\n");

scanf("%d",&a);

if(a==0){

printf("**********请重新输入信息*********\n");

printf("请输入书名:

");

scanf("%s",p->name);

printf("请输入作者名:

");

scanf("%s",p->writer);

printf("请输入书号:

");

scanf("%s",p->shuhao);

printf("请输入分类:

");

scanf("%s",&p->fenlei);

printf("请输入出版社:

");

scanf("%s",&p->chuban);

printf("请输入出版时间:

");

scanf("%d",&p->chubantime);

printf("请输入价格:

");

scanf("%f",&p->price);

p->type=news;

printf("\n\n<提醒:

信息修改成功!

>\n\n");

}

}

if(b==1)printf("<没有您要修改的信息!

>\n");

}

system("PAUSE");

}

voidshow()//显示图书信息

{

structfi_info*p=NULL;

system("cls");

for(p=head;p!

=NULL;p=p->next)

{

printf("图书名称%s\n",p->name);

printf("图书作者%s\n",p->writer);

printf("图书书号%s\n",p->shuhao);

printf("图书分类%s\n",p->fenlei);

printf("出版社%s\n",p->chuban);

printf("出版时间%d\n",p->chubantime);

printf("图书价格%.2f\n",p->price);

system("PAUSE");

}

}

voidpaixu()//按出版时间排序

{

printf("***********************************按出版时间排序如下***********************************");

structfi_info*a[1000],*p,*p1,*temp;

inti,k,index,n=0;

charb;

p1=head;

for(p=head;p;p=p->next)

n++;

for(i=0;i

a[i]=p1;

p1=p1->next;

}

for(k=0;k

index=k;

for(i=k+1;i

if(a[index]->chubantime>a[i]->chubantime)

index=i;

}

temp=a[index];

a[index]=a[k];

a[k]=temp;

}

for(i=0;i

printf("图书书名%s\n",a[i]->name);

printf("图书作者%s\n",a[i]->writer);

printf("图书书号%s\n",a[i]->shuhao);

printf("图书分类%s\n",a[i]->fenlei);

printf("出版社%s\n",a[i]->chuban);

printf("出版时间%d\n",a[i]->chubantime);

printf("图书价格%.2f\n",a[i]->price);

}

system("PAUSE");

}

voidXG()

{inta=0;

printf("---------图书信息查询-----------\n");

 

printf("\t\t1-----------------修改\n");

printf("\t\t2------------------删除\n");

printf("请输入菜单前的数字:

");

scanf("%d",&a);

switch(a)

{

case1:

xiugai();

break;

case2:

shanchu();

break;

default:

break;

}

}

八、调试及总结

通过这次亲自动手编写C语言图书管理系统,从中收获了很多。

很多学过的知识得以巩固,对链表、数组指针、结构体等知识有了更深一步的了解。

编写的过程中我也借鉴别人设计的一些程序,从中发现了自己的一些不足,在构建框架和编写源程序上面的一些问题。

在源程序编写好后,对源程序的检测花费了我很多时间,这也算是锻炼了我的耐心。

在检测中发现的一些细节上的毛病和粗心这个坏习惯都需要我加以改正。

同时同学对我的帮助也比较大,有些问题很感谢他们对我的帮助。

亲自编写了这个大型程序后,我领悟了“实践出真知”这个道理,体会到了C语言的巨大用处,对C语言有了更浓厚的兴趣。

在今后我也会更加深入的学习C语言,打好稳固的基础,努力掌握这门技术,能够编写出更多更好的程序。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 高中教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1