苏州市职业大学课程设计任务书课程名称:《计算机语言C》起讫时间:2007-12-31至2008-1-4院系:计算机工程系班级:07软件测试指导教师:李金祥顾小晶系主任:宣仲良苏州市职业大学课程设计说明书名称:《计算机语言C》课程设计图书登记管理程序2007年12 月31 日至2008年1 月4 日共1周院系计算机工程系班级07软件测试姓名马宝珠系主任宣仲良教研室主任叶良指导教师李金祥顾小晶1.需求分析图书登记管理系统作为一个应用软件将为学校的老师和学生提供一个对学校图书馆深入了解并借阅、还书的平台。
拥护根据系统界面的提示信息对图书馆信息进行查询、初始化等操作系统功能需求分析描述如下:(1)查询图书:根据图书编号进行查询,读者可以浏览或查询相关图书。
(2)系统主菜单:若未找到相应的书籍返回到上一级目录。
(3)图书登记:读者输入要查询的编号、出版社、作者姓名等信息,系统将进行处理。
(4)初始化:输入书号、书名、书籍的数量以空格隔开,建立新文件写入数据否则初始化失败。
(5)新书入库:可读入新书名称、编号、数量以空格隔开看是否有此类书籍。
(6)借书菜单:可输入读者编号和所借书编号或调用借书函数执行借书功能。
(7)还书菜单:可输入读者编号和所还书的编号执行还书功能,还书后修改图书库存量。
(8)保存连接数据:方便读者了解图书登记的相关信息,为图书管理人员和读者带来便利。
2.总体设计下面从系统的整体流程的功能模块系统界面及数据结构进行总体设计。
(1)总体思想本系统主要设计思想是实现图书馆的功能机管理系统信息的查询、初始化、添加新书、借书、还书等主要功能。
图书登记管理情况以文件的形式储存,系统的人机接口系用简单的字符界面进行交互,系统的设计方法是结构化实际方法,系统用C语言进行开发用户可以清晰的了解图书馆内的情况。
(2)系统模块结构图根据需求分析结果,图书登记管理系统可以分为三大模块:查询图书模块、图书登记管理模块、系统控制平台。
系统模块结构如图:3、概要设计㈠系统主菜单。
显示系统的主菜单,里面有相应的功能代码,根据选择各功能代码进入不同的界面。
功能主要包括:退出系统、查询图书、借书、还书、新书入库。
㈡查询图书信息进入此菜单功能模块,输入您要查询的图书的编号、名称、作者、出版日期等。
图书查询模块流程如图:㈢图书登记管理模块根据功能选择进行操作,主要包括建立图书入库文件的保存与修改,借书、还书文件的建立与修改。
对系统进行初始化。
4、数据结构设计图书信息和读者信息的数据结构系统云运用结构体来存放图书的编号、作者、出版、借书、还书、新书入库,读者的编号、姓名、借书名称等信息。
下面是结构体的简单描述:typedef struct bk{char book_num[11];char book_name[41];int book_kc;int book_xc;struct bk * next;}book;typedef struct rd{char reader_num[11];char reader_name[11];char reader_book_num[11];struct rd * next ;}reader;5、系统流程描述系统进行初始化后,根据提示输入图书、读者的相关信息后系统进入了主菜单,根据选择相应的功能代码进入不同的功能菜单。
主要包括退出系统、新书入库、图书查询、借书、还书、输出所有信息功能。
选择代码按回车键即可进入,进入功能模块后出现了不同选象,下面以进入借宿书模块为例:进入借书模块后系统将提醒选择1可返回主菜单,选择2可正式进入借书系统。
选择2后,系统提示“请输入所借书的相关信息,读者的相关信息。
6、界面设计一、系统主菜单void M_Form(){ char ch;printf("\nThe main window of books manage ");printf("\n 0:Exit");printf("\n 1:New book instore");printf("\n 2:Book check");printf("\n 3:Borrow book check in");printf("\n 4:Return book check in");printf("\n 5:Out put all information");do{printf("\n\n Please chose the code:");scanf("%c",&ch);fflush(stdin);}while(ch!='0'&&ch!='1'&&ch!='2'&&ch!='3'&&ch!='4'&&ch!='5');switch(ch){ case'0':exit(0);case'1':Form_Insert_New_Book();break;case'2':Form_Find_Book();break;case'3':Form_Borrow_Book();break;case'4':Form_Return_Book();break;case'5':load_data();print_book(h_book);print_reader(h_reader);M_Form(); default:printf("error\n");exit(0);}}二、系统初始化模块void init_book(){ book ba[3];FILE *fp;int i;printf("\n System will initialize,Book initialize module :\n"); printf("\n Enter 3books’num,name,quantity(Space out with blank):\n ");for(i=0;i<3;i++)scanf("%s%s%d",ba[i].book_num,ba[i].book_name,&ba[i].book_kc);for(i=0;i<3;i++) {ba[i].book_xc=ba[i].book_kc;}if((fp=fopen("book.dat","wb"))==NULL){ printf("Book 't be founded ,Initialize fail!Please restar system !\n"); return; }for(i=0;i<3;i++){ if(fwrite(&ba[i],sizeof(struct bk),1,fp)!=1){ printf("\Write date wrong!\n"); exit(0); }}fclose(fp);}三、新书入库模块void Insert_New_Book(char book_num[],char book_name[],int number) { struct bk *book_fp;struct bk *p,*q,*t;q=p=h_book;while(p!=NULL&&strcmp(p->book_num,book_num)!=0) { q=p;p=p->next; }if(strcmp(p->book_num,book_num)==0){ printf("\n\t\tThis num already exist,Please reorder!\n");return;}t=(struct bk *)malloc(sizeof(struct bk));strcpy(t->book_num,book_num);strcpy(t->book_name,book_name);t->book_kc=t->book_xc=number;q->next=t;t->next=NULL;if((book_fp=fopen("book.dat","ab"))==NULL){ printf("Book 't be founded ,Initialize fail!Please restar system!\n"); return; }fwrite(t,sizeof(struct bk),1,book_fp);fclose(book_fp);}void print_book(struct bk *h){ struct bk *p;p=h;printf("\n\tBook num\tBook name\tStore quantity\tNow quantity\n"); while(p!=NULL){ printf(" %10s\t %10s %10d\t%10d\n",p->book_num,p->book_name,p->book _kc,p->book_xc);p=p->next;}}四、借书模块void Borrow_Book(char reader_num[],char book_num[]){ struct bk *book_p;struct rd *reader_p;book_p=h_book;while(book_p!=NULL&&strcmp(book_p->book_num,book_num)!=0)book_p=book_p->next;if(book_p==NULL){ printf("\n\tThis num of book no exist!\n");Form_Borrow_Book();}reader_p=h_reader;while(reader_p!=NULL&&(strcmp(reader_p->reader_num,reader_num)!=0)) reader_p=reader_p->next;if(reader_p==NULL){ printf("\n\tThis num of reader no exist!\n");Form_Borrow_Book();}else if(strcmp(reader_p->reader_book_num,"0")!=0){ printf("\n\talready reach the top,Can't borrow again!\n"); Form_Borrow_Book();}else {book_p->book_xc=book_p->book_xc-1;strcpy(reader_p->reader_book_num,book_p->book_num);save();load_data();}Form_Borrow_Book();}五、还书功能模块void Return_Book(char reader_num[],char book_num[]){ struct bk *book_p;struct rd *reader_p;book_p=h_book;while(book_p!=NULL&&strcmp(book_p->book_num,book_num)!=0)book_p=book_p->next;if(book_p==NULL){ printf("\n\tThis num of book no exist!\n");Form_Return_Book();}reader_p=h_reader;while(reader_p!=NULL&&(strcmp(reader_p->reader_num,reader_num)!=0)) reader_p=reader_p->next;if(reader_p==NULL){ printf("\n\ttThis num of reader no exist!\n");Form_Return_Book();}else if(strcmp(reader_p->reader_book_num,book_num)!=0){ printf("\n\tReader didn't borrow this book\n");Form_Return_Book();}else {book_p->book_xc=book_p->book_xc+1;strcpy(reader_p->reader_book_num,"0");save();load_data();}Form_Return_Book();}六、输出所有信息模块void Form_Insert_New_Book(){ char ch;struct bk t;printf("\n New book instor module,Please chose the code:\n"); printf(" 0:Return main menu\n");printf(" 1:New book instore");do{printf("\n\n Please chose the code:");scanf("%c",&ch);fflush(stdin);}while(ch!='0'&&ch!='1'&&ch!='2'&&ch!='3'&&ch!='4'&&ch!='5'); switch(ch){ case'0':M_Form();break;case'1':{ printf(" \nEnter book's num name quantity(Space out with blank):");scanf("%s%s%d",t.book_num,t.book_name,&t.book_kc); fflush(stdin);Insert_New_Book(t.book_num,t.book_name,t.book_kc); Form_Insert_New_Book();}default:printf("error\n");exit(0);}}程序清单:#include<stdio.h>#include<graphics.h>#include<math.h>#include<string.h>typedef struct bk{char book_num[11];char book_name[41];int book_kc;int book_xc;struct bk * next;}book;typedef struct rd{char reader_num[11];char reader_name[11];char reader_book_num[11];struct rd * next ;}reader;struct bk * h_book,* h_reader;void Form_Insert_New_Book();void Form_Find_Book();void Form_Borrow_Book();void Form_Return_Book();void Find_Book(char *);void Insert_New_Book(char *,char * ,int );void Borrow_Book(char *,char *);void Return_Book(char *,char *);void print_book(struct bk *);void print_reader(struct rd *);void load_data();void init_reader();void init_book();void save();void M_Form(){ char ch;printf("\nThe main window of books manage ");printf("\n 0:Exit");printf("\n 1:New book instore");printf("\n 2:Book check");printf("\n 3:Borrow book check in");printf("\n 4:Return book check in");printf("\n 5:Out put all information");do{printf("\n\n Please chose the code:");scanf("%c",&ch);fflush(stdin);}while(ch!='0'&&ch!='1'&&ch!='2'&&ch!='3'&&ch!='4'&&ch!='5'); switch(ch){ case'0':exit(0);case'1':Form_Insert_New_Book();break;case'2':Form_Find_Book();break;case'3':Form_Borrow_Book();break;case'4':Form_Return_Book();break;case'5':load_data();print_book(h_book);print_reader(h_reader);M_Form(); default:printf("error\n");exit(0);}}void Form_Find_Book(){ char ch;char book_num[11];printf("\n Book check module,Please chose the code:\n");printf(" 0:Return to main menu\n");printf(" 1:Book check");do{printf("\n\n Please chose the code:");scanf("%c",&ch);fflush(stdin);}while(ch!='0'&&ch!='1');switch(ch){ case'0':M_Form();break;case'1':{ printf(" \nEnter need book’s num:");scanf("%s",book_num);fflush(stdin);Find_Book(book_num);Form_Find_Book();}default:printf("error\n");exit(0);}}void Find_Book(char book_num[]){ struct bk *p;p=h_book;while(p!=NULL&&strcmp(p->book_num,book_num)!=0)p=p->next;if(p==NULL) printf("\n\tThe num of book no exist !\n");else{ printf("\n\tBook num\tBook name\tStoreroom quantity\tNow quantity \n");printf(" %10s\t %10s\t %d\t %d\t\n",p->book_num,p->book_name,p->book_ kc,p->book_xc);}getch();}void init_book(){ book ba[3];FILE *fp;int i;printf("\n System will initialize,Book initialize module :\n"); printf("\n Enter 3books’num,name,quantity(Space out with blank):\n ");for(i=0;i<3;i++)scanf("%s%s%d",ba[i].book_num,ba[i].book_name,&ba[i].book_kc);for(i=0;i<3;i++) {ba[i].book_xc=ba[i].book_kc;}if((fp=fopen("book.dat","wb"))==NULL){ printf("Book 't be founded ,Initialize fail!Please restar system !\n"); return; }for(i=0;i<3;i++){ if(fwrite(&ba[i],sizeof(struct bk),1,fp)!=1){ printf("\Write date wrong!\n"); exit(0); }}fclose(fp);}void init(){ int drive=DETECT,mode=0;initgraph(&drive,&mode,"");init_book();init_reader();}void Insert_New_Book(char book_num[],char book_name[],int number) { struct bk *book_fp;struct bk *p,*q,*t;q=p=h_book;while(p!=NULL&&strcmp(p->book_num,book_num)!=0) { q=p;p=p->next; } if(strcmp(p->book_num,book_num)==0){ printf("\n\t\tThis num already exist,Please reorder!\n");return;}t=(struct bk *)malloc(sizeof(struct bk));strcpy(t->book_num,book_num);strcpy(t->book_name,book_name);t->book_kc=t->book_xc=number;q->next=t;t->next=NULL;if((book_fp=fopen("book.dat","ab"))==NULL){ printf("Book 't be founded ,Initialize fail!Please restar system!\n"); return; }fwrite(t,sizeof(struct bk),1,book_fp);fclose(book_fp);}void print_book(struct bk *h){ struct bk *p;p=h;printf("\n\tBook num\tBook name\tStore quantity\tNow quantity\n"); while(p!=NULL){ printf(" %10s\t %10s %10d\t%10d\n",p->book_num,p->book_name,p->book _kc,p->book_xc);p=p->next;}}void print_reader(struct rd *h){ struct rd *p;p=h;printf("\n\tReader's num\tRead's name\tThe num of his borrow\n"); while(p!=NULL){ printf(" %10s\t %10s %10s\n",p->reader_num,p->reader_name,p->reader _book_num);p=p->next;}getch();}void Form_Borrow_Book(){ char ch;char book_num[11],reader_num[11];printf("\n Book borrow module,Please chose the code:\n");printf(" 0:Return main menu\n");printf(" 1:Book borrow\n");do{printf("\n\n Please chose the code:");scanf("%c",&ch);fflush(stdin);}while(ch!='0'&&ch!='1');switch(ch){ case'0':M_Form();break;case'1':{ printf(" \nEnter read's num and borrow book's num:(Space out with blank)");scanf("%s%s",reader_num,book_num);fflush(stdin);Borrow_Book(reader_num,book_num);Form_Borrow_Book();}default:printf("error\n");exit(0);}}void Borrow_Book(char reader_num[],char book_num[]){ struct bk *book_p;struct rd *reader_p;book_p=h_book;while(book_p!=NULL&&strcmp(book_p->book_num,book_num)!=0)book_p=book_p->next;if(book_p==NULL){ printf("\n\tThis num of book no exist!\n");Form_Borrow_Book();} reader_p=h_reader;while(reader_p!=NULL&&(strcmp(reader_p->reader_num,reader_num)!=0)) reader_p=reader_p->next;if(reader_p==NULL){ printf("\n\tThis num of reader no exist!\n");Form_Borrow_Book();}else if(strcmp(reader_p->reader_book_num,"0")!=0){ printf("\n\talready reach the top,Can't borrow again!\n");Form_Borrow_Book();}else {book_p->book_xc=book_p->book_xc-1;strcpy(reader_p->reader_book_num,book_p->book_num);save();load_data();}Form_Borrow_Book();}void Form_Return_Book(){ char ch;char book_num[11],reader_num[11];printf("\n Return book module,Please chose the code:\n");printf(" 0:Return main menu\n");printf(" 1:Return book\n");do{printf("\n\n Please chose the code:");scanf("%c",&ch);fflush(stdin);}while(ch!='0'&&ch!='1');switch(ch){ case'0':M_Form();break;case'1':{ printf(" \nEnter reader's num and return book's num:(Space out with blank)");scanf("%s%s",reader_num,book_num);fflush(stdin);Return_Book(reader_num,book_num);Form_Return_Book();}default:printf("error\n");exit(0);}} void Return_Book(char reader_num[],char book_num[]){ struct bk *book_p;struct rd *reader_p;book_p=h_book;while(book_p!=NULL&&strcmp(book_p->book_num,book_num)!=0)book_p=book_p->next;if(book_p==NULL){ printf("\n\tThis num of book no exist!\n");Form_Return_Book();}reader_p=h_reader;while(reader_p!=NULL&&(strcmp(reader_p->reader_num,reader_num)!=0)) reader_p=reader_p->next;if(reader_p==NULL){ printf("\n\ttThis num of reader no exist!\n");Form_Return_Book();}else if(strcmp(reader_p->reader_book_num,book_num)!=0){ printf("\n\tReader didn't borrow this book\n");Form_Return_Book();}else {book_p->book_xc=book_p->book_xc+1;strcpy(reader_p->reader_book_num,"0");save();load_data();}Form_Return_Book();}void init_reader(){ FILE *fp;reader ra[3];int i;printf("\n System will initialize reader:\n");printf("\n Enter 3 readers' num and name(Space out with blank):\n "); for(i=0;i<3;i++)scanf("%s%s",ra[i].reader_num,ra[i].reader_name);for(i=0;i<3;i++)strcpy(ra[i].reader_book_num,"0");if((fp=fopen("reader.dat","wb"))==NULL){ printf("Reader's 't be founded,initialize fail!Please restar system!\n"); return; }for(i=0;i<3;i++){ if(fwrite(&ra[i],sizeof(struct rd),1,fp)!=1){ printf("\Write date wrong!\n"); exit(0); }}} void Form_Insert_New_Book(){ char ch;struct bk t;printf("\n New book instor module,Please chose the code:\n"); printf(" 0:Return main menu\n");printf(" 1:New book instore");do{printf("\n\n Please chose the code:");scanf("%c",&ch);fflush(stdin);}while(ch!='0'&&ch!='1'&&ch!='2'&&ch!='3'&&ch!='4'&&ch!='5'); switch(ch){ case'0':M_Form();break;case'1':{ printf(" \nEnter book's num name quantity(Space out with blank):");scanf("%s%s%d",t.book_num,t.book_name,&t.book_kc);fflush(stdin);Insert_New_Book(t.book_num,t.book_name,t.book_kc);Form_Insert_New_Book();}default:printf("error\n");exit(0);}}void load_data(){ struct bk *book_p1,*book_p2,*book_p3;struct rd *reader_p1,*reader_p2,*reader_p3;FILE *fp_book,*fp_reader;fp_book=fopen("book.dat","rb");book_p1=(struct bk *)malloc(sizeof(struct bk));fread(book_p1,sizeof(struct bk),1,fp_book);h_book=book_p3=book_p2=book_p1;while(! feof(fp_book)){ book_p1=(struct bk *)malloc(sizeof(struct bk));fread(book_p1,sizeof(struct bk),1,fp_book);book_p2->next=book_p1;book_p3=book_p2;book_p2=book_p1;}book_p3->next=NULL;free(book_p1);fclose(fp_book);fp_reader=fopen("reader.dat","rb");reader_p1=(struct rd *)malloc(sizeof(struct rd));fread(reader_p1,sizeof(struct rd),1,fp_reader);h_reader=reader_p3=reader_p2=reader_p1;while(! feof(fp_reader)){ reader_p1=(struct rd *)malloc(sizeof(struct rd));fread(reader_p1,sizeof(struct rd),1,fp_reader);reader_p2->next=reader_p1;reader_p3=reader_p2;reader_p2=reader_p1;}reader_p3->next=NULL;free(reader_p1);fclose(fp_reader);}void save(){ FILE *book_fp,*reader_fp;struct bk *book_p;struct rd *reader_p;book_p=h_book; reader_p=h_reader;if((book_fp=fopen("book.dat","wb"))==NULL){ printf("Book 't be founded,Initialize fail!Please restar system!\n"); return; }while(book_p!=NULL){ if(fwrite(book_p,sizeof(struct bk),1,book_fp)!=1){ printf("\Write date wrong!\n"); exit(0); }book_p=book_p->next;}fclose(book_fp);if((reader_fp=fopen("reader.dat","wb"))==NULL){ printf("Book 't be founded,Initialize fail!Please restar system!\n"); return; }while(reader_p!=NULL){ if(fwrite(reader_p,sizeof(struct rd),1,reader_fp)!=1){ printf("\Write date wrong!\n"); exit(0); }reader_p=reader_p->next;}fclose(reader_fp);}main(){ FILE * fp;struct bk temp;clrscr();h_book=NULL;h_reader=NULL;if((fp=fopen("book.dat","r"))==NULL)init();fclose(fp);load_data();M_Form();save();getch();}心得体会:经过一个星期的编译原理课程设计,我们在李教授的指导下,顺利完成该课程设计。