河南工业大学 C语言图书管理系统 课程报告

  • 格式:doc
  • 大小:511.75 KB
  • 文档页数:27

课程报告课程名称:程序设计实践专业班级:信息类*****学生姓名:*********学号: ************任课教师:徐振强学期:2010-2011学年第二学期课程报告任务书成绩评定教师:目录任务书 (2)目录 (3)1.需求分析 (4)2.概要设计 (4)3.详细设计 (5)3.1结构体设计 (5)3.2主函数 (6)3.3功能函数 (10)(1)函数:输出单本的图书数据 (10)(2)函数:接收单本的图书数据,返回指针 (10)(3)函数:得到图书的数据,并放入到链表中 (11)(4)函数:从文件读入图书记录 (11)(5)函数:把数据写入到文件 (12)(6)函数:按价格和出版时间排序排序 (13)(7)函数:统计图书的总本数 (15)(8)函数:修改图书的信息 (15)(9)函数:删除数据 (16)(10)函数:将图书的数据插入到顺序排放的链表中, (19)(11)函数:查询图书的信息,并把图书的数据输出 (19)(12)函数:用链表给图书排序 (21)(13)函数:输出链表中的图书信息 (21)4.调试分析 (22)5.测试结果 (22)6.课程心得总结 (27)1 需求分析1.图书信息录入功能(图书信息用文件保存)--输入。

2.图书信息浏览功能--输出。

3.查询功能、排序功能:①按编号查询或排序②按书名查询③按作者查询④按出版社查询⑤按价格排序⑥按出版时间排序4.统计图书数目。

5. 图书信息的插入、删除和修改。

6.使用密码登录本系统,且可以修改密码。

7. 本界面具有友善、直观、易操作等特点,本系统采用数字输入选择操作。

2 概要设计结构图如下所示:3 详细设计3.1结构体设计#define N 15 //编号位数#define M 15 //名称字节数#define K 15 //作者字节数#define F 15 //出版社字节数#define O 2 //数组位数建立图书结构体struct book{char num[N];char name[M];char zuozhe[K];char chuban[F];int jc[O];struct book *next;}3.2主函数int i=0,g=0;char mm[7],ch;char c[7];FILE *fp;int n,x=1,k=0;float a[O]={0};struct book *head=NULL;if((fp=fopen("密码(勿删,否则出错!).txt","r"))==NULL){printf("密码载入失败!\n");exit(0);}for(i=0;i<6;i++){mm[i]=fgetc(fp);}mm[6]='\0';printf("请输入密码\n");loop: for (i=0;i<6;i++){c[i]=getch();printf("*");}c[6]='\0';printf("\n");if (strcmp( mm, c)!=0){g++;if(g==3){printf("非法用户\n");getch();exit(0);}elseprintf("密码错误请重新输入\n");goto loop;}if (strcmp(mm,c)==0) {printf("************************************************\n");printf("★登录成功★\n");printf("★欢迎使用图书管理系统★\n");printf("★作者:隋忠翔班级:1006 学号:201046830603★\n");printf("★按回车键继续★\n");printf("************************************************\n");getchar();while(x){system("cls");printf("★ **************************************************************★\n"); printf("★★★图书管理系统★★★\n"); printf("★★★ 0---退出系统 1---录入图书数据★★★\n"); printf("★★★★ 2---保存文件 3---输出图书信息★★★★\n"); printf("★★★★★ 4---排序 5---统计图书数目★★★★★\n"); printf("★★★★ 6---查询图书信息 7---插入图书数据★★★★\n"); printf("★★★ 8---删除图书数据 9---修改图书数据★★★\n"); printf("★★ 10---从文件读取数据 11---修改登录密码★★\n"); printf("★***************************************************************★\n");scanf("%d",&n);getchar();switch(n){case 0:x=0;break;case 1:head=scanf_();break;case 2:if(head==NULL||head->next==NULL){printf("请先录入图书的数据!");getchar();break;}elsefprint_(head);break;case 3:if(head==NULL||head->next==NULL){printf("请先录入图书的数据!");getchar();break;}elseprint_(head);break;case 4:if(head==NULL||head->next==NULL){printf("请先录入图书的数据!");getchar();break;}else{head=jc_paixu(head);break;}case 5:if(head==NULL||head->next==NULL){printf("请先录入图书的数据!");getchar();break;}else{k=to_ji(head);printf("总共有%3d 本书",k);getchar();break;}case 6:if(head==NULL||head->next==NULL){printf("请先录入图书的数据!");getchar();break;}else{chaxun(head);getchar();break;}case 7:if(head==NULL||head->next==NULL){printf("请先录入图书的数据!");getchar();break;}elsehead=charu(head);break;case 8:if(head==NULL||head->next==NULL){printf("请先录入图书的数据!");getchar();break;}else{head=shanchu(head);break;}case 9:if(head==NULL||head->next==NULL){printf("请先录入图书的数据!");getchar();break;}else{xiugai(head);break;}case 10:head = load();if(head==NULL){printf("请先录入图书的数据!");getchar();break;}elsebreak;case 11:if((fp=fopen("密码(勿删,否则出错!).txt","w"))==NULL){ printf("文件载入失败!\n");exit(0);}printf("请输入6位新密码!\n");for(i=0;i<6;i++){ch=getchar();fputc(ch,fp);}fclose(fp);printf("密码修改成功!\n");getchar();getchar();break;default :printf("输入有误,请重新输入!");getchar();break;}}}3.3功能函数(1)函数:输出单本的图书数据void printf_(struct book *p0){printf("编号: ");puts(p0->num);printf("书名: ");puts(p0->name);printf("作者: ");puts(p0->zuozhe);printf("出版社: ");puts(p0->chuban);printf("价格: ");printf("%-8d\n",p0->jc[0]);printf("出版时间:");printf("%-8d",p0->jc[1]);printf("\n");}(2)函数:接收单本的图书数据,返回指针struct book * scanf1_(){struct book *p0;p0=(struct book *)malloc(sizeof(struct book));printf("请输入图书的编号:");gets(p0->num);printf("请输入图书的名称:");gets(p0->name);printf("请输入图书的作者:");gets(p0->zuozhe);printf("请输入图书的出版社:");gets(p0->chuban);printf("请输入图书的价格:");scanf("%d",&p0->jc[0]);printf("请输入图书的出版时间:");scanf("%d",&p0->jc[1]);getchar();return p0;}(3)函数:得到图书的数据,并放入到链表中struct book * scanf_(){struct book *p1,*p2,*head;int n=0;printf("注意:当图书编号为 0 时输入结束\n\n");p1=(struct book *)malloc(sizeof(struct book)); /*得到图书信息*/head=p2=p1;do{ printf("请输入图书的编号:");gets(p1->num);if(strcmp(p1->num,"0")==0)goto endd;printf("请输入图书的名称:");gets(p1->name);printf("请输入图书的作者:");gets(p1->zuozhe);printf("请输入图书的出版社:");gets(p1->chuban);printf("请输入图书的价格:");scanf("%d",&p1->jc[0]);printf("请输入图书的出版时间:");scanf("%d",&p1->jc[1]);getchar();printf("\n");p1=(struct book *)malloc(sizeof(struct book));p2->next=p1;p2=p1;n++;}while(1);endd:p1->next=NULL;printf("信息输入完毕!\n");getchar();/*图书的数据被放在链表中*/return head;}(4)函数:输出链表中的图书信息void print_(struct book *head){struct book *p;printf("***********************************************************\n ");printf("*\t|编号\t|书名\t|作者\t|出版社\t|价格\t|出版时间|*\n");printf("***********************************************************\n ");//打印表格域p=head;do{printf("*\t|%s\t|%s\t|%s\t|%s\t|%d\t|%d\t|*\n",p->num,p->name,p->zuozhe,p->chuban,p->jc[0],p->jc[1]);printf("***********************************************************\n ");//打印表格域p=p->next;}while(p!=NULL);getchar();}(5)函数:用链表给图书排序struct book *num_paixu(struct book *head){struct book *p1,*p2,*p3,*p4,*p5,*p6,*p7;int x=1;for(p1=head;p1->next!=NULL;p4=p1,p1=p1->next){p3=p1;for(p2=p1->next,p5=p7=p2;p2!=NULL;p7=p2,p2=p2->next){if(strcmp(p3->num,p2->num)>0){p3=p2;p5=p7;}}if(p3!=p1){if(x&&p1==head){p6=p1->next;p1->next=p3->next;p3->next=p6;p5->next=p1;head=p3;p1=p3;x=0;}else{p6=p1->next;p1->next=p3->next;p3->next=p6;p4->next=p3;p5->next=p1;p1=p3;}}}printf("排序成功!\n");return head;}(6)函数:查询图书的信息,并把图书的数据输出void chaxun(struct book *head){int k;char a[N];struct book *p1;printf("***********************************\n");printf("* 0---放弃查询 *\n");printf("* 1---按编号查询 *\n");printf("* 2---按书名查询 *\n");printf("* 3---按作者查询 *\n");printf("* 4---按出版社查询 *\n");printf("***********************************\n");scanf("%d",&k);getchar();switch(k){case 0:break;case 1:printf("请输入要查询的图书编号:");gets(a);p1=head;while(p1->next!=NULL){if(strcmp(p1->num,a)==0)break;p1=p1->next;}if(p1->next==NULL)printf("没有找到编号为 %s 的图书!\n",a);else{printf("要查询的图书信息如下:\n\n");printf_(p1);}break;case 2:printf("请输入要查询的书名:");gets(a);p1=head;while(p1->next!=NULL){if(strcmp(p1->name,a)==0)break;p1=p1->next;}if(p1->next==NULL)printf("没有找到名称为 %s 的图书!\n",a);else{printf("要查询的图书信息如下:\n\n");printf_(p1);}break;case 3:printf("请输入要查询的作者:");gets(a);p1=head;while(p1->next!=NULL){if(strcmp(p1->zuozhe,a)==0)break;p1=p1->next;}if(p1->next==NULL)printf("没有找到作者为 %s 的图书!\n",a);else{printf("要查询的图书信息如下:\n\n");printf_(p1);}break;case 4:printf("请输入要查询的出版社:");gets(a);p1=head;while(p1->next!=NULL){if(strcmp(p1->chuban,a)==0)break;p1=p1->next;}if(p1->next==NULL)printf("没有找到出版社为 %s 的图书!\n",a);else{printf("要查询的图书信息如下:\n\n");printf_(p1);}break;default:printf("您的输入有误!");getchar();break;}}(7)函数:将图书的数据插入到顺序排放的链表中,并且插入后也是顺序排放的。