程序设计实验报告.doc_第1页
程序设计实验报告.doc_第2页
程序设计实验报告.doc_第3页
程序设计实验报告.doc_第4页
程序设计实验报告.doc_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

班级:11计科 姓名:王向阳 学号:201130457106 C语言“图书信息管理系统设计”实验报告一设计目的1二 总体设计2三 详细设计21 界面设计22 模块设计33 主函数声明:34 主函数:45 录入密码模式源代码:46 浏览57 书名的读取68 书名的保存69 书名查找710 图书信息的录入811 删除912 信息保存在TXT中要链接11四 调试与测试11五 整个图书信息管理系统源代码如下:12一设计目的为了进一步提高我们的逻辑思维能力、动手能力和提高独立解决问题的能力,我们小组选择了“图书信息管理系统”课题来进行C语言的强化训练。图书信息管理系统,是每所大学都有的一个较实用的管理系统,我们选择“图书管理系统“课题,更贴近我们的生活从而能更一步了了解图书信息管理的运用。二 总体设计本系统的功能模块如下图: 主 菜 单书名的删除修改书名浏览书名录入书名查询作者名查询书名查询如图11:简单图书管理系统主要功能三 详细设计1 界面设计图1-2所示:*MENU*1登入菜单2退出 图-图书信息管理系统主菜单按Enter键后进入密码模式输入登入密码:1234562 模块设计1 头文件:#include#include#include#include2 结构体:typedef struct booksint ID; /登入号char name10; /图书书名char authorname10; /作者名int no; / 分类号char publisher5;/出版单位char time10;/出版时间float price; /价格struct books *next;BOO;3 主函数声明:BOO *create_form();void Cipher(); /密码登入菜单BOO *del(); /删除与修改void prin(); /浏览图书信息void search(); /查询图书信息void insert();void savefile();void readfile();void books();void myInsert(BOO *books);4 主函数:int main()int w=1;dosystem(cls);puts(nntt*MENU*nn);puts(tttt1.登入菜单n);puts(ttt2.退出);puts(nntt*n);printf(请输入选择(1-2):bb);scanf(%d,&ID);switch(ID)case 1:Cipher();break;case 2:w=0;break;while(w=1);return 0;5 录入密码模式源代码:void Cipher()int n,w=1,flag=0,i=3;char s8;char password7=123456;doprintf(nnEnter password:);scanf(%s,s);if(!strcmp(s,password)flag=1;break;elseprintf(nnError! You only have %d times! Enter again:n,i-1);i-;while(i0);if(!flag)printf(you have Enter 3 times!);exit(0); dosystem(cls);puts(nntt*登陆菜单*nn);puts(tttt1-图书信息录入n);puts(tttt2-图书信息浏览n);puts(tttt3-图书信息查询n);puts(tttt4-图书信息的删除与修改-n);puts(tttt5-返回主菜单);puts(nntt*n);printf(请输入选择(1-5):bb); scanf(%d,&n);switch(n)case 1:insert();savefile();break;case 2:prin();break;case 3:search();break;case 4:del();insert();savefile();break;case 5:return;while(w=1);6 浏览浏览的函数名为“void prin()”,浏览选项可以将录入的图书一次显示出来。可被主函数调用浏览的源代码为:void prin() /浏览图书信息BOO *ptr=NULL;head=NULL;readfile();if(head=NULL)printf(nnt*NO RECORDS!*n);return;printf(登入号 书名 作者名 分类号 出版单位 出版时间 价格n);for(ptr=head;ptr;ptr=ptr-next)printf(%5d%10s%12s%12d%10s%12s%12fn,ptr-ID,ptr-name,ptr-authorname,ptr-no,ptr-publisher,ptr-time,ptr-price);system(pause);7 书名的读取 读取保存在”all_book.txt”中的图书信息。 读取的源代码:void readfile()BOO *newBoo=NULL;char c,fID15;FILE *fp;strcpy(fID,all_boo.txt);fp=fopen(fID,r);if(fp=NULL) printf(read file error!);exit(0);while(!feof(fp)if(c=fgetc(fp)=n)break;printf(ok);while(!feof(fp)newBoo=(BOO *)malloc(sizeof(BOO);fscanf(fp,%d%s%s%d%s%s%f,&newBoo-ID,newBoo-name,newBoo-authorname,&newBoo-no,newBoo-publisher,newBoo-time,&newBoo-price);myInsert(newBoo);fclose(fp);8 书名的保存保存录入的图书信并存入”all_book.txt”电子书中,以便在读取,查询,浏览中调用。 源代码为:void savefile()BOO *p;FILE *fp;fp=fopen(all_boo.txt,w);if(fp=NULL) printf(open file error!);exit(0);fprintf(fp,登入号 书名 作者名 分类号 出版单位 出版时间 价格n);for(p=head;p;p=p-next)fprintf(fp,%5d%10s%12s%12d%10s%12s%12fn, p-ID,p-name,p-authorname,p-no,p-publisher,p-time,p-price);fclose(fp);printf(创建后的信息已放入all_boo.txt文件中n);system(PAUSE); 9 书名查找“查找”的函数名为“void search_book(void)”能够对录入的图书进行查找,查找的方式有“按书名查询”和“按作者名查询” ,可被主函数调用。查找的源代码为:void search()int a;int t=1;char type10,min10;BOO *ptr=NULL;head=NULL;readfile();l1:system(cls); printf(nntt*请选择查询方式*n); printf(nttt1-按书名查询n); printf(nttt2-按作者名查询n); printf(nttt3-退出查询n); printf(nttt*n); printf(nnChoose your number(1-3):bb); scanf(%d,&a); switch(a) case 1: printf(请输入要查询的书名:); scanf(%s,min); printf(登入号 书名 作者名 分类号 出版单位 出版时间 价格n); for(ptr=head;ptr;ptr=ptr-next) if(strcmp(min,ptr-name)=0) printf(%5d%10s%12s%12d%10s%12s%12fn,ptr-ID,ptr-name, ptr-authorname,ptr-no,ptr-publisher,ptr-time, ptr-price); t=0; if(t) printf(tn未找到!n); t=1; system(PAUSE); goto l1; case 2: printf(请输入要查询的作者名:); scanf(%s,type); printf(登入号 书名 作者名 分类号 出版单位 出版时间 价格n); for(ptr=head;ptr;ptr=ptr-next) if(strcmp(type,ptr-authorname)=0) printf(%5d%10s%12s%12d%10s%12s%12fn,ptr-ID,ptr-name, ptr-authorname,ptr-no,ptr-publisher,ptr-time, ptr-price); t=0; if(t) printf(tn未找到!n); t=1; system(PAUSE); goto l1; case 3:break; 10 图书信息的录入源代码如下:void myInsert(BOO *books) /红色字全体为刚刚所加的BOO *p1,*p2;p1=books;if(head=NULL)head=p1;head-next=NULL;elsefor(p2=head;p2;p2=p2-next)if(p2-next=NULL)p2-next=books;p2-next-next=NULL;break;void insert()BOO *ptr,*books;int size=sizeof(BOO);char ch=1,ch1;while(ch!=0)books=(BOO*)malloc(size);printf(输入录入的图书信息:n);printf(ntt登入号:);scanf(%d,&books-ID);printf(ntt书名:);scanf(%s,books-name);printf(ntt作者名:);scanf(%s,books-authorname);printf(ntt分类号:);scanf(%d,&books-no);printf(ntt出版单位:);scanf(%s,books-publisher);printf(ntt出版时间:);scanf(%s,books-time);printf(ntt价格:);scanf(%f,&books-price);myInsert(books);printf(nn继续录入请按回车n);printf(n结束录入请按n:bb);ch1=getchar();ch=getchar();11 删除“删除”的函数名为“void book_del(void)”主要功能为对录入的图书信息进行删除。可被主函数调用。删除的源代码为:BOO *del()BOO *p1,*p2;char ch,ch1;int ID;head=NULL;readfile();while(ch!=0)printf(输入想要删除的图书ID: bbbbb);scanf(%d,&ID);if(head-ID=ID)p2=head;head=head-next;free(p2);if(head=NULL)return NULL;p1=head;p2=head-next;while(p2)if(p2-ID=ID)p1-next=p2-next;free(p2);break;elsep1=p2;p2=p2-next;printf(n继续删除请按回车n);printf(n结束删除图书信息按0:bb);ch1=getchar();ch=getchar();system(PAUSE);12 信息保存在TXT中要链接 链接代码:BOO *create_form()BOO *head,*tail,*p;int no,ID;float price;char name5,authorname5,publisher5,time5;int size=sizeof(BOO);head=tail=NULL;printf(输入图书信息:n);scanf(%5d%5s%12s%12s%10s%12s%12dn,&ID,name,authorname,&no,publisher,time,&price);while(ID!=0)p=(BOO*)malloc(size);p-ID=ID;strcpy(p-name,name);strcpy(p-authorname,authorname);strcpy(p-publisher,publisher);strcpy(p-time,time);p-no=no;p-price=price;if(head=NULL)head=p;elsetail-next=p;tail=p;scanf(%5d%5s%12s%12s%10s%12s%12d,&ID,name,authorname,&no,publisher,time,&price);tail-next=NULL;return head;四 调试与测试在编程的过程中我们遇到了许许多多的错误,令我印象最深的调试错误有如下:1. 函数的未定义声明。因为把一般函数写在主函数的后面而没有在前面做函数的声明,导致函数未定义声明错误。2. 两个不同类型的变量在用if语句时相比较。3. 变量的重复定义,未能成功调用函数。4. 语句的混乱导致主要功能的无法运用的。5. 也学会如果语句无法调用时,看程序运行到哪一条语句时,可以写入输出语句,如:printf(“ok”),看是否会被输出。五 整个图书信息管理系统源代码如下: #include#include#include#includetypedef struct booksint ID; /登入号char name10; /图书书名char authorname10; /作者名int no; / 分类号char publisher5;/出版单位char time10;/出版时间float price; /价格struct books *next;BOO;BOO *create_form();void Cipher(); /密码登入菜单BOO *del(); /删除与修改void prin(); /浏览图书信息void search(); /查询图书信息void insert();void savefile();void readfile();void books();void myInsert(BOO *books);BOO *head=NULL;int ID=0; /定义可能为错int main()int w=1;dosystem(cls);puts(nntt*MENU*nn);puts(tttt1.登入菜单n);puts(ttt2.退出);puts(nntt*n);printf(请输入选择(1-2):bb);scanf(%d,&ID);switch(ID)case 1:Cipher();break;case 2:w=0;break;while(w=1);return 0;void Cipher()int n,w=1,flag=0,i=3;char s8;char password7=123456;doprintf(nnEnter password:);scanf(%s,s);if(!strcmp(s,password)flag=1;break;elseprintf(nnError! You only have %d times! Enter again:n,i-1);i-;while(i0);if(!flag)printf(you have Enter 3 times!);exit(0); dosystem(cls);puts(nntt*登陆菜单*nn);puts(tttt1-图书信息录入n);puts(tttt2-图书信息浏览n);puts(tttt3-图书信息查询n);puts(tttt4-图书信息的删除与修改-n);puts(tttt5-返回主菜单);puts(nntt*n);printf(请输入选择(1-5):bb); scanf(%d,&n);switch(n)case 1:insert();savefile();break;case 2:prin();break;case 3:search();break;case 4:del();insert();savefile();break;case 5:return;while(w=1);void prin() /浏览图书信息BOO *ptr=NULL;head=NULL;readfile();if(head=NULL)printf(nnt*NO RECORDS!*n);return;printf(登入号 书名 作者名 分类号 出版单位 出版时间 价格n);for(ptr=head;ptr;ptr=ptr-next)printf(%5d%10s%12s%12d%10s%12s%12fn,ptr-ID,ptr-name,ptr-authorname,ptr-no,ptr-publisher,ptr-time,ptr-price);system(pause);void readfile()BOO *newBoo=NULL;char c,fID15;FILE *fp;strcpy(fID,all_boo.txt);fp=fopen(fID,r);if(fp=NULL) printf(read file error!);exit(0);while(!feof(fp)if(c=fgetc(fp)=n)break;printf(ok);while(!feof(fp)newBoo=(BOO *)malloc(sizeof(BOO);fscanf(fp,%d%s%s%d%s%s%f,&newBoo-ID,newBoo-name,newBoo-authorname,&newBoo-no,newBoo-publisher,newBoo-time,&newBoo-price);myInsert(newBoo);fclose(fp);void savefile()BOO *p;FILE *fp;fp=fopen(all_boo.txt,w);if(fp=NULL) printf(open file error!);exit(0);fprintf(fp,登入号 书名 作者名 分类号 出版单位 出版时间 价格n);for(p=head;p;p=p-next)fprintf(fp,%5d%10s%12s%12d%10s%12s%12fn, p-ID,p-name,p-authorname,p-no,p-publisher,p-time,p-price);fclose(fp);printf(创建后的信息已放入all_boo.txt文件中n);system(PAUSE);void search()int a;int t=1;char type10,min10;BOO *ptr=NULL;head=NULL;readfile();l1:system(cls); printf(nntt*请选择查询方式*n); printf(nttt1-按书名查询n); printf(nttt2-按作者名查询n); printf(nttt3-退出查询n); printf(nttt*n); printf(nnChoose your number(1-3):bb); scanf(%d,&a); switch(a) case 1: printf(请输入要查询的书名:); scanf(%s,min); printf(登入号 书名 作者名 分类号 出版单位 出版时间 价格n); for(ptr=head;ptr;ptr=ptr-next) if(strcmp(min,ptr-name)=0) printf(%5d%10s%12s%12d%10s%12s%12fn,ptr-ID,ptr-name, ptr-authorname,ptr-no,ptr-publisher,ptr-time, ptr-price); t=0; if(t) printf(tn未找到!n); t=1; system(PAUSE); goto l1; case 2: printf(请输入要查询的作者名:); scanf(%s,type); printf(登入号 书名 作者名 分类号 出版单位 出版时间 价格n); for(ptr=head;ptr;ptr=ptr-next) if(strcmp(type,ptr-authorname)=0) printf(%5d%10s%12s%12d%10s%12s%12fn,ptr-ID,ptr-name, ptr-authorname,ptr-no,ptr-publisher,ptr-time, ptr-price); t=0; if(t) printf(tn未找到!n); t=1; system(PAUSE); goto l1; case 3:break; void myInsert(BOO *books) /红色字全体为刚刚所加的BOO *p1,*p2;p1=books;if(head=NULL)head=p1;head-next=NULL;elsefor(p2=head;p2;p2=p2-next)if(p2-next=NULL)p2-next=books;p2-next-next=NULL;break;void insert()BOO *ptr,*books;int size=sizeof(BOO);char ch=1,ch1;while(ch!=0)books=(BOO*)malloc(size);printf(输入录入的图书信息:n);printf(ntt登入号:);scanf(%d,&books-ID);printf(ntt书名:);scanf(%s,books-name);printf(ntt作者名:);scanf(%s,books-authorname);printf(ntt分类号:);scanf(%d,&books-no);printf(ntt出版单位:);scanf(%s,books-publisher);printf(ntt出版时间:);scanf(%s,b

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论