1、一:系统功效基础功效:图书录入,删除,查找,和导入导出等。图书属性:书号,书名,第一作者,版次,出版年等。菜单功效:1. Input Records(输入若干条统计)从键盘一次输入一本书信息,存放到结构体数组中,然后显示。提醒信息,确定是否输入下一条统计。2. Display All Records(显示全部统计)按次序显示全部统计,每屏显示10条统计,按键继续显示下一屏。3. Delete a Record(按书名查找,删除一本书)输入待删除书书名,显示该书名全部书目,提醒输入待删除书目标书号,提醒是否删除,确定后,删除该书。4. Sort(排序)以书名为升序排列数组5. Insert a
2、record(插入一条统计)以书名为序排列数组中插入一条统计,插入后,数组仍然有序。输出插入成功后信息。6. Query(查找并显示一个统计)输入书名,查找并显示包含该书名全部图书信息7. Add Records from a Text File(从文件读入图书信息到结构体数组中)用户可事先建立一个文本文件Dictory.txt。存放全部图书信息,文件格式以下:21182高等数学刘浩荣 5 同济大学出版社 7300 物理化学王德明 2 化学工业出版社 8. Write to a Text File将数组中全部统计写入文件Records.txt中,要求格式和Dictory.txt相同。0. Qu
3、it(退出图书管理系统)新增加菜单功效:9. Change a record修改某一条统计值a. Menu显示菜单b. Clear Screen清屏c. Pause按暂停,按任意键继续二:数据结构Typedef structchar ISBN10;/书号char book30;/书名char author20;/作者Int edition;/版本号char press50;/出版社名int year;/出版年Bookinfo;三:函数调用关系Write_to_Text()Display_main_menu()Change_a_record()Delete()Sort_by_name()Inse
4、rt()Insert_a_record()AddfromText()Delete_a_record()Display()Query()Query_a_record()Input()main四:关键算法及实现i=0语句Bn+1是是是否否否b=strcmp(*s).book,dictListi.book)=0c=strcmp(*s).book,dictListi+1.book)i+1j=nb&cin-1i=0插入算法排序算法结束否否是否否是是是p=j语句Ai+j+j0P!=ip=ij=i+1in-1i=0开始b=strcmp(dictListp.book,dictListj.book)语句A:t
5、= dictListp; dictListp = dictListi; dictListi = t;五:源程序(含注释)#include#include#include#define NUM 100typedef struct /定义结构体数组 char ISBN10; /书号 char book30; /书名 char author20; /作者 int edition; /版本号 char press50; /出版社名 int year; /出版年Bookinfo;int Input(Bookinfo dictList,int n) /从键盘输入数据,存入结构体数组dictList cha
6、r c1,c2; do c1=getchar(); printf(Please input ISBN:n); gets(dictListn.ISBN); printf(Please input book:n); gets(dictListn.book); printf(Please input author:n); gets(dictListn.author); printf(Please input press:n); gets(dictListn.press); printf(Please input edition:n); scanf(%d,&dictListn.edition); pr
7、intf(Please input year:n); scanf(%d,&dictListn.year); n+=1; printf(是否输入下一条?确定(y)|取消(n)n);/提醒信息 c1=getchar(); while(c2=getchar()=y); return(n); /返回值为新统计数量void Display(Bookinfo dictList,int n) /显示全部统计,每10个暂停一次,输入回车继续显示 int i=0,j; char input,c;printf(%-10s%-23s%-18s%-8s%-15s%-4sn,ISBN,book,author,editi
8、on,press,year); c=getchar(); do j=10; /每10个循环一次 do printf(%-10s%-23s%-18s%-8d%-15s%-4dn,dictListi.ISBN,dictListi.book,dictListi.author,dictListi.edition,dictListi.press,dictListi.year); i+; j-; while(j & in); if(i=n) break; /若数据全部输出,则跳出循环, scanf(%c,&input); while(input=n); /输入回车,实施循环int delete(Booki
9、nfo dictList,int n,char *ISBN) /只删除书号为ISBN第一条统计 int i,j; for(i=0;in;i+) if(!strcmp(dictListi.ISBN,ISBN) /strcmp()函数判定两个字符串是否相等 for(j=i;jn-1;j+) dictListj=dictListj+1; /将目标值右面数据全部左移一位 return(n-1);/删除后统计数降低1 return(n);int Delete_a_record(Bookinfo dictList,int n)/删除某一条统计 int i,j=0; char book30,isbn10,s
10、,c; c=getchar(); printf(请输入待删除书目标书名n); gets(book); /获取书名字符串 printf(%-10s%-23s%-18s%-8s%-15s%-4sn,ISBN,book,author,edition,press,year); for(i=0;i0) printf(请输入待删除书目标书号n); gets(isbn); /获取要删除数据书号 printf(确实要删除该统计?是(y)|否(n)n); /提醒删除 if(s=getchar()=y) for(i=0;in;i+) if(!strcmp(dictListi.ISBN,isbn) /调用delet
11、e函数删除 printf(删除成功!n); return(delete(dictList,n,dictListi.ISBN); printf(未找到待删除统计!n); /删除成功后统计减1 else printf(已取消删除!n); /取消删除后统计数不变 return n; else printf(未找到待删除统计!n);void Sort_by_name(Bookinfo dictList,int n)/选择法按书名升序排列 int i,j,p; Bookinfo t; for(i = 0;in-1;i+) p=i; for(j=i+1;j0) p=j; if(p!=i) t = dict
12、Listp; dictListp = dictListi; dictListi = t; int insert(Bookinfo dictList,int n,Bookinfo *s)/按书名次序插入统计 int i,j; Sort_by_name(dictList,n); for(i=0;in-1;i+) if(strcmp(*s).book,dictList0.book)0;j-) dictListj=dictListj-1; dictList0=*s; return(n+1); else if(strcmp(*s).book,dictListi.book)=0 & strcmp(*s).
13、book,dictListi+1.book)i+1;j-) dictListj=dictListj-1; dictListi+1=*s; /放在i和i+1之间或放在最终一个 return(n+1); dictListn=*s; return(n+1);int Insert_a_record(Bookinfo dictList,int n)/出现问题,调用该函数时总是全部显示统计? int k; char c; Bookinfo s; /输入数据 c=getchar(); printf(Please input ISBN:n); gets(s.ISBN); printf(Please input
14、 book:n); gets(s.book); printf(Please input author:n); gets(s.author); printf(Please input press:n); gets(s.press); printf(Please input edition:n); scanf(%d,&s.edition); printf(Please input year:n); scanf(%d,&s.year); k=insert(dictList,n,&s); /依据insert返回值是否大于n判定插入成功是否 if(kn) printf(插入成功!n); return(k
15、); else printf(插入失败!n); return(n); int Query(Bookinfo dictList,int n,char *book)/查询并显示书名为book统计 int i,count=0; printf(%-10s%-23s%-18s%-8s%-15s%-4sn,ISBN,book,author,edition,press,year); for(i=0;i0) printf(共找到%d条统计n,i); /若查到数据,Query函数返回值为正数 else printf(未找到所查找统计n);int AddfromText(Bookinfo dictList,int
16、 n,char *filename)int i; Bookinfo s;FILE *p; p=fopen(filename,r); fscanf(p,%d,&i); /先读取文件第一行统计数 while(i-) fscanf(p,%s%s%s%d%s%dn,s.ISBN,s.book,s.author,&s.edition,s.press,&s.year); /读取统计具体值 n=insert(dictList,n,&s); /插入到dictList数组中 fclose(p); printf(读取成功!n); return(n);void WritetoText(Bookinfo dictLi
17、st,int n,char *filename) FILE *p2;int i; p2=fopen(filename,w); for(i=0;i0)/确定找到待修改统计 printf(共找到%d条统计n请输入待修改图书书号n,i); gets(ISBN); for(i=0;in;i+) if(!strcmp(dictListi.ISBN,ISBN) printf(请更新书号为%s图书数据n,ISBN);/开始修改 printf(Please input ISBN:n); gets(dictListi.ISBN); printf(Please input book:n); gets(dictLi
18、sti.book); printf(Please input author:n); gets(dictListi.author); printf(Please input press:n); gets(dictListi.press); printf(Please input edition:n); scanf(%d,&dictListi.edition); printf(Please input year:n); scanf(%d,&dictListi.year); printf(修改完成!n); else printf(未找到相关统计n);main() static int n=12; c
19、har filename130,filename230,c; /创建初始结构体数组,应不少于十个 Bookinfo booksNUM= 97814842,python Language,gnus Lie land,2,Berkeley, 97871190,history of Chinese,Goa qua,2,Beijing, 97814129,public communication,Ronald E.Rice,3,London, 97836422,cultural composition,Yang Pan,2,pardon, 97801240,analyzing the social,J
20、ennifer beck,1,Walt, 78016958,recored servicing,Scottish Qua,1,Chinese, 01354851,management guide,Ferdinand K. Levy,1,Englewood,1969, 1096-424,macroeconomics,Dusk ,2,Gog,1977, 04448649,competitive economics,Ki Hang Kim,2,Amsterdam,1983, 08531419,guide to banking,Robin Pr,7,London,1973, 01311606,guid
21、e to banking,Jerry S.Rosen,2,Englewood,1972, 97875100,dirt pricing dynamic,Pamela La,1,World book,; Display_main_menu(); /显示菜单 while(c=getchar() /连续获取输入,并用switch语句调用对应函数 switch(c) case 0:exit(1);break; case 1:n=Input(books,n);break; case 2:Display(books,n);break; case 3:n=Delete_a_record(books,n);br
22、eak; case 4:Sort_by_name(books,n);break; case 5:n=Insert_a_record(books,n);break; case 6:Query_a_record(books,n);break; case 7: printf(请输入文件名n); scanf(%s,filename1); n=AddfromText(books,n,filename1); break; case 8: printf(请输入文件名n); scanf(%s,filename2); WritetoText(books,n,filename2); break; case 9:C
23、hange_a_record(books,n);break; case a:Display_main_menu();break; case b:system(cls);break; case c:system(pause);break; 六:程序实施(包含经典测试数据)-1.Input records2.Display All Records3.Delete a Record4.sort5.Insert a Record6.Query7.Add Records from a Text File8.Write to a Text File9.Change a record0.QuitTIPS a
24、.Menu b.Clear Screen c.Pause-Give your choice:1Please input ISBN:4296Please input book:明朝那些事Please input author:当年明月Please input press:浙江出版社Please input edition:2Please input year:是否输入下一条?确定(y)|取消(n)n2ISBN book author edition press year97814842 python Language gnus Lie land 2 Berkeley 97871190 histo
25、ry of Chinese Goa qua 2 Beijing 97814129 public communication Ronald E.Rice 3 London 97836422 cultural composition Yang Pan 2 pardon 97801240 analyzing the social Jennifer beck 1 Walt 78016958 recored servicing Scottish Qua 1 Chinese 01354851 management guide Ferdinand K. Levy 1 Englewood 19691096-4
26、24 macroeconomics Dusk 2 Gog 197704448649 competitive economics Ki Hang Kim 2 Amsterdam 198308531419 guide to banking Robin Pr 7 London 197301311606 guide to banking Jerry S.Rosen 2 Englewood 197297875100 dirt pricing dynamic Pamela La 1 World book 4296 明朝那些事当年明月 2 浙江出版社 3请输入待删除书目标书名明朝那些事ISBN book a
27、uthor edition press year4296 明朝那些事当年明月 2 浙江出版社 请输入待删除书目标书号4296确实要删除该统计?是(y)|否(n)y删除成功!42ISBN book author edition press year97801240 analyzing the social Jennifer beck 1 Walt 04448649 competitive economics Ki Hang Kim 2 Amsterdam 198397836422 cultural composition Yang Pan 2 pardon 97875100 dirt prici
28、ng dynamic Pamela La 1 World book 08531419 guide to banking Robin Pr 7 London 197301311606 guide to banking Jerry S.Rosen 2 Englewood 197297871190 history of Chinese Goa qua 2 Beijing 1096-424 macroeconomics Dusk 2 Gog 197701354851 management guide Ferdinand K. Levy 1 Englewood 196997814129 public c
29、ommunication Ronald E.Rice 3 London 97814842 python Language gnus Lie land 2 Berkeley 78016958 recored servicing Scottish Qua 1 Chinese 5Please input ISBN:84772281Please input book:english learningPlease input author:tomPlease input press:AllaPlease input edition:2Please input year:插入成功!6请输入待查找书名recored servicingISBN book author edition press year78016958 recored servicing Scottish Qua 1 Chinese 共找到1条统计7请输入文件名Dictory.txt读取成功!2ISBN b
©2010-2024 宁波自信网络信息技术有限公司 版权所有
客服电话:4008-655-100 投诉/维权电话:4009-655-100