Ⅰ 如何用c语言编写图书馆管理系统
为什么一定要用C语言呢?
数据库多不好做啊
Ⅱ 用c语言写图书馆管理系统
你不觉得给的悬赏少了点么
新建一个下面的文件 讲这个文件和下面的代码放在一个目录下 表示你的图书数据库信息
lib.txt
1001 1
1 0
c primier
1003 1
1 0
c primier
1002 2
1 0
c++ primier
代码
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>//定义bool类型
#include<string.h>
typedef struct book book;
struct book{
int bid;//书的id
int cid;//category id 所属的书的类别id
char bname[30];
int state;//书的state 0 已借出 1代表还未借出
int stdid;//借书人id 如果未借出 则此项为0
};
//booklist
book lib[100];
int len=0;
//书的类别五类
int category[5]={0};
void init_lib()//讲lib.txt存储的图书馆信息读入内存
{
FILE *fin=fopen("lib.txt","r");
if(!fin)
{
printf("openfile error!\n");
exit(1);
}
len=0;
while(!feof(fin))
{
fscanf(fin,"%d %d",&lib[len].bid,&lib[len].cid);
fscanf(fin,"%d %d",&lib[len].state,&lib[len].stdid);
fgetc(fin);
fgets(lib[len].bname,28,fin);
lib[len].bname[strlen(lib[len].bname)-1]='\0';//去除\n
category[lib[len].cid]++;
len++;
}
fclose(fin);
}
void libprint()//输出图书信息
{
int i;
for(i=0;i<len;i++)
{
printf("书名:%s\n编号:%d \n书目前的所属人(0代表图书馆):%d \n同类别图书共有:%d\n",lib[i].bname,lib[i].bid,lib[i].stdid,category[lib[i].cid]);
printf("-------------------------------------------------------------------------\n");
//printf("%d %d\n%d %d\n%s",lib[i].bid,lib[i].cid,lib[i].state,lib[i].stdid,lib[i].bname);
}
}
bool borrowbook(int bookid,int stdid)//借书
{
int i;
for(i=0;i<len;i++)
{
if(bookid==lib[i].bid&&lib[i].state==1)
{
lib[i].state=0;
category[lib[i].cid]--;
lib[i].stdid=stdid;
return 1;
}else
return 0;
}
return 0;
}
bool returnbook(int bookid,int stdid)//还书
{
int i=0;
for(i=0;i<len;i++)
{
if(bookid==lib[i].bid&&lib[i].state==0&&lib[i].stdid==stdid)
{
lib[i].state=1;
lib[i].stdid=0;
category[lib[i].cid]++;
return 1;
}
}
return 0;
}
void savelib()//将内存的数据写入lib.txt存储起来
{
FILE *fout=fopen("lib.txt","w");
if(!fout)
{
printf("写入失败!\n");
exit(0);
}
int i;
for(i=0;i<len;i++)
{
fprintf(fout,"%d %d\n%d %d\n%s\n",lib[i].bid,lib[i].cid,lib[i].state,lib[i].stdid,lib[i].bname);
}
fclose(fout);
printf("成功写入数据库文件!\n");
}
int main(void)
{
int choice,stdid,bookid;
init_lib();//数据读入内存
while(1)
{
choice=0;
printf("图书馆管理系统\n");
printf("---------------\n");
printf("1-将每本书信息输出\n");
printf("2-借书 \n");
printf("3-还书 \n");
printf("4-save \n");
printf("5-exit without save\n");
printf("---------------------------\n");
scanf("%d",&choice);
printf("---------------------------\n");
if(choice<1||choice>5)
{
printf("检查你的输入!(1,2,3,4,5)\n");
continue;
}
if(choice==1)
libprint();
if(choice==2)
{
printf("输入你要借的书的id和你的studentid(以空格分隔):\n");
scanf("%d %d",&bookid,&stdid);
if(borrowbook(bookid,stdid))
printf("成功借出!\n");
else
printf("借出错误\n");
}
if(choice==3)
{
printf("输入你要还的书的id和你的studentid(以空格分隔):\n");
scanf("%d %d",&bookid,&stdid);
if(returnbook(bookid,stdid))
printf("成功还书\n");
else
printf("还书错误\n");
}
if(choice==4)
{
savelib();
}
if(choice==5)
exit(0);
}
return 0;
}
Ⅲ 如果用C语言编写一个图书馆管理系统,大概需要什么样的主函数求大体的编写步骤
建议采用模块化,自顶向低的编程思路
主函数只负责绘制菜单,根据用户的选择跳入对应功能。
然后各个功能有一个函数单独编写实现,调试,最后组装完成。
如果你的系统需要实现添加、保存、修改、删除、排序等功能,建议采用文件读写
可能会用到如下函数
strcmp(字符串比较函数,用于查找)
fprintf/fscanf/fopen/fclose(文件读写函数)
并且可能会用到结构体数组
如果您有需要,可以私信我,我可以帮您代写。
谢谢
Ⅳ 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;
}
Ⅳ 用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();
}
}
Ⅵ 如何使用C语言编写图书管理系统
图书管理系统是运行于Windows系统下的应用软件,主要用于对图书馆中的图书信息进行增、删、改、查等操作,并且还可对使用该系统的用户进行登录名和密码的管理等。系统给用户提供了一个简单的人机界面,使用户可以根据提示输入操作项,调用系统提供的管理功能。
所需功能类似于学生成绩管理系统,界面可参考附录C。用户分为管理员和一般人员两大类。
功能需求描述如下。
①用户登录:根据用户输入的用户名和密码判断是否允许该用户使用本系统,并且当用户登录后根据用户权限判断用户可以使用哪些功能。学生只有浏览等权限而不能进行实质性改动。
②提供系统主控平台:系统主控平台也应根据用户权限不同而有所区别,只列出在用户权限范围内的功能供用户选择。系统主控平台包括输入功能选项、调用相应程序两大需求。教师和学生对应的系统主控平台是不同的。所能进行的操作也不相同。
③创建图书信息文件:用户根据提示输入图书编号、图书分类号、书名、作者姓名、出版社名、出版年月、定价、存库数量和借阅和上架情况等等信息存储在系统磁盘的文件中。以便进行管理、查找和备份。
④增加图书信息:可在原有图书信息文件的基础上增加新的图书信息记录并继续保存至磁盘,并且将增加后的文件存储状况显示给用户。
⑤删除图书信息:提示用户输入要进行删除操作的图书编号,如果在文件中有该信息存在,则将该书号所对应的记录删除。并选择是否继续进行删除操作。
⑥修改图书信息:提示用户输入要进行修改操作的书号,如果在文件中有该息存在,则将提示用户输入该书号对应的要修改的选项,结果存储于文件。该部分需求也需要提示用户选择是否继续进行修改操作。
⑦查询图书信息:提供按书号或书名等查询。在该功能中,也需提示用户是否需要继续查再继续查找,则返回主界面。
⑧一般用户查询个人的借阅情况并按日期进行排序:。
⑨管理员和一般用户管理:管理员对用户的管理也需要进行用户的创建、增加、删除、浏览。管理员创建的用户存储在名为yonghu的磁盘文件中,每当有用户登录系统时,会根据该文件中的用户名和密码进行核实判断,用户才能够顺利登录。管理员还具有用户的功能。增加的用户及密码、权限等也被继续存储在yonghu文件中。当某些用一用该系统时,还可以进行删除操作,并且管理员具有修改用户权限的功能,一般用户和管理员对于系统的权限是不一样的。
Ⅶ 看不太明白 怎么用C语言编写图书馆管理系统呢
通过c语言中的链表记录图书的信息、修改图书的信息、删除图书的信息、保存图书的信息、输出图书的信息啊、加载图书信息,记录,修改,删除很简单解决,保存的话,就用文件的输入输出就行了,同理就是加载信息,也是用文件的输入输出就行了。然后这些各个功能就单独作为一个函数,然后通过主函数去调用,就行了。
Ⅷ C语言图书管理信息系统
借书的限制:教师180天,借15本;学生120天,借10本
图书的信息:书的编号号,书名,作者,书的种类,书的总量以及书的剩余量
学生/教师信息:学号/工号(4位数字字符),姓名,借书日期,还书日期(以此判定是否超出有效期)
(一)、查询:(无条件或有条件指按所有字段查询)
一、单链表上实现图书信息管理
利用链表结构实现图书存储
二、二叉排序树或平衡树上实现图书信息管理
利用二叉排序树或平衡树实现图书的存储
三、B_树的操作(手工题)
插入、删除操作:
从空的3阶B_树开始,依次插入20,30,50,52,60,68,70,10,80,90,40,75。画出建树过程,然后分别画出删除50,60,10,75,20的B_树状态。
1.课程设计的题目内容要求
2.数据结构的设计思想和任务的总体结构
链接:https://pan..com/s/11BBC4ec7x3l62u83lJeGpw
提取码:1234
Ⅸ 怎样用C语言制作图书馆管理系统
这个是自己写的
注释很清楚地
有什么不清楚的问我
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
struct books_list
{
char author[20]; /*作者名*/
char bookname[20]; /*书名*/
char publisher[20]; /*出版单位*/
char pbtime[15]; /*出版时间*/
char loginnum[10]; /*登陆号*/
float price; /*价格*/
char classfy[10]; /*分类号*/
struct books_list * next; /*链表的指针域*/
};
struct books_list * Create_Books_Doc(); /*新建链表*/
void InsertDoc(struct books_list * head); /*插入*/
void DeleteDoc(struct books_list * head , int num);/*删除*/
void Print_Book_Doc(struct books_list * head);/*浏览*/
void search_book(struct books_list * head); /*查询*/
void info_change(struct books_list * head);/*修改*/
void save(struct books_list * head);/*保存数据至文件*/
/*新建链表头节点*/
struct books_list * Create_Books_Doc()
{
struct books_list * head;
head=(struct books_list *)malloc(sizeof(struct books_list)); /*分配头节点空间*/
head->next=NULL; /*头节点指针域初始化,定为空*/
return head;
}
/*保存数据至文件*/
void save(struct books_list * head)
{
struct books_list *p;
FILE *fp;
p=head;
fp=fopen("data.txt","w+"); /*以写方式新建并打开 data.txt文件*/
fprintf(fp,"┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓\n"); /*向文件输出表格*/
fprintf(fp,"┃登录号┃ 书 名 ┃ 作 者┃ 出版单位 ┃ 出版时间 ┃分类号┃ 价格 ┃\n");
fprintf(fp,"┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫\n");
/*指针从头节点开始移动,遍历至尾结点,依次输出图书信息*/
while(p->next!= NULL)
{
p=p->next;
fprintf(fp,"┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃\n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price);
}
fprintf(fp,"┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛\n");
fclose(fp);
printf(" 已将图书数据保存到 data.txt 文件\n");
}
/*插入*/
void InsertDoc(struct books_list *head)
{
/*定义结构体指针变量 s指向开辟的新结点首地址 p为中间变量*/
struct books_list *s, *p;
char flag='Y'; /*定义flag,方便用户选择重复输入*/
p=head;
/*遍历到尾结点,p指向尾结点*/
while(p->next!= NULL)
{
p=p->next;
}
/*开辟新空间,存入数据,添加进链表*/
while(flag=='Y'||flag=='y')
{
s=(struct books_list *)malloc(sizeof(struct books_list));
printf("\n 请输入图书登陆号:");
fflush(stdin);
scanf("%s",s->loginnum);
printf("\n 请输入图书书名:");
fflush(stdin);
scanf("%s",s->bookname);
printf("\n 请输入图书作者名:");
fflush(stdin);
scanf("%s",s->author);
printf("\n 请输入图书出版社:");
fflush(stdin);
scanf("%s",s->publisher);
printf("\n 请输入图书出版时间:");
fflush(stdin);
scanf("%s",s->pbtime);
printf("\n 请输入图书分类号:");
fflush(stdin);
scanf("%s",s->classfy);
printf("\n 请输入图书价格:");
fflush(stdin);
scanf("%f",&s->price);
printf("\n");
p->next=s; /*将新增加的节点添加进链表*/
p=s; /*p指向尾节点,向后移*/
s->next=NULL;
printf(" ━━━━ 添加成功!━━━━");
printf("\n 继续添加?(Y/N):");
fflush(stdin);
scanf("%c",&flag);
printf("\n");
if(flag=='N'||flag=='n')
{break;}
else if(flag=='Y'||flag=='y')
{continue;}
}
save(head); /*保存数据至文件*/
return;
}
/*查询操作*/
void search_book(struct books_list *head)
{
struct books_list * p;
char temp[20];
p=head;
if(head==NULL || head->next==NULL) /*判断数据库是否为空*/
{
printf(" ━━━━ 图书库为空!━━━━\n");
}
else
{
printf("请输入您要查找的书名: ");
fflush(stdin);
scanf("%s",temp);
/*指针从头节点开始移动,遍历至尾结点,查找书目信息*/
while(p->next!= NULL)
{
p=p->next;
if(strcmp(p->bookname,temp)==0)
{
printf("\n图书已找到!\n");
printf("\n");
printf("登录号: %s\t\n",p->loginnum);
printf("书名: %s\t\n",p->bookname);
printf("作者名: %s\t\n",p->author);
printf("出版单位: %s\t\n",p->publisher);
printf("出版时间: %s\t\n",p->pbtime);
printf("分类号: %s\t\n",p->classfy);
printf("价格: %.2f\t\n",p->price);
}
if(p->next==NULL)
{
printf("\n查询完毕!\n");
}
}
}
return;
}
/*浏览操作*/
void Print_Book_Doc(struct books_list * head)
{
struct books_list * p;
if(head==NULL || head->next==NULL) /*判断数据库是否为空*/
{
printf("\n ━━━━ 没有图书记录! ━━━━\n\n");
return;
}
p=head;
printf("┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓\n");
printf("┃登录号┃ 书 名 ┃ 作 者┃ 出版单位 ┃ 出版时间 ┃分类号┃ 价格 ┃\n");
printf("┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫\n");
/*指针从头节点开始移动,遍历至尾结点,依次输出图书信息*/
while(p->next!= NULL)
{
p=p->next;
printf("┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃\n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price); /*循环输出表格*/
}
printf("┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛\n");
printf("\n");
}
/*修改操作*/
void info_change(struct books_list * head)
{
struct books_list * p;
int panan=0; /*此变量用于判断是否找到书目*/
char temp[20];
p=head;
printf("请输入要修改的书名:");
scanf("%s",temp);
while(p->next!= NULL)
{
p=p->next;
if(strcmp(p->bookname,temp)==0)
{
printf("\n 请输入图书登陆卡号:");
fflush(stdin);
scanf("%s",p->loginnum);
printf("\n 请输入图书书名:");
fflush(stdin);
scanf("%s",p->bookname);
printf("\n 请输入图书作者名:");
fflush(stdin);
scanf("%s",p->author);
printf("\n 请输入图书出版社:");
fflush(stdin);
scanf("%s",p->publisher);
printf("\n 请输入图书出版时间:");
fflush(stdin);
scanf("%s",p->pbtime);
printf("\n 请输入图书分类号:");
fflush(stdin);
scanf("%s",p->classfy);
printf("\n 请输入图书价格:");
fflush(stdin);
scanf("%f",&p->price);
printf("\n");
panan=1;
}
}
if(panan==0)
{
printf("\n ━━━━ 没有图书记录! ━━━━\n\n");
}
return;
}
/*删除操作*/
void DeleteDoc(struct books_list * head)
{
struct books_list *s,*p; /*s为中间变量,p为遍历时使用的指针*/
char temp[20];
int panan; /*此变量用于判断是否找到了书目*/
panan=0;
p=s=head;
printf(" [请输入您要删除的书名]:");
scanf("%s",temp);
/*遍历到尾结点*/
while(p!= NULL)
{
if(strcmp(p->bookname,temp)==0)
{
panan++;
break;
}
p=p->next;
}
if(panan==1)
{
for(;s->next!=p;) /*找到所需删除卡号结点的上一个结点*/
{
s=s->next;
}
s->next=p->next; /*将后一节点地址赋值给前一节点的指针域*/
free(p);
printf("\n ━━━━ 删除成功! ━━━━\n");
}
else /*未找到相应书目*/
{
printf(" 您输入的书目不存在,请确认后输入!\n");
}
return;
}
int main(void)
{
struct books_list * head;
char choice;
head=NULL;
for(;;) /*实现反复输入选择*/
{
printf(" ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n");
printf(" ┃ ┃ socat 图书管理系统 ┃ ┃\n");
printf(" ┃ ┗━━━━━━━━━━━━━━━━━━━┛ ┃\n");
printf(" ┃ ●[1]图书信息录入 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[2]图书信息浏览 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[3]图书信息查询 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[4]图书信息修改 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[5]图书信息删除 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[6]退出系统 ┃\n");
printf(" ┗━━━━━━━━━━━━━━━━━━━━━━━┛\n");
printf(" 请选择:");
fflush(stdin);
scanf("%c",&choice);
if(choice=='1')
{
if(head==NULL)
{
head=Create_Books_Doc();
}
InsertDoc(head);
}
else if(choice=='2')
{
Print_Book_Doc(head);
}
else if(choice=='3')
{
search_book(head);
}
else if(choice=='4')
{
info_change(head);
}
else if(choice=='5')
{
DeleteDoc(head);
}
else if(choice=='6')
{
printf("\n");
printf(" ━━━━━━━━ 感谢使用图书管理系统 ━━━━━━━━\n");
break;
}
else
{
printf(" ━━━━ 输入错误,请重新输入!━━━━");
break;
}
}
return 0;
}
Ⅹ 如何用 C语言做 图书管理系统(要求:不能用链表做)
网上很多的,无非就是结构体,然后赋值问题,指针,主要用这两个多