A. 用c语言做图书馆图书信息管理软件设计
呵呵,谁会为了那20个没用的玩意儿浪费自己的时间为你写程序
B. 用C语言设计和实现一个“图书信息管理系统”,满足以下要求:
const int MAXLEN=100;int count; //记录书籍数量char fName[20]="backup.dat"; //磁盘文件:书籍信息文件名 int LEN; //全局变量,通讯录中当前联系人总数int n;char *key;
typedef struct book //联系人数据结构
{ char no[20]; //序号 char book_name[20]; // 书名 char writer[30]; //作者名 char booknum[20]; //书籍分类 char press[20]; //出版单位 char price[10]; //书籍价格 }BOOK;BOOK b[MAXLEN];
typedef struct index{ int len; //数组长度 BOOK b[MAXLEN]; //指针数组}Index;
int Select();int Menu(void);int SubMenu2(void);int SubMenu4(void);int addbook(BOOK b[]);int output(BOOK b[]);int deletebook(BOOK b[]);void printno(BOOK b[]);int modifyIndo(BOOK b[]);int Save(BOOK b[]); int loaddata(BOOK b[]);int Copy(void);void New(BOOK b[]);int Load(BOOK b[]);void List(BOOK b[]);//void findbook(char *name,BOOK b[],char *key);
#include<stdio.h>#include<stdlib.h>#include<conio.h>#include<string.h>#include<memory.h>int main(int argc, char* argv[]){ int select=0;
/*int select;用户所选的菜单项代码: 主菜单:1 查找图书信息、2 更新图书信息 、3 备份图书信息、0 退出程序 更新图书信息子菜单:21 新增图书信息、 22 编辑图书信息、 23 删除图书信息、 20 返回主菜单 查看图书信息子菜单:11 图书信息库 、12书名查找、13 作者名查找、14 序号查找 */
BOOK b[MAXLEN]; memset(b,0,sizeof(b)); //将b初始化为空,memory.h loaddata(b); //从图书库文件中读取信息 //循环显示菜单,供用户选择 do{
if(select<10||select==20||select==40) select=Menu(); else if(select>20 && select<30) select=SubMenu2(); else if(select>40 && select<50) select=SubMenu4(); switch(select) { case 11:// 图书信息库 break; case 12://书名查找 break;
case 13://作者名查找 break; case 14://类别查找 break;
case 21://新增图书信息、 break; case 22://编辑图书信息、 break; case 23://删除图书信息、 break; case 20://返回主菜单 break; case 3: system("cls"); Save(b); Copy(); break; case 0://退出程序 break; } }while(select!=0); return 0;}
int SubMenu4(void){ char menu; do{ system("cls");//清屏,需要使用到stdlib.h puts("\n\t======更新图书信息======\n"); puts("\t 1.新增图书信息"); puts("\t 2.删除图书信息"); puts("\t 3.编辑图书信息"); puts("\t 0.返回主菜单"); puts("\n\t=================="); printf("\t请选择:");//提示选择 menu=getche(); switch(menu) { case '0': puts("\n\n\t返回主菜单!"); break; case '1': addbook(b); break; case '2': deletebook(b); break; case '3': modifyIndo(b); break; default: puts("\n\n\t选择错误!"); menu='9'; } }while(menu=='9'); return 40+menu-'0';}
void New(BOOK b[]){ int t=0; //找到BOOK中第一个空的位置,存放新输入 if(LEN>=MAXLEN) { printf("\n\n\t图书库已满!"); return ; }
while(strcmp(b[t].book_name,"")!=0) //找到b中第一个空的位置t t++; addbook(b); //新增,输入 LEN++; //增1}
int modifyIndo(BOOK b[])//编辑图书信息{ char no[20]; int i; printno(b);again: printf("\n请输入你想要编辑的书籍编号:"); fflush(stdin); gets(no); for(i=0;i<=count;i++) { if(strcmp(no,b[i].no)==0) break; } if(i>count) { printf("对不起,你输入的编号不存在,是否继续?Y/N:"); if((getchar()=='Y')||(getchar()=='y')) goto again; else return 0; } printf("\n正在修改《%s》的信息……\n",b[i].book_name); printf("请输入图书的名字:"); gets(b[i].book_name); printf("请输入图书的作者名:"); gets(b[i].writer); printf("请输入书籍类别:"); gets(b[i].booknum); printf("请输入书籍的出版单位:"); gets(b[i].press); printf("请输入书籍的价格:"); gets(b[i].price); printf("\n图书信息编辑成功!\n");
}
void printno(BOOK b[]){ int i; printf("\n当前库存中的书籍目录:\n"); for( i=0;i<=count;i++) { printf("%s %s ",b[i].no,b[i].book_name); if(i%3==0&&i>0) printf("\n"); }}
int output(BOOK b[]) //输出图书信息{ if(count<0) { printf("对不起,当前图书数量为0\n"); return 0; } for(int i=0;i<=count;i++) { printf("\n*************************书籍信息*****************************\n"); printf("序号:%s\n",b[i].no); printf("书名:%s\n",b[i].book_name); printf("作者名:%s\n",b[i].writer); printf("书籍类别:%s\n",b[i].booknum); printf("出版单位:%s\n",b[i].press); printf("书籍价格:%s\n",b[i].price); } return 1; }
int deletebook(BOOK b[]) { char no[20]; int i; printno(b);loop: printf("\n请输入你要删除的书籍编号:"); fflush(stdin); gets(no); for(i=0;i<=count;i++) { if(strcmp(no,b[i].no)==0) break; } if(i>count) { printf("对不起,你输入的编号不存在,是否继续?Y/N:"); if((getchar()=='Y')||(getchar()=='y')) goto loop; else return 0; } printf("您确定要删除《%s》吗?Y/N:",b[i].book_name); if((getchar()=='Y')||(getchar()=='y'))
{ if(i==count) { count--; } else { for(;i<=count;i++) { b[i]=b[i+1]; count--; }
}
} else return 0; }
int loaddata(BOOK b[]){ int i=0; //i:b数组的下标 FILE *fp=fopen(fName,"r"); if(!fp) { printf("\n\t对不起,路径或者文件错误,无法读入!请重新增加!"); getch(); return 0; } fscanf(fp,"书籍编号\t书名\t作者\t类别\t出版单位\t价格"); while((!feof(fp))) { fscanf(fp,"\n%s\t%s\t%s\t%s\t%s\t%s",&b[i].no,&b[i].book_name,&b[i].writer,&b[i].booknum,&b[i].press,&b[i].price); i++; } count=i; fclose(fp); printf("加载成功!!"); return 1;}
int Select(){ int i=0; int c; //c:scanf输入的返回值,输入成功返回1;否则返回0 printf("\n\t请按需要选择图书信息:"); c=scanf("%d",&i); while(i<1 || i>LEN) { printf("\n\t输入错误!请按序号选择图书信息:"); if(c==0) fflush(stdin); c=scanf("%d",&i); } return i-1;} int addbook(BOOK b[]) //增加图书信息{ int i=0; char c; printf("\n*******************************新增图书信息****************************\n"); for(;;i++) { if(i>=MAXLEN) { printf("\n对不起,库存已满!不能继续添加。"); } printf("请输入图书的序号:"); gets(b[i].no); printf("请输入图书的名字:"); gets(b[i].book_name); printf("请输入图书的作者名:"); gets(b[i].writer); printf("请输入书籍类别:"); gets(b[i].booknum); printf("请输入书籍的出版单位:"); gets(b[i].press); printf("请输入书籍的价格:"); gets(b[i].price); printf("图书增加成功!\n"); printf("请问您要继续添加书籍信息吗?(Y/N): "); c=getchar(); if(c=='Y'||c=='y') { getchar(); printf("\n"); continue; } else break; } count=i; return i;
}//查重。int Duplicate(char *name,BOOK b[],char *original){ int i,j; int p=0; //重复标志:1 重复 ,0 没有重复 if(strcmp(name,original)!=0) for(i=0,j=0;j<LEN;) { while(strcmp(b[i].book_name,"")==0) i++;
if(strcmp(name,b[i].book_name) ==0) { p=1; printf("\n\t重复!请重新输入:"); break; } i++; j++; } return p; }int SubMenu2(void){ char menu,*name; do{ system("cls"); //清屏,需要使用到stdlib.h puts("\n\t======查找图书信息======\n"); puts("\t 1.图书信息库"); puts("\t 2.书名查找"); puts("\t 3.作者名查找"); puts("\t 4.序号查找"); puts("\t 0.返回主菜单"); puts("\n\t=================="); printf("\t请选择:"); //提示选择 menu=getche(); switch(menu) { case '0': puts("\n\n\t返回主菜单!"); break; case '1': output(b); getch(); break; case '2': //findbook(name,b,key); getch(); break; case '3': case '4': printno(b); break; default: puts("\n\n\t选择错误!"); menu='9'; } }while(menu=='9'); return 20+menu-'0';}
int Menu(void){ char menu; do{ system("cls"); puts("\n\t======主菜单======\n"); puts("\t 1.查找图书信息"); puts("\t 2.更新图书信息"); puts("\t 3.备份图书信息"); puts("\t 0.退出程序"); puts("\n\t=================="); printf("\t请选择:"); //提示选择 menu=getche(); switch(menu) //将用户输入的选项menu转换成系统定义的菜单代码 {
case '0': puts("\n\n\t退出程序!"); menu=menu-'0'; break;
case '2': menu=SubMenu4();
break; case '3': menu=menu-'0';
break; case '1': menu=SubMenu2();
break; default: puts("\n\n\t选择错误!"); menu='9'; //输入了无效的菜单代码,需要重新输入 } }while(menu=='9'); return menu;}
int Load(BOOK b[]){ FILE *fin; int i=0; fin=fopen(fName,"rb"); if(!fin) { printf("\n\t书籍信息不存在,请先新增加图书信息!\n\n按任意键继续……"); getch(); return 0; } while(1) { fread(&b[i],sizeof(BOOK),1,fin); if(feof(fin)) break; i++; } fclose(fin); LEN=i; return i;
}
int Save(BOOK b[])//存入文件 {
int i; //i:b数组的下标 FILE *fp=fopen(fName,"w"); if(!fp) { printf("\n\t不能正确保存书籍信息!按任意键继续……"); getch(); return 0; } fprintf(fp,"书籍编号\t书名\t作者\t类别\t出版单位\t价格"); for( i = 0; i <=count; i++) { fprintf(fp,"\n%s\t%s\t%s\t%s\t%s\t%s",b[i].no,b[i].book_name,b[i].writer,b[i].booknum,b[i].press,b[i].price); } fclose(fp); printf("保存成功!!"); return 1;}
int Copy(void) //备份图书信息,复制图书信息文件{ FILE *fout,*fin; BOOK *p=(BOOK *)malloc(sizeof(BOOK)); //存放从图书信息库读入的临时数据 char name[20];
fin=fopen(fName,"rb"); if(!fin) { printf("\n\t没有此图书信息!"); return 0; }
do{ printf("\n\t请输入备份文件名:"); scanf("%s",name); strcat(name,".bak"); fout=fopen(name,"wb"); if(!fout) printf("\t无效文件名或路径!\n"); }while(!fout);
while(1) { fread(p,sizeof(BOOK),1,fin); if(feof(fin)) break; fwrite(p,sizeof(BOOK),1,fout); }
printf("\n\t备份成功!"); free(p); return 1;}
void findbook(char *name,BOOK b[],char *key){
int i,j; //i:数组下标 j:除姓名为空串以外的实际人数 int p=0; printf("请输入您需要查找图书信息的书名:"); scanf("%s",name); if(strcmp(name,key)!=0) for(i=0,j=0;j<LEN;) { while(strcmp(b[i].book_name ,"")==0) i++; if(strcmp(name,b[i].book_name) ==0) { p=1; printf("\n%s\t%s\t%s\t%s\t%s\t%s",&b[i].no,&b[i].book_name,&b[i].writer,&b[i].booknum,&b[i].press,&b[i].price); } }}
C. C语言程序设计的图书管理系统
我们也开始做课程设计了呢~~~ 这是我同学做的:
#include
#include
#include
struct BOOK
{
int id,usr[10],total,store,days[10];
char name[31],author[21];
}books[100];
/*上面是结构体的定义,用于存放书籍及借书的信息。*/
void page_title(char *menu_item)
{
clrscr();
printf(">>> 图 书 管 理 系 统 <<<\n\n- %s -\n\n",menu_item);
}
/*上面是打印页眉的函数,同时通过参数menu_item,可以显示当前的状态。*/
void return_confirm(void)
{
printf("\n按任意键返回……\n");
getch();
}
/*上面是返回前请求确认的函数,以便在返回前观察结果*/
int search_book(void)
{
int n,i;
printf("请输入图书序号:");
scanf("%d",&i);
for(n=0;n<100;n++)
{
if(books[n].id==i)
{
printf("书名:%s\n",books[n].name);
printf("作者:%s\n",books[n].author);
printf("存数:%d of ",books[n].store);
printf("%d\n",books[n].total);
return n;
}
}
printf("\n输入错误或无效图书序号.\n");
return -1;
}
/*上面的函数是在数组中找到图书号匹配的记录,显示其信息并返
回数组下标,如果找不到相应记录则提示错误并返回-1。*/
void book_out(void)
{
int n,s,l,d;
page_title("借阅图书");
if((n=search_book())!=-1&&books[n].store>0)
{
printf("请输入借书证序号:");
scanf("%d",&s);
printf("请输入可借天数:");
scanf("%d",&d);
for(l=0;l<10;l++)
{
if(books[n].usr[l]==0)
{
books[n].usr[l]=s;
books[n].days[l]=d;
break;
}
}
books[n].store--;
}
if(n!=-1&&books[n].store==0) printf("此书已经全部借出.\n");
return_confirm();
}
/*上面是借书的函数,首先调用找书函数*/
void book_in(void)
{
int n,s,l;
page_title("归还图书");
if((n=search_book())!=-1&&books[n].store<books[n].total)
{
printf("借阅者图书证列表:\n");
for(l=0;l<10;l++)
if (books[n].usr[l]!=0)
printf("[%d] - %d天\n",books[n].usr[l],books[n].days[l]);
printf("请输入借书证序号:");
scanf("%d",&s);
for(l=0;l<10;l++)
{
if(books[n].usr[l]==s)
{
books[n].usr[l]=0;
books[n].days[l]=0;
break;
}
}
books[n].store++;
}
if(n!=-1&&books[n].store==books[n].total)
printf("全部入藏.\n");
return_confirm();
}
void book_add(void)
{
int n;
page_title("注册新书");
for(n=0;n<100;n++)
if(books[n].id==0) break;
printf("序号:");
scanf("%d",&books[n].id);
printf("书名:");
scanf("%s",&books[n].name);
printf("作者:");
scanf("%s",&books[n].author);
printf("数量:");
scanf("%d",&books[n].total);
books[n].store=books[n].total;
return_confirm();
}
void book_del(void)
{
int n;
page_title("注销旧书");
if((n=search_book())!=-1) books[n].id=0;
printf("该书已注销.\n");
return_confirm();
}
void main(void)
{
menu: page_title("操作选单");
printf("请用数字键选择操作\n\n");
printf("1 借阅图书\n2 归还图书\n\n");
printf("3 注册新书\n4 注销旧书\n\n");
printf("\n0 退出\n");
switch(getch())
{
case '1' : book_out();break;
case '2' : book_in();break;
case '3' : book_add();break;
case '4' : book_del();break;
case '0' : exit(0);
}
goto menu;
}
{
int n;
page_title("广?症慕");
if((n=search_book())!=-1) books[n].id=0;
printf("乎慕厮广?.\n");
return_confirm();
}
void main(void)
{
menu: page_title("荷恬佥汽");
printf("萩喘方忖囚佥夲荷恬\n\n");
printf("1 処堋夕慕\n2 拷珊夕慕\n\n");
printf("3 广过仟慕\n4 广?症慕\n\n");
printf("\n0 曜竃\n");
switch(getch())
{
case '1' : book_out();break;
case '2' : book_in();break;
case '3' : book_add();break;
case '4' : book_del();break;
case '0' : exit(0);
}
goto menu;
}
D. 用C语言写个图书馆系统
下面可以参考参考!
完整的C语言图书管理系统
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include "graphics.h"
#include "math.h"
#define m 1
struct data
{ int year;
int month;
int day;
};
struct ReaderNode
{
char num[20];
struct data bro;
struct data back;
};
struct BookNode
{
char title[15];
char writer[15];
int currentnum;
int totalnum;
char brief[30];
struct ReaderNode reader[20];
};
struct TreeNode
{
int n;
struct TreeNode *prt;
int key[2*m];
struct BookNode *rec[2*m];
struct TreeNode *link[2*m+1];
};
struct BookNode *InputNode();
struct TreeNode *mbsearch(struct TreeNode *bth,int x,int *k,int *flag);
struct TreeNode *mbinsert(struct TreeNode *bth);
struct TreeNode *mbdel(struct TreeNode *bth);
void OutputNode(struct TreeNode *bth);
void borrow(struct TreeNode *bth);
void payback(struct TreeNode *bth);
char menu(void);
struct TreeNode *mbsearch(struct TreeNode *bth,int x,int *k,int *flag)
{
struct TreeNode *p,*q;
p=bth; *flag=0; q=p;
while( (p!=NULL) && (*flag==0) )
{
*k=1;q=p;
while( (*k < q->n) && ( q->key[*k-1] < x) ) *k=*k+1;
if( q->key[*k-1]==x) *flag=1;
else if( ( *k==q->n ) && ( q->key[*k-1] < x) ) {p=q->link[*k];p->prt=q;}
else { p=q->link[*k-1]; p->prt=q;*k=*k-1;}
}
return(q);
}
struct TreeNode *mbinsert(struct TreeNode *bth)
{
int flag,j,k,t;
int y,x,z;
struct TreeNode *p,*q,*u,*s;
struct BookNode *r,*l;
clrscr();
printf("\n\tPlease input the book you want to insert: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==1)
{
printf("\n\tHas %d this kind of book,do you want to add another?(y/n)\n",(q->rec[k-1])->totalnum);
z=getch();
if(z=='y'||z=='Y')
{
(q->rec[k-1])->totalnum++; (q->rec[k-1])->currentnum++;
printf("\n\tNow total has %d this kind of book,",(q->rec[k-1])->totalnum);
printf("\n\tand current has %d in the library.",(q->rec[k-1])->currentnum);
}
return(bth);
}
r=InputNode(bth);
if(bth==NULL)
{
bth=p=(struct TreeNode *)malloc(sizeof(struct TreeNode));
p->n=1; p->key[0]=x; p->rec[0]=r;p->prt=NULL;
for(j=1;j<=2*m+1;j++) p->link[j-1]=NULL;
return(p);
}
p=NULL; t=0;
while(t==0)
{
if(k==q->n) {y=x;l=r;u=p;}
else
{
y=q->key[q->n-1]; l=q->rec[q->n-1];u=q->link[q->n];
for(j=(q->n)-1; j>=k+1; j--)
{
q->key[j]=q->key[j-1];q->rec[j]=q->rec[j-1];q->link[j+1]=q->link[j];
}
q->key[k]=x;q->rec[k]=r;q->link[k+1]=p;
if(p!=NULL) p->prt=q;
}
if(q->n<2*m)
{
q->n=(q->n)+1;
t=1;
q->key[(q->n)-1]=y; q->rec[(q->n)-1]=l; q->link[q->n]=u;
if(u!=NULL) u->prt=q;
}
else
{
p=(struct TreeNode *)malloc(sizeof(struct TreeNode));
p->n=m; q->n=m; p->prt=q->prt;
x=q->key[m];r=q->rec[m];
for(j=1;j<=m-1;j++)
{
p->key[j-1]=q->key[m+j];p->rec[j-1]=q->rec[m+j];p->link[j-1]=q->link[m+j];
if(q->link[m+j]!=NULL) (q->link[m+j])->prt=p;
}
p->link[m-1]=q->link[2*m];
p->link[m]=u;
p->key[m-1]=y;
p->rec[m-1]=l;
if(u!=NULL) u->prt=p;
for(j=m+2;j<=2*m+1;j++)
{
q->link[j-1]=NULL;p->link[j-1]=NULL;
}
if(q->prt==NULL)
{
s=(struct TreeNode *)malloc(sizeof(struct TreeNode));
s->key[0]=x; s->rec[0]=r;
s->link[0]=q; s->link[1]=p;
s->n=1; s->prt=NULL; q->prt=s; p->prt=s;
for(j=3;j<=2*m+1;j++) s->link[j-1]=NULL;
bth=s; t=1;
}
else
{
q=q->prt; k=1;
while((k<=q->n)&&(q->key[k-1]<x)) k=k+1;
k=k-1;
}
}
}
return(bth);
}
struct TreeNode *mbdel(struct TreeNode *bth)
{
int flag,j,k,t;
int x,y;
struct TreeNode *u,*s,*p,*q;
struct BookNode *r,*l;
clrscr();
printf("\n\tPlease input the book you want to delete: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==0) { printf("\n\tThe book is not exist!\n"); return(bth);}
p=q->link[k];
if(p!=NULL)
{
while(p->link[0]!=NULL) p=p->link[0];
q->key[k-1]=p->key[0];
q->rec[k-1]=p->rec[0];
k=1;q=p;
}
for(j=k;j<=q->n-1;j++)
{
q->key[j-1]=q->key[j];
q->rec[j-1]=q->rec[j];
}
q->n=q->n-1;
while ((q!=bth)&&(q->n<m))
{
p=q->prt;j=1;
while(p->link[j-1]!=q) j=j+1;
if((j<=p->n)&&((p->link[j])->n>m))
{
s=p->link[j];
y=s->key[0];
l=s->rec[0];
u=s->link[0];
for(k=1;k<=s->n-1;k++)
{
s->key[k-1]=s->key[k];
s->rec[k-1]=s->rec[k];
s->link[k-1]=s->link[k];
}
s->link[s->n-1]=s->link[s->n];
s->link[s->n]=NULL;
s->n=s->n-1; q->n=q->n+1;
q->key[q->n-1]=p->key[j-1];
q->rec[q->n-1]=p->rec[j-1];
q->link[q->n]=u;
p->key[j-1]=y;
p->rec[j-1]=l;
if(u!=NULL) u->prt=q;
}
else if((j>1)&&((p->link[j-2])->n>m))
{
s=p->link[j-2];
q->n=q->n+1;
q->link[q->n]=q->link[q->n-1];
for(k=q->n-1;k>=1;k--)
{
q->key[k]=q->key[k-1];
q->rec[k]=q->rec[k-1];
q->link[k]=q->link[k-1];
}
q->key[0]=p->key[j-2];
q->rec[0]=p->rec[j-2];
u=s->link[s->n];
q->link[0]=u;
if(u!=NULL) u->prt=q;
p->key[j-2]=s->key[s->n-1];
p->rec[j-2]=s->rec[s->n-1];
s->link[s->n]=NULL;
s->n=s->n-1;
}
else
{
if(j==p->n+1)
{ q=p->link[j-2]; s=p->link[j-1]; j=j-1;}
else s=p->link[j];
q->key[q->n]=p->key[j-1];
q->rec[q->n]=p->rec[j-1];
t=q->n+1;
for(k=1;k<=s->n;k++)
{ q->key[t+k-1]=s->key[k-1];
q->rec[t+k-1]=s->rec[k-1];
u=s->link[k-1];
q->link[t+k-1]=u;
if(u!=NULL) u->prt=q;
}
u=s->link[s->n]; q->link[t+s->n]=u;
if(u!=NULL) u->prt=q;
q->n=2*m;
free(s);
for(k=j;k<=p->n-1;k++)
{
p->key[k-1]=p->key[k];
p->rec[k-1]=p->rec[k];
p->link[k]=p->link[k+1];
}
p->n=p->n-1; s=q; q=p;
}
}
if((q==bth)&&(q->n==0))
{ free(bth); bth=s; bth->prt=NULL;
if(s->n==0) {bth=NULL; free(s); }
}
printf("\n\tThe book has been delete !");
return(bth);
}
struct BookNode *InputNode()
{
struct BookNode *p;
int i;
p=(struct BookNode *)malloc(sizeof(struct BookNode));
clrscr();
fflush(stdin);
printf("\n\tInput the title: ");
gets(p->title);
printf("\n\tInput the writer: ");
gets(p->writer);
printf("\n\tInput the book current amount: ");
scanf("%d",&p->currentnum);
printf("\n\tInput the book total amount: ");
scanf("%d",&p->totalnum);
fflush(stdin);
printf("\n\tInput the book brief instruction: ");
gets(p->brief);
for(i=0;i<20;i++)
(p->reader[i]).num[0]='\0';
return(p);
}
void OutputNode(struct TreeNode *bth)
{
struct TreeNode *q;
struct BookNode *p;
int k;
int x;
int flag;
clrscr();
printf("\n\tPlease input the book you want to search: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==1)
{
p=q->rec[k-1];
printf("\n\tTitle: %s",p->title);
printf("\n\tWriter: %s",p->writer);
printf("\n\tCurrentAmount: %d",p->currentnum);
printf("\n\tTotalAmount: %d",p->totalnum);
printf("\n\tBriefIntroction: %s\n",p->brief);
}
else printf("\n\tThis book is not exist!");
}
void borrow(struct TreeNode *bth)
{
struct TreeNode *q;
struct BookNode *p;
struct ReaderNode *r;
int i,k, x, flag,t;
clrscr();
printf("\n\tPlease input the book you want to borrow: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==1)
{
p=q->rec[k-1];
printf("\n\tDo you want this book ?(y/n)");
printf("\n\tTitle: %s",p->title);
printf("\n\tWriter: %s",p->writer);
printf("\n\tCurrentAmount: %d",p->currentnum);
printf("\n\tTotalAmount: %d",p->totalnum);
printf("\n\tBriefIntroction: %s",p->brief);
t=getch();
if(t=='y'||t=='Y')
{
if( (p->currentnum)==0) printf("\n\tSorry,this book has all borrow out...");
else
{
clrscr();
for(i=0;i<20;i++) if( (p->reader[i]).num[0]=='\0') break;
printf("\n\tPlease input your certificate number: ");
scanf("%s",(p->reader[i]).num);
printf("\n\tPlease input the borrow data: ");
printf("\n\tYear: ");
scanf("%d",&((p->reader[i]).bro.year));
printf("\tMonth: ");
scanf("%d",&((p->reader[i]).bro.month));
printf("\tDay: ");
scanf("%d",&((p->reader[i]).bro.day));
printf("\n\tPlease input the payback data: ");
printf("\n\tYear: ");
scanf("%d",&((p->reader[i]).back.year));
printf("\tMonth: ");
scanf("%d",&((p->reader[i]).back.month));
printf("\tDay: ");
scanf("%d",&((p->reader[i]).back.day));
p->currentnum--;
printf("\n\tYou have borrow the book.");}
}
}
else printf("\n\tThis book is not exist!");
}
void payback(struct TreeNode *bth)
{
struct TreeNode *q;
struct BookNode *p;
int i,k, x, flag,t,j;
int year,month,day,d;
float pay;
char temp[20];
clrscr();
printf("\n\tPlease input the book you want to payback: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==1)
{
p=q->rec[k-1];
printf("\n\tDo you want to payback this book ?(y/n)");
printf("\n\tTitle: %s",p->title);
printf("\n\tWriter: %s",p->writer);
printf("\n\tCurrentAmount: %d",p->currentnum);
printf("\n\tTotalAmount: %d",p->totalnum);
printf("\n\tBriefIntroction: %s",p->brief);
t=getch();
if(t=='y'||t=='Y')
{
if( (p->currentnum) >=(p->totalnum) )
printf("\n\tYou want to offer a more book ??\n");
else
{
clrscr();
printf("\n\tPlease input your certificate number: ");
scanf("%s",temp);
j=0;
for(i=0;i<20;i++)
{
if(! (strcmp(temp,(p->reader[i]).num))) {j=1;break;}
}
if(j==0) {printf("\n\tYou haven't borrow this book.");return;}
printf("\n\tToday is:");
printf("\n\tYear: ");
scanf("%d",&year);
printf("\tMonth: ");
scanf("%d",&month);
printf("\tDay: ");
scanf("%d",&day);
d=0;
if(year<(p->reader[i]).back.year) d=1;
if(year<=(p->reader[i]).back.year && month<(p->reader[i]).back.month) d=1;
if(year<=(p->reader[i]).back.year && month<=(p->reader[i]).back.month && day<(p->reader[i]).back.day) d=1;
if(d==0)
{
clrscr();
pay=(year-(p->reader[i]).back.year)*365+(month-(p->reader[i]).back.month)*30+(day-(p->reader[i]).back.day);
printf("\n\tYou borrow this book is in %d-%d-%d",(p->reader[i]).bro.year,(p->reader[i]).bro.month,(p->reader[i]).bro.day);
printf("\n\tYou should pay it back in %d-%d-%d",(p->reader[i]).back.year,(p->reader[i]).back.month,(p->reader[i]).back.day);
printf("\n\tToday is %d-%d-%d",year,month,day);
printf("\n\n\tSo you have go out the payback day");
printf("\n\tYou have to pay %2.1f Yuan.",0.1*pay);
}
(p->reader[i]).num[0]='\0';
p->currentnum++;
printf("\n\tYou have payback the book.");
}
}
}
else printf("\n\tYou want to payback an inexistence book ???");
}
donghua()
{int graphdriver=VGA;
int graphmode=VGAHI;
int i,j;
registerbgidriver(EGAVGA_driver);
initgraph(&graphdriver,&graphmode,"");
clrscr();
for(i=0;i<=150;i+=5)
{setcolor(i);
textbackground(RED);
settextstyle(0,0,2);
outtextxy(100,i+140,"Liberary management System");
delay(10000000);
clrscr();
}
setcolor(RED);
outtextxy(50,200,"Loading");
delay(100000000000);
outtextxy(50,200,"Loading.");
delay(100000000000);
outtextxy(50,200,"Loading..");
delay(100000000000);
outtextxy(50,200,"Loading...");
delay(100000000000);
outtextxy(50,200,"Loading....");
delay(100000000000);
outtextxy(50,200,"Loading.....");
delay(100000000000);
outtextxy(50,200,"Loading......");
delay(100000000000);
outtextxy(50,200,"Loading.......");
delay(100000000000);
outtextxy(50,200,"Loading........");
delay(100000000000);
outtextxy(50,200,"Loading.........");
delay(100000000000);
outtextxy(50,200,"Loading..........");
delay(100000000000);
outtextxy(50,200,"Loading...........");
outtextxy(50,200,"Loading............");
delay(100000000000);
for(i=0;i<=10;i++)
delay(100000000000);
clrscr();
}
char menu(void)
{
clrscr();
window(1,1,80,25);
textmode(MONO);
textbackground(BLACK);
textcolor(5);
printf("\n\t ****************************************************");
printf("\n\t ***** Welcome to Liberary management System *****");
printf("\n\t ****************************************************");
printf("\n\t ****************************************************");
printf("\n\t *1.Add a book *");
printf("\n\t ****************************************************");
printf("\n\t *2.Delete a book *");
printf("\n\t ****************************************************");
printf("\n\t *3.Search a book *");
printf("\n\t ****************************************************");
printf("\n\t *4.Borrow a book *");
printf("\n\t ****************************************************");
printf("\n\t *5.Payback a book *");
printf("\n\t ****************************************************");
printf("\n\t *0.exit *");
printf("\n\t ****************************************************");
printf("\n\t please select: ");
return getch();
}
bofangdonghua()
{int graphdriver=VGA;
int graphmode=VGAHI;
int i,j;
char c;
registerbgidriver(EGAVGA_driver);
initgraph(&graphdriver,&graphmode,"");
/*************shi fou bo fang dong hua?**************/
printf:{setcolor(RED);
settextstyle(3,0,5);
outtextxy(100,30,"bo fang dong hua?");
outtextxy(150,80,"Yes");
outtextxy(300,80,"No");
c=getch();
if(c=='Y'||c=='y')
{donghua();
menu();
}
else
if(c=='N'||c=='n')
menu();
else
{setcolor(GREEN);
settextstyle(3,0,8);
outtextxy(200,240,"Error!");
delay(10000000000);
clrscr();
goto printf;
}
}
/**************************************/
}
void main()
{
char c,t;
int x;
int k,flag,p=1;
struct TreeNode *bth=NULL;
bofangdonghua();
while(1)
{
c=menu();
putch(c);
getch();
switch(c)
{
case '1': bth=mbinsert(bth);
break;
case '2': bth=mbdel(bth);
break;
case '3': OutputNode(bth);
break;
case '4': borrow(bth);
break;
case '5': payback(bth);
break;
case '0': clrscr();
printf("\n\tDo you want to return ?(y/n)");
t=getch();
if(t=='y'||t=='Y') exit(0);
break;
defult :break;
}
printf("\n\tPress any key to the main menu....");
getch();
}
}
E. 图书信息管理系统设计c语言(急求!!!)
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
typedefstructrecord{
chartitle[64];
charauthor[24];
charisbn[24];
doubleprice;
intcopies;
structrecord*next;
}Node,*LinkList,*pNode;
LinkListInitList(){
LinkListhead=(pNode)malloc(sizeof(Node));
head->title[0]='