c语言课程设计图书管理系统.docx
《c语言课程设计图书管理系统.docx》由会员分享,可在线阅读,更多相关《c语言课程设计图书管理系统.docx(30页珍藏版)》请在冰点文库上搜索。
c语言课程设计图书管理系统
C语言课程设计报告
图书信息管理系统设计
专业计应
班级3
学号
姓名陈金
指导老师杨有安
C语言程序设计
1、题目要求
设计“图书信息管理系统”
要求:
图书信息包括:
登录号,书名,作者名,分类号,出版单位,出版时间,价格等。
使之提供以下功能:
(1)系统以菜单方式工作。
(2)管理员登入系统。
(3)图书信息录入功能。
(图书信息用文件保存)。
(4)图书信息浏览功能。
(5)图书信息(按作者,按书名查)
(6)图书信息查询功能的删除和修改。
2、分析:
根据题目要求,应当把图书信息和管理员信息用结构体形式输入,再定义一个全局变量和文件指针进行整个程序的运行,然后把图书信息送到文件中,所以应该提供一个结构体和文件的输入输出等操作;在程序中需实现图书信息录入,浏览,查询,删除和修改等功能的操作,所以需要建立相应的模块来实现;另外还需提供键盘式选择菜单实现功能,在运行时达到所要目的。
3、总体设计:
一、根据题目要求,可以将系统分为六个模块:
(1)管理员登录系统模块。
(2)菜单选择模块。
(3)图书信息录入功能模块。
(4)图书信息浏览功能。
(5)图书信息查询功能。
(6)图书信息的删除和修改。
二、功能模块图
三、程序结构
head
head
users
structtsxt_list
{
charbookname[20];
charchubanshe[20];
charcbtime[15];
charloginnum[10];
floatprice;
charfenleihao[10];
structtsxt_list*next;
};
/*图书信息结构体*/管理员结构体
structusers
{
CharName[20];
charps[8];
}user,up,mg;
{
……
null
四、程序调用图
账户密码不匹配
匹配
选择错误
四、各个函数所实现的功能
cijimian---------------------次界面菜单
creat_Books_doc-------------增加图书节点
DeleteDoc------------------删除图书
Info_changw------------------改变图书信息
insertDoc----------------------录入图书
loginmanager----------------管理员登陆
print_book_Doc-------------打印图书
save-------------------------保存图书
search-------------------------查询界面
search_author_name--------按作者查
search_book_name---------按书名查
4、详细设计:
头函数名:
#include
#include
#include
#include
#include
/*********图书信息结构体*********/
/***包括登录号,书名,作者名,分类号,出版单位,出版时间,价格等***/
structtsxt_list
{
charbookname[20];
charchubanshe[20];
charcbtime[15];
charloginnum[10];
floatprice;
charfenleihao[10];
structtsxt_list*next;
};
structusers//管理员结构体
{
charName[20];//管理员账户
charps[8];//用户密码
}user,up,mg;//user[N]为文件保存的管理员信息,up为键盘输入管理员信息,mg为管理员结构体变量。
一管理员登入:
/********管理员登录函数**********/
voidloginmanager()
{
FILE*fp=NULL;//定义文件指针
charDataFile[20]="manager.txt";//存储管理员信息的文件名
inti=0,j=1;
charrelogin;//是否重新登录
intsuccess=0;//登录成功的标志
printf("\n---管理员登录---\n");
fp=fopen(DataFile,"r");
if(fp==NULL)//如果当前文件不存在,初始化根账户为gary,密码为313
{
printf("首次使用该系统!
\n");
printf("管理员账户为:
gary密码为:
313\n");
fp=fopen(DataFile,"a");//以追加方式打开文件
strcpy(user.Name,"gary");
strcpy(user.ps,"313");
fwrite(&user,sizeof(user),1,fp);
fclose(fp);
}
else
fclose(fp);
again:
printf("请输入管理员账户:
");
scanf("%s",up.Name);//输入用户名
up.Name[19]='\0';
printf("请输入管理员密码:
");
fflush(stdin);
for(i=0;i<7;i++)//输入密码,以*在屏幕显示
{
up.ps[i]=getch();
up.ps[i+1]='\0';//字符要以'\0'结尾
if(up.ps[i]=='\b')
{
i--;
up.ps[i]='\0';//清除前一个字符
i--;//接收前一个字符
printf("\b");
printf("\b");
continue;
}
if(up.ps[i]=='\r')
{
up.ps[i]='\0';
break;
}
printf("*");
}
fp=fopen(DataFile,"rt");
if(fp==NULL)//打开文件失败时提示
{
printf("\n打开%s失败!
按任意键结束程序\n",DataFile);
perror("Openfilefail");
getchar();
return;
}
if((fp=fopen("manager.txt","r"))==NULL)//打开文件,并判断是否出错
printf("\n出错,请检查文件是否存在,按任意键返回主菜单\n");
else
fread(&mg,sizeof(structusers),1,fp);//从文件中读取信息
fclose(fp);
if(strcmp(mg.Name,up.Name)==0&&strcmp(mg.ps,up.ps)==0)
success=1;
if(success==1)
{
printf("\n登录成功,按任意键进入图书管理系统菜单系统!
\n");
getchar();
zujiemian();
}
else
{
fflush(stdin);//清除输入缓冲区中的字符
printf("\n用户名或密码错误!
重新输入请按y,退出请按n:
\n");
relogin=getchar();
if(relogin=='y'||relogin=='Y')
{
getchar();
gotoagain;
}
else
{cijiemian();
exit(0);
}
}
}
登入流程图
二、来到功能菜单页面
voidsearch_author_name(structtsxt_list*head);
voidsearch_book_name(structtsxt_list*head);
structtsxt_list*Create_Books_Doc()/*新增图书*/
{
structtsxt_list*head;
head=(structtsxt_list*)malloc(sizeof(structtsxt_list));
head->next=NULL;
returnhead;
}
voidsave(structtsxt_list*head)/*保存图书*/
{
structtsxt_list*p;
FILE*fp;
p=head;
fp=fopen("data.txt","w+");
fprintf(fp,"┏━━━┳━━━┳━━━━┳━━━┳━━━━┳━━━━┳━━━┓\n");
fprintf(fp,"┃登录号┃书名┃作者┃出版单位┃出版时间┃分类号┃价格┃\n");
fprintf(fp,"┣━━━╋━━━╋━━━╋━━━━╋━━━━╋━━━━╋━━━┫\n");
while(p->next!
=NULL)
{
p=p->next;
fprintf(fp,"┃%-6.6┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f┃\n",p->loginnum,p->bookname,p->author,p->chubanshe,p->cbtime,p->fenleihao,p->price);
}
fprintf(fp,"┗━━━┻━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━━━┻━━━━━━┛\n");
fclose(fp);
printf("已将图书数据保存\n");
}
voidInsertDoc(structtsxt_list*head)/*添加图书*/
{
structtsxt_list*s,*p;
charflag='Y';
p=head;
while(p->next!
=NULL)
p=p->next;
while(flag=='Y'||flag=='y')
{system("cls");/******************进行清屏*/
s=(structtsxt_list*)malloc(sizeof(structtsxt_list));
printf("--<-<-<------------------图书录入---------------------<-<-<");
printf("\t\t\t\t\t\t\t\t\t\t");
printf("\n请输入图书登陆号(5位):
");
fflush(stdin);
scanf("%s",s->loginnum);
printf("\n请输入图书书名(5位):
");
fflush(stdin);
scanf("%s",s->bookname);
printf("\n请输入图书作者名(4位):
");
fflush(stdin);
scanf("%s",s->author);
printf("\n请输入图书出版社(4位):
");
fflush(stdin);
scanf("%s",s->chubanshe);
printf("\n请输入图书出版时间(9位):
");
fflush(stdin);
scanf("%s",s->cbtime);
printf("\n请输入图书分类号(5位):
");
fflush(stdin);
scanf("%s",s->fenleihao);
printf("\n请输入图书价格(4位):
");
fflush(stdin);
scanf("%f",&s->price);
printf("\n");
p->next=s;
p=s;
s->next=NULL;
printf("━━━━添加成功!
━━━━");
system("cls");/*********************进行清屏*/
printf("\n继续添加?
(Y/N):
");
fflush(stdin);
scanf("%c",&flag);
printf("\n");
if(flag=='N'||flag=='n')
{break;}
elseif(flag=='Y'||flag=='y')
{continue;}
}
save(head);
return;
}
voidsearch(structtsxt_list*head)/*********定义查询函数*/
{
inta;
system("cls");/**************进行清屏*/
printf("\t\t******************************\n");
printf("开始查询\n");
printf("\t\t\t1▄︻┳═一按书名查询\n");
printf("\t\t\t2▄︻┳═一按作者查询\n");
printf("\t\t\t0▄︻┻═┳一退出\n");
printf("\t\t******************************\n");
printf("\t\t请选择你想要的枪毙的方式(*^__^*)嘻嘻:
");
scanf("%d",&a);
switch(a)
{
case1:
search_book_name(head);break;
case2:
search_author_name(head);break;
case0:
system("cls");/******************进行清屏*/
return;
}
}
voidsearch_book_name(structtsxt_list*head)/*按照书名查询*/
{
structtsxt_list*p;
chartemp[20];
p=head;
if(head==NULL||head->next==NULL)
printf("━━━━图书库为空!
━━━━\n");
else
{
printf("请输入您要查找的书名:
");
fflush(stdin);
scanf("%s",temp);
while(p->next!
=NULL)
{
p=p->next;
if(strcmp(p->bookname,temp)==0)
{
printf("\n图书已找到!
\n");
printf("\n");
printf("━━━━━━━━━━━登录号:
%s\t\n",p->loginnum);
printf("━━━━━━━━━━━书名:
%s\t\n",p->bookname);
printf("━━━━━━━━━━━作者名:
%s\t\n",p->author);
printf("━━━━━━━━━━━出版单位:
%s\t\n",p->chubanshe);
printf("━━━━━━━━━━━出版时间:
%s\t\n",p->cbtime);
printf("━━━━━━━━━━━分类号:
%s\t\n",p->fenleihao);
printf("━━━━━━━━━━━价格:
%.2f\t\n",p->price);
}
if(p->next==NULL)
{
printf("\n查询完毕!
!
\n");
}
}
}
return;
}
voidsearch_author_name(structtsxt_list*head)/*按照作者查询*/
{
structtsxt_list*p;
chart[20];
p=head;
if(head==NULL||head->next==NULL)
printf("━━━━图书库为空!
━━━━\n");
else
{
printf("请输入您要查找的作者名:
");
fflush(stdin);
scanf("%s",t);
while(p->next!
=NULL)
{
p=p->next;
if(strcmp(p->author,t)==0)
{
printf("\n*******图书已找到!
*************\n");
printf("\n");
printf("******************登入号:
%s\t\n",p->loginnum);
printf("\n");
printf("******************书名:
%s\t\n",p->bookname);
printf("\n");
printf("******************作者名:
%s\t\n",p->author);
printf("\n");
printf("******************出版单位:
%s\t\n",p->chubanshe);
printf("\n");
printf("******************出版时间:
%s\t\n",p->cbtime);
printf("\n");
printf("******************分类号:
%s\t\n",p->fenleihao);
printf("\n");
printf("******************价格:
%.2f\t\n",p->price);
}
if(p->next==NULL)
printf("查询完毕!
!
");
printf("\n");
printf("\n");
}
}
return;
}
voidPrint_Book_Doc(structtsxt_list*head)/*打印图书信息*/
{
structtsxt_list*p;
if(head==NULL||head->next==NULL)
{
printf("\n━━━━没有图书记录!
━━━━\n\n");
return;
}
p=head;
printf("┏━━━┳━━━━┳━━━┳━━━━┳━━━━┳━━━┳━━┓\n");
printf("┃登录号┃书名┃作者┃出版单位|出版时间┃分类号┃价格┃\n");
printf("┣━━━╋━━━━╋━━━╋━━━━╋━━━━╋━━━╋━━┫\n");
while(p->next!
=NULL)
{
p=p->next;
printf("┃%-6.6s┃%-10.10s┃%-8.8s┃%-9.8s┃%-12.12s┃%-6.5s┃%.2f┃\n",p->loginnum,p->bookname,p->author,p->chubanshe,p->cbtime,p->fenleihao,p->price);
}
printf("┗━━━┻━━━┻━━┻━━━┻━━━━┻━━━┻━━━━┛\n");
printf("\n");
}
voidinfo_change(structtsxt_list*head)/*修改图书信息*/
{
structtsxt_list*p;
intpanduan=0;
chartemp[20];
p=head;
system("cls");/*进行清屏*/
printf("请输入要修改的书名:
");
scanf("%s",temp);
while(p->next!
=NULL)
{
p=p->next;
if(strcmp(p->bookname,temp)==0)
{
printf("\n请输入图书登陆卡号:
");
fflush(stdin);
scanf("%s",p->loginnum);
printf("\n请输入图书书名:
");
fflush(stdin);
scanf("%s",p->bookname);
printf("\n请输入图书作者名:
");
fflush(stdin);
scanf("%s",p->author);
printf("\n请输入图书出版社:
");
fflush(stdin);
scanf("%s",p->chubanshe);
printf("\n请输入图书出版时间:
");
fflush(stdin);
scanf("%s",p->cbtime);
printf("\n请输入图书分类号:
");
fflush(stdin);
scanf("%s",p->fenleihao);
printf("\n请输入图书价格:
");
fflush(stdin);
scanf("%f",&p->price);
printf("\n");
panduan=1;
}
}
if(panduan==0)
{system("cls");/*进行清屏*/
printf("\n━━━━没有图书记录!
━━━━\n\n");
}
return;
}
voidDeleteDoc(structtsxt_list*head)/*删除图书*/
{
structtsxt_list*s,*p;
chartemp[20];
intpanduan;
panduan=0;
p=s=head;
system("cls");/*进行清屏*/
printf("[请输入您要删除的书名]:
");
scanf("%s",temp);
while(p!
=NULL)
{
if(strcmp(p->bookname,temp)==0)
{
panduan++;
break;
}
p=p->next;
}
if(panduan==1)
{
for(;s