C语言课程设计

您所在的位置:网站首页 c语言课程设计指导书答案 C语言课程设计

C语言课程设计

2023-11-13 18:40| 来源: 网络整理| 查看: 265

实训项目名称:图书管理系统的设计与实现

1.实训目的

开发一个小型的图书管理应用软件,使用该软件可以实现图书信息的登记、浏览、借书、还书、删除和更新等操作。通过该系统的实现可以了解C++连接数据库的原理和技术,掌握VC界面的设计方法。

2.实训要求

(1)选择适当的程序开发语言(建议用C或C++)和数据库系统,完成实训内容。

(2)程序能够正常运行,运算结果正确,满足设计要求。

3.功能描述

该图书管理系统主要包含以下基本功能:

(1)图书基本信息:书号ISBN,书名,出版社,出版日期,作者,价格等。

(2)图书类别信息:可分为科学技术、语言文学、政治经济、历史地理、意识形态和艺术等类别,每个类别有不同的类别代码。

(3)图书出售信息:图书出售日期、出售价格、出售数量。

4.总体设计

 

图书管理系统主要由图书信息、借阅系统和退出系统组成,如图所示。各模块功能如下:

1. 建立菜单界面。进入功能必须打开菜单,然后用户根据菜单选择相应的操作方式,

 

“图书信息”模块包含对图书的操作,增加图书、删除图书以及图书查询、库存浏览等功能,“增加图书”功能中需要依次输入书号、书名、作者、出版社、类别、进库量、单价,“图书查询”功能是按书名、书号、作者、图书分类查询,只要输入其中任一条件即可查询。

2.“图书借阅”模块由借书登记、还书登记和借阅情况模块构成,在“借书登记”中管理员对借出的图书进行登记,需要进行对证号、姓名、归还日期、借书书名进行登记,图书库中

这本书的库存减少,而读者在归还图书的图书库中这本书库存增加。图书管理借阅系统相当于图书管理人员日常的管理工作,即图书借阅、归还等登记工作。

 

3.退出系统。

5. 程序实现及相关描述

struct library { //图书馆结构体 int xcl;//库存 float price;//单价 char name[20],author[20],chuban[20],kind[20],shuhao[20]; struct library *next; }; struct reader { //读者结构体 int zhenghao; char mingzi[20],riqi[20],zname[20]; struct reader *next; }; void mainmenu()//主菜单 { system ("cls"); printf("**************************************************"); printf("\n\n 1.图书信息\n\n"); printf("\n\n 2.借阅系统\n\n"); printf("\n\n 3.退出系统\n\n"); printf("\n\n 请按键选择,回车确定\n"); printf("*************************************************\n"); return ; } void menu1() //显示图书馆信息菜单 { system ("cls"); printf("****************************************************"); printf("\n 1.增加图书\n\n"); printf("\n 2.删除图书\n\n"); printf("\n 3.图书查询\n\n"); printf("\n 4.库存浏览\n\n"); printf("\n 5.返回上一层\n\n"); printf("\n 请按键选择,回车确定\n"); printf("***************************************************\n"); return ; } void menu2() //显示查询菜单 { system ("cls"); printf("请输入书号,书名,作者或类别查询:\n"); printf("类别(科学技术 语言文学 政治经济 历史地理 意识形态 艺术)\n\n"); return ; } void main1()//main1函数 { void tsgxx();//声明 void jieshuxitong();//声明 char choose; mainmenu(); scanf("%c",&choose); switch(choose)//功能函数选择 { case '1': ????tsgxx(); break; case '2': ????jieshuxitong(); break; case '3': ????system ("cls"); getch(); exit(0); system ("cls"); break; } } void tsgxx()//图书馆信息函数 { void tsjinku(); void shanchu(); void chaxunts(); void xianshikucun();//函数声明 char choose; menu1(); scanf("%c",&choose); scanf("%c",&choose); for (;;) switch(choose) { case '1': ????tsjinku(); ????break; case '2': ????shanchu(); ????break; case '3': ????chaxunts(); ????break; case '4': ????xianshikucun(); ????break; case '5': ????main1(); ????break; } } int tjzs()//统计文本个数函数 { FILE *fp; int txcl=0,n; float tprice=0; char tname[20]= {'\0'},tauthor[20]= {'\0'},tchuban[20]= {'\0'},tkind[20]= {'\0'},tshuhao[20]= {'\0'}; fp=fopen("library.txt","r");//打开文件 for (n=0; !feof(fp); n++) //逐个读文件 fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice); n--; fclose(fp);//关闭文件 return (n);//返回个数 } int tjdzzs()//统计文本个数函数 { FILE *fp; int zhenghao=0,n; char mingzi[20]= {'\0'},riqi[20]= {'\0'},zname[20]= {'\0'}; fp=fopen("reader.txt","r");//打开文件 for (n=0; !feof(fp); n++) //逐个读文件 fscanf(fp,"%d%s%s%s ",&zhenghao,&mingzi,&riqi,&zname); fclose(fp);//关闭文件 return (n);//返回个数 } void tsjinku()//图书进库函数 { FILE *fp; int xcl=0,n=0; float price=0; char name[20]= {'\0'},author[20]= {'\0'},kind[20]= {'\0'},chuban[20]= {'\0'},shuhao[20]= {'\0'}; char hitkey; system ("cls"); if ((fp=fopen("library.txt","r"))==NULL)//打开图书馆文件,不存在此文件则新建 { fp=fopen("library.txt","w"); fclose(fp); } fp=fopen("library.txt","a"); printf("\n请按以下格式输入图书信息:\n书号 书名 作者 出版社 类别 进库量 单价"); printf("\n(类别(科学技术 语言文学 政治经济 历史地理 意识形态 艺术))\n"); for (; hitkey!=27;) //循环输入 { if (n!=0) printf("请输入:"); scanf("%s%s%s%s%s%d%f",shuhao,name,author,chuban,kind,&xcl,&price); fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",shuhao,name,author,chuban,kind,xcl,price); printf("继续输入请按回车,结束输入请按Esc\n"); n++; hitkey=getch(); for (; hitkey!=13&&hitkey!=27;) hitkey=getch(); } fclose(fp); printf("\n保存成功,按任意键返回上一层!"); getch(); tsgxx();//返回上一层 } void shanchu()//删除图书信息 { struct library *head=NULL; struct library *p,*p1,*p2; int txcl=0,n=0,j,i; float tprice=0; char tname[20]= {'\0'},tauthor[20]= {'\0'},tchuban[20]= {'\0'},tkind[20]= {'\0'},ttname[20]= {'\0'},tshuhao[20]= {'\0'}; char hitkey; FILE *fp; if ((fp=fopen("library.txt","r"))==NULL)//打开文件 { system ("cls"); printf("\n记录文件不存在!按任意键返回"); getch(); tsgxx(); } else { system ("cls"); printf("\n请输入你要删除的书名:");//输入删除图书书名 scanf("%s",&ttname); printf("\n确认删除请回车,取消请按Esc\n"); hitkey=getch(); for(; hitkey!=13&&hitkey!=27;) hitkey=getch(); if (hitkey==27) tsgxx(); fp=fopen("library.txt","r"); for (j=0; !feof(fp);) //读文件夹信息,统计个数 { j++; fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice); } fclose(fp); fp=fopen("library.txt","r"); for (i=1; inext=p1; p2=p1; p1=(struct library*)malloc(LEN);//新建链表 } strcpy(p1->shuhao,tshuhao);//复制书号 strcpy(p1->name,tname);//复制书名 strcpy(p1->author,tauthor);//复制作者名字 strcpy(p1->chuban,tchuban);//复制出版社 strcpy(p1->kind,tkind);//复制类别 p1->xcl=txcl;//复制个数 p1->price=tprice;//复制单价 } } if (n==0) { head=NULL; } else { p2->next=p1; p1->next=NULL; fclose(fp); } } fp=fopen("library.txt","w");//清空文件 fclose(fp); fp=fopen("library.txt","a");//追加文件 p=head; for (; p!=NULL;) //把链表内容覆盖到文件 { fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",p->shuhao,p->name,p->author,p->chuban,p->kind,p->xcl,p->price); p=p->next; } fclose(fp);//关闭文件 system ("cls"); printf("\n删除成功 \n按任意键返回上一层\n"); getch();//返回上一层 tsgxx(); } void chaxunts()//查询函数 { FILE *fp; char choose; int txcl=0,n=0,k=0,i,l; float tprice=0; char tname[20]= {'\0'},tauthor[20]= {'\0'},chazhao[20]= {'\0'},tchuban[20]= {'\0'}, tshuhao[20]= {'\0'},tkind[20]= {'\0'}; if ((fp=fopen("library.txt","r"))==NULL)//打开文件 { system ("cls"); printf("\n记录文件不存在!按任意键返回"); getch(); tsgxx(); } l=tjzs();//获得文件个数 menu2();//调用菜单函数 scanf("%s",chazhao); system ("cls"); for (i=0; iname,tname);//复制书名 strcpy(p1->author,tauthor);//复制作者 strcpy(p1->chuban,tchuban);//复制出版社 strcpy(p1->kind,tkind);//复制类别 p1->xcl=txcl;//复制现存量 p1->price=tprice;//复制单价 } if (n==0) head=NULL; else { p2->next=p1; p1->next=NULL; fclose(fp); } } } p=head; for (; p!=NULL;) //读链表 { if(!(strcmp(p->name,zname)))//名字相同 { flag=1;//标记取1 loop=p->xcl;//现存量减1 (p->xcl)--; } p=p->next; } if(flag&&(loop>0))//存在借书书名且现存量大于0 { fp=fopen("library.txt","w"); fclose(fp); fp=fopen("library.txt","a"); p=head; for (; p!=NULL;) { fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",p->shuhao,p->name,p->author,p->chuban,p->kind,p->xcl,p->price); p=p->next; } free(p);//把链表内容覆盖文件 fclose(fp); } if(flag&&(loop>0))//存在借书书名且现存量大于0 {{ if ((fp3=fopen("reader.txt","r"))==NULL)//建读者文件夹 { fp3=fopen("reader.txt","w");//打开只读文件 fclose(fp3); } fp3=fopen("reader.txt","a");//以附加的方式打开文件 } {{ if (n!=0) printf("\n请按以下格式输入读者信息:\n 证号 姓名 归还日期 借书书名\n请输入:");//录入读者信息 scanf("%d %s %s %s",&zhenghao,&mingzi[20],&riqi[20],&zname[20]); fprintf(fp3,"\n%-8d%-23s%-18s%-10s\n",zhenghao,&mingzi[20],&riqi[20],&zname[20]); fp=fopen("library.txt","w");//删除图书馆文件信息 fclose(fp); fp=fopen("library.txt","a");//重新追加信息 p=head; for (; p!=NULL;) //把链表内容覆盖图书馆文件 { fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",p->shuhao,p->name,p->author,p->chuban,p->kind,p->xcl,p->price); p=p->next; } fclose(fp); fclose(fp3); printf("成功!按任意键返回\n"); getch();//返回 jieshuxitong();//调用借阅系统 } } jieshuxitong();//调用借阅系统 } else printf("此书已被借完!按任意键返回!");//否则输出此书已被借完 getch();//返回 jieshuxitong();//调用借阅系统 } } void huanshu()//还书函数 { FILE *fp,*fp3; struct reader *head=NULL; struct reader *p,*p1,*p2; struct library *lhead1=NULL; struct library *zp1,*lp1,*lp2; int txcl=0,i; float tprice=0; char?tname[20]= {'\0'},tauthor[20]= {'\0'},tkind[20]= {'\0'}, tchuban[20]= {'\0'},ttname[20]= {'\0'},tshuhao[20]= {'\0'}; int ttzhenghao=0,tzhenghao=0,n=0,k=0,t=0,flag=0; char tmingzi[20]= {'\0'},triqi[20]= {'\0'},tzname[20]= {'\0'},ttzname[20]= {'\0'}; char hitkey=0; system ("cls"); { if ((fp=fopen("reader.txt","r"))==NULL)//不存在读者文件,则输出不能还书 { system ("cls"); printf("\n 不存在借书者!按任意键退出!"); getch(); exit (0); } else {{ printf("\n请输入读者证号和书名:\n请输入:"); scanf("%d %s",&ttzhenghao,ttzname);//输入还书证号和书名 k=tjdzzs();//获取读者文件夹信息个数 for (i=0; izhenghao=tzhenghao;//复制证号 strcpy(p1->mingzi,tmingzi);//复制读者名字 strcpy(p1->riqi,triqi);//复制日期 strcpy(p1->zname,tzname);//复制书名 } } if (n==0) head=NULL; else { p2->next=p1; p1->next=NULL; fclose(fp); } fp=fopen("reader.txt","w");//清空读者文件 fclose(fp); fp=fopen("reader.txt","a");//追加信息 p=head; for (; p!=NULL;) //把链表内容覆盖读者文件 { fprintf(fp,"\n%-8d%-23s%-18s%-10s\n",p->zhenghao,p->mingzi,p->riqi,p->zname); p=p->next; } free(p); fclose(fp); } } } } if(flag)//标记为1,即还书时 {{ { printf("确认还书请按回车!"); for (; hitkey!=13&&hitkey!=27;) hitkey=getch(); if (hitkey==13) printf("成功!按任意键返回!"); n=0; flag=0; fp3=fopen("library.txt","r");//打开图书馆文件 k=tjzs();//获取图书馆文件个数 for (i=0; inext=lp1; lp2=lp1; lp1=(struct library*)malloc(LEN);//新建链表 } strcpy(lp1->shuhao,tshuhao);//复制书号 strcpy(lp1->name,tname);//复制书名 strcpy(lp1->author,tauthor);//复制作者 strcpy(lp1->chuban,tchuban);//复制出版社 strcpy(lp1->kind,tkind);//复制类别 lp1->xcl=txcl; //复制现存量 lp1->price=tprice;//复制单价 } if (n==0) { lhead1=NULL; } else { lp2->next=lp1; lp1->next=NULL; fclose(fp3); } } } zp1=lhead1; for (; zp1!=NULL;) { if(!(strcmp(zp1->name,ttzname)))//寻找书名相同 ++(zp1->xcl);//现存量加1 zp1=zp1->next; } fp3=fopen("library.txt","w");//清空图书馆文件 fclose(fp); fp3=fopen("library.txt","a");//追加信息 zp1=lhead1; for (; zp1!=NULL;) //把链表内容覆盖图书馆文件 { fprintf(fp3,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n", ????????zp1->shuhao,zp1->name,zp1->author,zp1->chuban,zp1->kind,zp1->xcl,zp1->price); zp1=zp1->next; } fclose(fp3); getch();//返回 jieshuxitong();//调用借阅系统 } else printf("不存在此信息!按任意键返回!"); getch();//返回 jieshuxitong();//调用借阅系统 } void duzheyilang()//显示借书情况函数 { FILE *fp; int zhenghao=0,xcl=0,n=0,i=0,j=0; char mingzi[20]= {'\0'},riqi[20]= {'\0'},zname[20]= {'\0'}; if ((fp=fopen("reader.txt","r"))==NULL)//打开读者文件夹 { system ("cls"); printf("\n记录文件不存在!"); } n=tjdzzs(); if (n==0) { system ("cls"); printf("\n无任何记录!"); } fp=fopen("reader.txt","r"); system ("cls"); printf("\n证号\t读者姓名\t\t还书日期\t书名\n"); for (i=0; i


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3