您好,欢迎来到帮我找美食网。
搜索
您的当前位置:首页图书馆管理系统代码

图书馆管理系统代码

来源:帮我找美食网


图书馆管理系统代码.txt男人偷腥时的智商仅次于爱因斯坦。美丽让男人停下,智慧让男人留下。任何东西都不能以健康做交换。#include

#include

#include

#include

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\以写方式新建并打开 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\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\

printf(\"\\n fflush(stdin);

scanf(\"%s\

printf(\"\\n fflush(stdin);

scanf(\"%s\

printf(\"\\n 请输入图书登陆号:\");

请输入图书书名:\");

请输入图书作者名:\");

请输入图书出版社:\");

fflush(stdin);

scanf(\"%s\

printf(\"\\n 请输入图书出版时间:\");

fflush(stdin);

scanf(\"%s\

printf(\"\\n 请输入图书分类号:\");

fflush(stdin);

scanf(\"%s\

printf(\"\\n 请输入图书价格:\");

fflush(stdin);

scanf(\"%f\

printf(\"\\n\");

p->next=s; /*将新增加的节点添加进链表*/

p=s; /*p指向尾节点,向后移*/

s->next=NULL;

printf(\" ━━━━ 添加成功!━━━━\");

printf(\"\\n fflush(stdin);

scanf(\"%c\

printf(\"\\n\");

if(flag=='N'||flag=='n')

{break;}

else if(flag=='Y'||flag=='y')

{continue;}

}

save(head); /*保存数据至文件*/

继续添加?(Y/N):\");

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\

/*指针从头节点开始移动,遍历至尾结点,查找书目信息*/

while(p->next!= NULL)

{

p=p->next;

if(strcmp(p->bookname,temp)==0)

{

printf(\"\\n图书已找到!\\n\");

printf(\"\\n\");

printf(\"登录号: %s\\\n\

printf(\"书名: %s\\\n\

printf(\"作者名: %s\\\n\

printf(\"出版单位: %s\\\n\

printf(\"出版时间: %s\\\n\

printf(\"分类号: %s\\\n\

printf(\"价格: %.2f\\\n\

}

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\price); /*循环输出表格*/

}

printf(\"┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛\\n\");

printf(\"\\n\");

}

/*修改操作*/

void info_change(struct books_list * head)

{

struct books_list * p;

int panduan=0; /*此变量用于判断是否找到书目*/

char temp[20];

p=head;

printf(\"请输入要修改的书名:\");

scanf(\"%s\

while(p->next!= NULL)

{

p=p->next;

if(strcmp(p->bookname,temp)==0)

{

printf(\"\\n 请输入图书登陆卡号:\");

fflush(stdin);

scanf(\"%s\

printf(\"\\n fflush(stdin);

scanf(\"%s\

printf(\"\\n fflush(stdin);

scanf(\"%s\

printf(\"\\n fflush(stdin);

scanf(\"%s\

请输入图书书名:\");

请输入图书作者名:\");

请输入图书出版社:\");

printf(\"\\n 请输入图书出版时间:\");

fflush(stdin);

scanf(\"%s\

printf(\"\\n fflush(stdin);

scanf(\"%s\

printf(\"\\n fflush(stdin);

scanf(\"%f\

printf(\"\\n\");

panduan=1;

}

}

请输入图书分类号:\");

请输入图书价格:\");

if(panduan==0)

{

printf(\"\\n ━━━━ 没有图录! ━━━━\\n\\n\");

}

return;

}

/*删除操作*/

void DeleteDoc(struct books_list * head)

{

struct books_list *s,*p; /*s为中间变量,p为遍历时使用的指针*/

char temp[20];

int panduan; /*此变量用于判断是否找到了书目*/

panduan=0;

p=s=head;

printf(\" [请输入您要删除的书名]:\");

scanf(\"%s\

/*遍历到尾结点*/

while(p!= NULL)

{

if(strcmp(p->bookname,temp)==0)

{

panduan++;

break;

}

p=p->next;

}

if(panduan==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 图书管理系统 printf(\" ┃ ┗━━━━━━━━━━━━━━━━━━━┛ ┃\\n\");

┃\\n\");

printf(\" ┃ ●[1]图书信息录入 ┃\\n\");

printf(\" ┃ ┃\\n\");

printf(\" ┃ ●[2]图书信息浏览 ┃\\n\");

printf(\" printf(\" printf(\" printf(\" printf(\" printf(\" printf(\" printf(\" printf(\" printf(\" ●[3]图书信息查询 ●[4]图书信息修改 ●[5]图书信息删除 ●[6]退出系统 \\n\");

请选择:\");

┃\\n\");

\\n\");

┃\\n\");

\\n\");

┃\\n\");

\\n\");

┃\\n\");

\\n\");

┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━┛

fflush(stdin);

scanf(\"%c\

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(\" break;

}

else

{

printf(\" break;

}

}

return 0;

━━━━━━━━ 感谢使用图书管理系统 ━━━━━━━━\\n\");

━━━━ 输入错误,请重新输入!━━━━\");

}

8回答者: pjckcs

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- banwoyixia.com 版权所有 湘ICP备2023022004号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务