c++图书管理系统源代码
C图书管理系统源代码
C图书管理系统源代码 Standardization of sany group #QS8QHH-HHGX8Q8-GNHHJ8-HHMHGN#图书管理系统系统功能:1.借书:根据借书人提出的图书编号(id)查询该图书,如果该图书现存量(store)不为0,则提示输入借阅者的学号(num),为借书人办理借书手续,提示用户该书已被借出。
2.归书:根据借书人的学号查询该读者的信息,若有该读者,则提示输入所借书籍的编号(id),为该读者办理还书手续,提示该书已还。
3.书籍管理:弹出书籍管理界面,输入所要执行操作的号码:(1)增加书籍:弹出注册新书的窗口,按照提示输入所增加书籍的信息,最后,提示用户该书已被注册。
(2)删除书籍:弹出删除书籍的窗口,输入所要删除书籍的编号(id),输出该书的信息,确认是否删除该书,1为删除,0为放弃。
(3)修改书籍:弹出修改书籍的窗口,输入所要修改书籍的编号(id),输出该书的信息,确认是否修改该书,1为修改,0为放弃。
之后按照提示重新输入书籍的信息。
4.读者管理:弹出读者管理界面,输入所要执行操作的号码:(1)增加读者:弹出注册读者的窗口,按照提示输入所增加读者的信息,最后,提示用户该读者已被注册。
(2)删除书籍:弹出删除读者的窗口,输入所要删除读者的学号(num),输出该读者的信息,确认是否删除该读者,1为删除,0为放弃。
(3)修改书籍:弹出修改读者的窗口,输入所要修改读者的学号(num),输出该读者的信息,确认是否修改该读者,1为修改,0为放弃。
之后按照提示重新输入读者的信息。
5.搜索:此搜索包括两方面的搜索,书籍搜索以及读者搜索,弹出搜索的窗口,按照提示输入所要搜索的内容,1为书籍搜索,2为读者搜索:(1)搜索书籍:弹出搜索书籍的窗口,按照提示输入所要搜索的方式,包括按<1>书名搜索,<2>书号搜索,<3>作者搜索,<4>出版社搜索,<5>出版时间搜索;根据所选方式输入相应的内容,若是该书籍存在,则输出该书籍的信息,否则,返回主界面。
C语言 图书信息管理系统 最终源代码
C语言图书信息管理系统最终源代码#include<stdio.h>#include"string.h"struct book /* book2 是用来装用户要录入图书的信息*/{long num,time;char name[12],writer[12],fenlei[8],danwei[10];int pay;}stu[100];struct book1{long num,time;char name[12],writer[12],fenlei[8],danwei[10];int pay;}stu1[100];struct book2 /* book 是用来装cc.dat 文件中的图书信息*/{long num,time;char name[12],writer[12],fenlei[8],danwei[10];int pay;}stu2[100];denglu(){char a[15]="drzhang",b[15]="29257966",c[15],d[15];L3:system("cls");printf(" 欢迎登陆图书管理系统\n\n");printf("请输入姓名:");gets(c);printf("请输入密码:");gets(d);if(strcmp(a,c)==0&&strcmp(b,d)==0)return 0;else{printf("输入错误请重新输入\n\n");printf("1.重新输入 2.退出系统\n\n");printf("请输入.....");switch(getch()){case 49: goto L3;break;default: return 56;break;}}}/*此功能实现的是开始菜单的显示和具体功能的选择*/start(){printf("******************************欢迎使用图书管理系统******************************");printf("* 功能目录:*");printf("* |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| *");printf("* || || *");`printf("* || 1、图书查询2、图书浏览3、录入图书4、删除与修改5、备份与还原|| *");printf("* || || *");printf("* || || *");printf("* || || *");printf("* |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| *");printf("* 使用说明:如要选择“图书查询”,直接输入:1 退出:0 *");printf("************************************************************************* *******");printf("你想要做什么:");return getch(); /*输入选择对应功能的值,返回输入的值,即:用于判断选择的功能*/ }/*实现备份功能,以防图书信息出错带来的麻烦,不必看懂*/beifen(){FILE *fp1,*fp2;int i,a;jieshuo();system("cls");printf("\n\n请选择\\ 备份(B)| 浏览备份(L)/ \\ 还原(H)/ \\ 退出(Q)/ \n");switch(getch()){case 'B':case 'b':if((fp1=fopen("cc","r"))==NULL){printf("不能打开次文件\n");exit(0);}if((fp2=fopen("cc01","w"))==NULL){printf("不能打开次文件\n");exit(0);}fscanf(fp1,"%d",&a);fprintf(fp2,"%d\n",a);printf("\n\n确认备份吗?(Y/N)");switch(getch()){case 'Y':case 'y':for(i=0;i<a;i++){fscanf(fp1,"%ld %s %s %s %s %ld %d",&stu[i].num,stu[i].name,stu[i].writer,stu[i].fenlei,stu[i] .danwei,&stu[i].time,&stu[i].pay);fprintf(fp2,"%ld\t%s\t%s\t%s\t%s\t%ld\t%d\n",stu[i].num,stu[i].name,stu[i].writer,stu[i].fenlei,st u[i].danwei,stu[i].time,stu[i].pay);}printf("\n\n备份成功!\n\n是否打开浏览备份文件?(Y/N)");switch(getch()){case 'Y':case 'y':fclose(fp1);fclose(fp2);liulan02();break;case 'N':case 'n':break;}break;case 'N':case 'n':break;}fclose(fp1);fclose(fp2);break;case 'H':case 'h':if((fp1=fopen("cc01","r"))==NULL){printf("不能打开此文件\n");exit(0);}if((fp2=fopen("cc","w"))==NULL){printf("不能打开此文件\n");exit(0);}fscanf(fp1,"%d",&a);fprintf(fp2,"%d\n",a);printf("\n\n确认还原吗?(Y/N)");switch(getch()){case 'Y':case 'y':for(i=0;i<a;i++){fscanf(fp1,"%ld %s %s %s %s %ld %d",&stu[i].num,stu[i].name,stu[i].writer,stu[i].fenlei,stu[i] .danwei,&stu[i].time,&stu[i].pay);fprintf(fp2,"%ld\t%s\t%s\t%s\t%s\t%ld\t%d\n",stu[i].num,stu[i].name,stu[i].writer,stu[i].fenlei,st u[i].danwei,stu[i].time,stu[i].pay);}printf("\n\n还原成功!\n\n是否打开浏览还原文件?(Y/N)");switch(getch()){case 'Y':case 'y':fclose(fp1);fclose(fp2);liulan();break;case 'N':case 'n':break;}break;case 'N':case 'n':break;}fclose(fp1);fclose(fp2);break;case 'l':case 'L':liulan02();break;case 'Q':case 'q':break;}}/* 在屏幕上打印查询菜单*/chaxun(){jieshuo();system("cls");printf("******************************欢迎使用图书查询系统******************************");printf("* 查询方式:*");printf("**");printf("* 1、书名2、作者名3、出版时间*");printf("**");printf("* 4、价格5、分类号6、出版单位*");printf("**");printf("* 使用说明:如要选择“书名”,直接输入:1 退出:0 *");printf("************************************************************************* *******");printf("\n请输入你要怎么查询:");chaxun01(); /*打印完毕后,进入chaxun()函数,执行用户需要的查询功能*/}/*此程序段实行查询的各种功能*/chaxun01(){FILE *fp;char ch[8];int a=0,i,j,k,n=0,c,d;long b;if((fp=fopen("cc","r"))==NULL) /*说明:cc.dat 文件装着图书的信息,*/ {printf("不能打开此文件\n");exit(0);} /*并且文件开记录的是图书的书量,后*/ fscanf(fp,"%d",&a); /*从文件中读出图书数*/ /*面依次才是具体信息。
C语言图书管理系统源代码
#include<stdio。
h〉#include<stdlib。
h〉#include<string.h〉struct tushu{/*图书结构体*/ char num[10];/*编号*/char name[20];/*书名*/char writer[20];/*作者*/char press[20];/*出版社*/char kind[20];/*类别*/double time;/*时间*/double price;/*价格*/struct tushu *next;};struct stu /*学生结构体*/ {int snum;/*学号*/char mima[10]; /*密码*/struct stu *next;};FILE *fp; /*图书文件*/FILE *fp1;/*管理员信息文件*/ FILE *fp2; /*学生信息文件*/void menu(); /*管理员主菜单(管理员进入对图书及学生信息进行管理操作)*/void xmenu();/*学生主菜单(学生进入可对图书,密码进行操作)*/void gfind(); /*管理员查询(管理员可按一定的方式查询图书)*/void xfind(); /*学生查询(学生可按一定的方式查询图书)*/void secret();/*管理员权限(管理员登陆所用,输入错误次数过多自动退出)*/void sort(); /*排序(管理员可按一定的方式对图书进行排序,排序完之后可选择文件进行保存)*/void fprint(struct tushu *head);/*保存(可追加的保存,如添加可用)*/void fprint_(struct tushu *head);/*保存(可覆盖保存如修改,删除,排序后用)*/void hfprint(struct tushu *head); /*还书保存(还书成功后自动保存到文件)*/void jfprint_(struct tushu *head); /*借书保存(借书成功之后自动从图书馆删除)*/struct tushu * Input();/*图书添加(可进行图书的添加)*/struct tushu *create(); /*从文件创建链表(从文件中读出信息,建立单链表)*/void gBrowse(struct tushu *head);/*管理员浏览(对图书进行遍历)*/void xBrowse(struct tushu *head);/*学生浏览(学生对图书进行遍历)*/void count(struct tushu *head);/*统计数量(管理员可对图书进行统计)*/void Findofname(struct tushu *head); /*按书名查找*/ void Findofwriter(struct tushu *head);/*按作者查找*/ void Findofkind(struct tushu *head);/*按类别查找*/ void xFindofname(struct tushu *head); /*学生按书名查找*/void xFindofwriter(struct tushu *head);/*学生按作者查找*/ void xFindofkind(struct tushu *head); /*学生按类别查找*/ void Sort_time(struct tushu * head);/*按时间排序(管理员按时间对图书进行排序,排序完之后可选择文件进行保存)*/ void Sort_price(struct tushu *head); /*按价格排序*/void Sort_num(struct tushu * head);/*按编号排序*/ void Delete(struct tushu * head,char m[15]);/*按编号删除(管理员可按编号删除图书)*/void Revise(struct tushu *head); /*修改(管理员可对图书进行修改,并选择是否保存)*/void borrow(struct tushu *head);/*借书*/void huanshu(); /*还书(学生借完书之后进行还书,若没有图书则不能借)*/void gxinxi(); /*管理员信息(有管理员的账号及密码,可进行修改)*/void xmima(struct stu *head1);/*学生密码修改(学生可对自己的密码进行修改)*/struct stu *xcreate();/*从文件创建学生信息(从文件读出学生信息,建立学生链表)*/void xsecret(struct stu *head1); /*学生权限(学生登陆所用)*/void menu()/*管理员主菜单(管理员进入对图书及学生信息进行管理操作)*/{int choice,n=0;struct tushu *head;struct stu *head1,*p;char m[15];there:printf(”┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n”);printf(” ┃┃socat 图书管理系统┃┃\n”);printf(" ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n”);printf(” ┃●[0]退出系统┃\n");printf(" ┃┃\n");printf(” ┃●[1]帮助┃\n");printf(” ┃┃\n”);printf(" ┃●[2]浏览图书┃\n");printf(” ┃┃\n”);printf(" ┃●[3]统计图书数目┃\n”);printf(” ┃┃\n”);printf(” ┃●[4]查询printf(" ┃┃\n");printf(" ┃●[5]添加┃\n");printf(" ┃┃\n");printf(" ┃●[6]排序┃\n”);printf(” ┃┃\n”);printf(” ┃●[7]修改┃\n”);printf(” ┃┃\n”);printf(” ┃●[8]删除┃\n");printf(" ┃┃\n”);printf(" ┃●[9]修改账号及密码┃\n");print f(” ┃printf(" ┃●[10]学生信息┃\n");printf(" ┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”);printf(” 请选择:");fflush(stdin);head=create();scanf(”%d",&choice);if(choice==1){//help();printf(”没有内容!\n");system(”pause");system("cls”);menu();}else if(choice==2){system("cls");if(head==NULL){printf(”没有图书,请先添加图书!\n");system("pause");system("cls”);menu();}gBrowse(head);}else if(choice==3){system(”cls");count(head);}else if(choice==4){system("cls");if(head==NULL){printf(”没有图书,请先添加图书!\n”);system("pause”);system(”cls”);menu();}gfind();}else if(choice==5){Input();}else if(choice==6){system(”cls”);if(head==NULL){printf(”没有图书,请先添加图书!\n”);system(”pause”);system(”cls”);menu();}sort(head);}else if(choice==7){system(”cls");if(head==NULL){printf("没有图书,请先添加图书!\n");system(”pause”);system("cls");menu();}Revise(head) ;}else if(choice==8){if(head==NULL){printf("没有图书,请先添加图书!\n");system(”pause”);system("cls”);menu();}printf(” 请输入想要删除的图书编号:");scanf(”%s",m);Delete(head,m);}else if(choice==9)gxinxi();}else if(choice==10){system("cls”);head1=xcreate();if(head1==NULL){printf("没有学生信息,请到xuesheng_list。
C语言图书管理系统源代码
C语言图书管理系统源代码Revised by Jack on December 14,2020/*需要在源代码相同目录下创建四个t x t文件:,,,*/#include<>#include<>#include<>struct tushu{ /*图书结构体*/char num[11]; /*编号*/char name[31]; /*书名*/char writer[21]; /*作者*/char press[21]; /*出版社*/char kind[21]; /*类别*/double time; /*时间*/double price; /*价格*/struct tushu *next;};struct stu /*学生结构体*/{int snum; /*学号*/char mima[11]; /*密码*/struct stu *next;};struct jieshu{ /*借书信息结构体*/int xuehao; /*学生学号*/char num[11]; /*编号*/char name[31]; /*书名*/char writer[21]; /*作者*/char press[21]; /*出版社*/char kind[21]; /*类别*/double time; /*时间*/double price; /*价格*/struct jieshu *next;};int denglu=-1; /*已登录学生学号*/FILE *fp; /*图书文件*/FILE *fp1; /*管理员信息文件*/FILE *fp2; /*学生信息文件*/FILE *fp3; /*借书信息文件*/int main(); /*主函数声明*/ struct tushu * create(); /*从文件创建图书链表(从文件中读出图书信息,建立单链表)*/struct stu * xcreate(); /*从文件创建学生信息(从文件读出学生信息,建立学生链表)*/struct jieshu * jcreate(); /2.否):");scanf("%d",&x);if(x==1)fprint(head);else{system("cls");printf("\n\n\n\t\t\t 文件没有被保存!\n\n\n\n");system("pause");system("cls");menu();}}lf %.2lf\n", p1->num,p1->name,p1->writer,p1->press,p1->kind,p1->time,p1->price );/*将图书信息写入文件*/fclose(fp);system("cls");printf("\n 图书信息已成功保存到文件中!\n");system("pause");system("cls");getchar();menu();}lf %.2lf\n", p1->num,p1->name,p1->writer,p1->press,p1->kind,p1->time,p1->price );/*将图书信息写入文件*/fclose(fp);system("cls");printf("\n 图书信息已成功保存到文件 %s 中!\n",a);system("pause");system("cls");menu();}lf %.2lf\n", p1->num,p1->name,p1->writer,p1->press,p1->kind,p1->time,p1->price );/*将图书信息写入文件*/fclose(fp);xmenu();}lf %.2lf\n", p1->num,p1->name,p1->writer,p1->press,p1->kind,p1->time,p1->price );/*将图书信息写入文件*/}fclose(fp);system("cls");getchar();xmenu();}lf %.2lf\n",pj->xuehao,pj->num,pj->name,pj->writer,pj->press,pj->kind,pj->time,pj->price );fclose(fp3);}lf\n", p1->num,p1->name,p1->writer,p1->press,p1->kind,p1->time,p1->price);}system("pause");system("cls");menu();}lf\n", p1->num,p1->name,p1->writer,p1->press,p1->kind,p1->time,p1->price);}system("pause");system("cls");xmenu();}lf\n", p->num,p->name,p->writer,p->press,p->kind,p->time,p->price);i++;}p=p->next;}if(i==0){system("cls");printf("\n 对不起!没有找到名为《%s》的图书!\n",b);system("pause");}printf("\n\n\n\t\t\t是否继续查找图书信息(1.是/其他.返回):");scanf("%d",&n);if(n==1)gfind();else{system("cls");menu();}}lf\n", p->num,p->name,p->writer,p->press,p->kind,p->time,p->price);i++;}p=p->next;}if(i==0){system("cls");printf("\n 对不起!没有找到' %s '所着的相关图书!\n",b);system("pause");}printf("\n\n\n\t\t\t是否继续查找图书信息(1.是/其他.返回):");scanf("%d",&n);if(n==1)gfind();else{system("cls");menu();}}lf\n", p->num,p->name,p->writer,p->press,p->kind,p->time,p->price);i++;}p=p->next;}if(i==0){system("cls");printf("\n 对不起!没有找到类别为' %s '的图书!\n",b);system("pause");}printf("\n\n\n\t\t\t是否继续查找图书信息(1.是/其他.返回):");scanf("%d",&n);if(n==1)gfind();else{system("cls");menu();}}lf\n", p->num,p->name,p->writer,p->press,p->kind,p->time,p->price);i++;}p=p->next;}if(i==0){system("cls");printf("\n 对不起!没有找到名为《%s》的图书!\n",b);system("pause");}printf("\n\n\n\t\t\t是否继续查找图书信息(1.是/其他.返回):");scanf("%d",&n);if(n==1)xfind();else{system("cls");xmenu();}}lf\n", p->num,p->name,p->writer,p->press,p->kind,p->time,p->price);i++;}p=p->next;}if(i==0)system("cls");printf("\n 对不起!没有找到' %s '所着的相关图书!\n",b);system("pause");printf("\n\n\n\t\t\t是否继续查找图书信息(1.是/其他.返回):");scanf("%d",&n);if(n==1)xfind();else{system("cls");xmenu();}}lf\n", p->num,p->name,p->writer,p->press,p->kind,p->time,p->price);i++;}p=p->next;}if(i==0)system("cls");printf("\n 对不起!没有找到类别为' %s '的图书!\n",b);system("pause");printf("\n\n\n\t\t\t是否继续查找图书信息(1.是/其他.返回):");scanf("%d",&n);if(n==1)xfind();else{system("cls");xmenu();}}lf\n", p5->num,p5->name,p5->writer,p5->press,p5->kind,p5->time,p5->price);system("pause");system("cls");printf("\n\n\n\t\t\t是否保存图书信息(1.是/2.否(返回)):");scanf("%d",&x);if(x==1)fprint_(p1);elsesystem("cls");printf("\n\n\n\t\t\t 没有被保存到文件!\n\n\n\n");system("pause");system("cls");menu();return;}lf\n", p5->num,p5->name,p5->writer,p5->press,p5->kind,p5->time,p5->price);system("pause");system("cls");printf("\n\n\n\t\t\t是否保存图书信息(1.是/2.否(返回)):");scanf("%d",&x);if(x==1)fprint_(p1);elsesystem("cls");printf("\n\n\n\t\t\t 没有被保存到文件!\n\n\n\n");system("pause");system("cls");menu();return;}lf\n", p5->num,p5->name,p5->writer,p5->press,p5->kind,p5->time,p5->price);system("pause");system("cls");printf("\n\n\n\t\t\t是否保存图书信息(1.是/2.否(返回)):");scanf("%d",&x);if(x==1)fprint_(p1);elsesystem("cls");printf("\n\n\n\t\t\t 没有被保存到文件!\n\n\n\n");system("pause");system("cls");menu();return;}/2.否(返回)):");scanf("%d",&x);if(x==1)fprint_(head);elsesystem("cls");printf("\n\n\n\t\t\t 并没有被保存到文件!\n\n\n\n");system("pause");system("cls");menu();return;}/2.否(返回)):");scanf("%d",&x);if(x==1)fprint_(head);elsesystem("cls");printf("\n\n\n\t\t\t 没有被保存到文件!\n\n\n\n");system("pause");system("cls");menu();return;}lf %.2lf\n",pj->xuehao,pj->num,pj->name,pj->writer,pj->press,pj->kind,pj->time,pj->price);fclose(fp3);}lf %.2lf\n", h->num,h->name,h->writer,h->press,h->kind,h->time,h->price);fclose(fp);}....\n");getchar();there:fflush(stdin);system("cls");printf("\n\n\n1 :管理员登陆系统\n\n2 :学生登陆系统\n\n0 :退出\n\n\n\n");printf("请选择:");scanf("%d",&i);if(i==0){system("cls");printf("\n\n\n\n****************************************************** ***************************\n");printf(" 感谢使用图书管理系统\n");printf("************************************************************** *******************\n\n\n");system("pause");exit(0);}else if(i==1){system("cls");secret();}else if(i==2){system("cls");head1=xcreate();if(head1==NULL){printf("暂没有学生信息,学生不能登录!\n");system("pause");system("cls");main();}xsecret(head1);}else{printf("\n\n输入错误,请重新输入!\n\n\n");system("pause");system("cls");j++;if(j==3){system("cls");printf("\n\n\n******************************************************** *****************\n\n");printf("\n\n\t\t你输入的次数过多,自动退出!谢谢使用!\n\n");printf("\n\n********************************************************** ***************\n\n");system("pause");exit(0);}goto there;}}。
C 大型实验之图书管理系统源代码(仅供参考)
//===================================
void DBFile::Write_borrowdata_infile(){
ofstream outfile("BorrowData.dat",ios::trunc);
//覆盖写入模式,因为中间有修改变量
infile>>(m->ID);
if((m->ID)[0]=='\0')break;
infile>>(m->Password);
infile>>(m->Name);
infile>>(m->Sex);
if(managers==0)
managers=m;
string bname;//书名
string author;//作者
string press;//出版社
int storenum;//现有藏书量
int borrownum;//借出数
Book *next;
Book();
void print();
};
#endif
//DBFile.h//数据操作类
//====================
#ifndef HEADER_DBFILE
#define HEADER_DBFILE
#include <iostream>
#include <fstream>
#include <string>
#include "Reader.h"
图书管理系统C语言实现源代码
//建立链表,并输入数据 struct book *chu_jian() {
struct book *head,*tail,*p; char num[N],name[M],autor[L],dizhi[K],leixing[E],time[F]; float price;
**********\n");
printf("
图书管理系统
\n");
printf("
0---退出系统
1---录入数据
\n");
printf("
2---保存文件
3---输出信息
\n");
printf("
4--- 根 据 编 号 查 询 信 息
5--- 插 入 数 据
\n");
printf("
6---删除数据
getchar();
} //输出图书的信息 void printf_(struct book *head) {
struct book *p; p=head; if(head!=NULL) {
do {
printf("编号:"); puts(p->num); printf("书名:"); puts(p->name); printf("作者:"); puts(p->autor); printf("出版社:"); puts(p->dizhi); printf("类型:"); puts(p->leixing); printf("时间:"); puts(p->time); printf("价格:"); printf("%f",p->price); printf("\n"); p=p->next; }while(p!=NULL); } getchar(); } //根据图书的编号查询图书的信息,并输出数据 void num_chaxun(struct book *head) { char a[N]; struct book *p;
图书管理系统(源代码)
#include"stdio.h"#include"stdlib.h"#include"string.h"#define MENU_ADMIN_COUNT 2#define MENU_SEARCH_BOOK_COUNT 6 #define MENU_USER_COUNT 7#define BOOK_FILE "books.dat"#define USER_FILE "user.dat"#define MAX_BOOK_NAME 20#define MAX_PUBLISHER 20#define MAX_DATE 10#define MAX_AUTHOR 20#define MAX_ISBN 20typedef struct _book_info{ char book_name[MAX_BOOK_NAME]; char author[MAX_AUTHOR];char publisher[MAX_PUBLISHER];char pub_date[MAX_DA TE];char ISBN[MAX_ISBN];int pages;}book_info;typedef struct _book{ book_info bi;struct _book* next;}book;#define MAX_USERNAME 10#define MAX_PASSWORD 10typedef enum _USER_TYPE{ADMIN=0,USER}USER_TYPE;typedef struct _user_info{char username[MAX_USERNAME];char password[MAX_PASSWORD]; USER_TYPE user_type;}user_info;typedef struct _user{ user_info ui;struct _user* next;}user;void init_user();void load_users();USER_TYPE login();void add_user();void search_user();void save_users();void clear_users();void save_users_to_file();user* get_last_user();user* get_previous_user(user* p);user* find_user(char* name);void show_user(user_info* info);void input_user(user_info* info);void delete_user(user* p);void update_user(user* p);void init_book();void load_books();void add_book();void view_book();void delete_book();void save_books();void clear_books();void search_book_by_name();void search_book_by_author();void search_book_by_publisher();void search_book_by_pubdate();void search_book_by_isbn();int findstr(char *source,char *str);void save_books_to_file();book* get_last_book();book* get_previous_book(book* p);void input_book(book_info* info);void show_book(book_info* info);void show_admin_menu();void show_search_book_menu();void show_user_menu();void admin_exit();void user_exit();book *first_book=NULL;user* first_user=NULL;char menu_title[]="=========================================\n" "| 图书管理系统|\n""+---------------------------------------+\n";char menu_admin[]="| |\n" "| (1)图书管理|\n" "| (2)用户管理|\n" "| (3)退出系统|\n" "+---------------------------------------+\n";char admin_menu1[]="-----------------------------------------\n""| 图书管理|\n" "----------------------------------------|\n""| <1>新增图书|\n" "| <2>浏览图书|\n" "| <3>查找图书|\n" "| <4>删除图书|\n" "| <5>保存图书|\n" "| <0>返回主菜单|\n" "-----------------------------------------\n";char admin_menu2[]="----------------------------------------\n"" 用户管理|\n" "----------------------------------------|\n""| <1>新增用户|\n" "| <2>查找用户|\n" "| <3>保存用户|\n" "| <0>返回主菜单|\n" "|---------------------------------------|\n";void(*menu1_fun[])()={add_book,view_book,show_search_book_menu,delete_book,save_books,};void(*menu2_func[])()={add_user,search_user,save_users,};char menu_admin_search_book[]="| 查找图书:|\n" "| <1>按书名查找|\n" "| <2>按作者查找|\n" "| <3>按出版社查找|\n" "| <4>按出版日期查找|\n" "| <5>按国际标准书号(ISBN)查找|\n" "| <0>返回主菜单|\n" "+--------------------------------------+\n";void (*admin_search_book_func[])()={search_book_by_name,search_book_by_author,search_book_by_publisher,search_book_by_pubdate,search_book_by_isbn,};char menu_user[]="| <1>浏览图书|\n" "| <2>按书名查找图书|\n" "| <3>按作者查找图书|\n" "| <4>按出版社查找图书|\n" "| <5>按出版日期查找图书|\n" "| <6>按国际标准书号(ISBN)查找图书|\n" "| <0>退出系统|\n" "+--------------------------------------+\n";void (*user_func[])()={view_book,search_book_by_name,search_book_by_author,search_book_by_publisher,search_book_by_pubdate,search_book_by_isbn,user_exit};void add_book(){ char try_again='Y';book *p=NULL;book *new_book=NULL;while(try_again=='Y' || try_again=='y'){ new_book=(book*)malloc(sizeof(book));memset(new_book,0,sizeof(book));new_book->next=NULL;printf(">新增图书...\n");input_book(&(new_book->bi));p=get_last_book();if(p==NULL){ first_book=new_book;}else{ p->next=new_book;}printf(">继续添加图书吗?(y or n):");getchar();try_again=getchar();}}void view_book(){ book *p=NULL;char input='Y';int count=0;while(input=='y' || input=='Y'){ count=0;p=first_book;printf("+---------------------------------------+\n");printf("| 书名| 作者|\n");printf("+---------------------------------------+\n");while(p!=NULL){ printf("|%20s|%20s|\n",p->bi.book_name,p->bi.author);printf("+-------------------------------------+\n");count++;if(count==5){ count=0;printf(">显示下一页吗?(y or n):");getchar();input=getchar();if(input!='y' && input!='Y'){ break;}}p=p->next;}printf(">再次浏览图书吗?(y or n):");getchar();input=getchar();}}void search_book_by_name(){ book *p=NULL;char s[MAX_BOOK_NAME]={0};char input='Y';int count=0;int i=0;printf(">查找图书...\n");while(input=='Y' || input=='y'){ count=0;p=first_book;memset(s,0,MAX_BOOK_NAME);printf(">请输入书名(最大长度为%d):",MAX_BOOK_NAME);scanf("%s",s);while(p!=NULL){ if(findstr(p->bi.book_name,s)!=-1){ show_book(&(p->bi));count++;}p=p->next;}if(count==0){ printf(">没有找到图书%s。
c语言图书管理系统源代码
#include <stdio.h>#include <stdlib.h>#include<string.h>typedef struct Books/*图书信息结构体*/{char bookName[21];char auther[21];char bookNumber[16];char publisher[21];int publitionTime;float price;int allNumber;int availableNumber;}Books;void luru();/*录入函数*/void liulan();/*浏览函数*/void chaxunz();/*关键字搜索,如搜"线性代数"可用关键字"线代"*/int bijiao(char a[],char b[]);/*关键字查询主要靠该函数*/void xiushan();/*修改删除函数*/int main(){printf(" ========图书信息管理系统=======\n");int a;char ch='y';/*执行主循环*/while((ch=='y')||(ch=='Y')){printf(" ===============================\n");printf(" *1_信息录入====*====2_信息浏览*\n");printf(" *==============*==============*\n");printf(" *3_信息查询====*====4_信息修删*\n");printf(" ===============================\n");printf("请选择需要的功能\n");scanf("%d",&a);switch(a){case 1:luru();break;case 2:liulan();break;case 3:chaxunz();break;case 4:xiushan();break;default:printf("输入错误\n");break;}printf("是否继续管理:y or n\n");scanf("%c",&ch);scanf("%c",&ch);}}void luru(){Books lurua;int c,b=0;char fileName[31],*name=fileName;printf("请输入管理图书文件名及路径\n");scanf("%s",name);FILE *fp;fp=fopen(name,"a");if(fp==NULL)printf("错误请重新选择\n");elseprintf("请输入入库数量\n");scanf("%d",&c);while(b<c){printf("请输入第%d本图书书名\n",b+1);scanf("%s",lurua.bookName);printf("请输入第%d本图书作者名\n",b+1);scanf("%s",lurua.auther);printf("请输入第%d本图书编号\n",b+1);scanf("%s",lurua.bookNumber);printf("请输入第%d本图书出版单位\n",b+1);scanf("%s",lurua.publisher);printf("请输入第%d本图书出版时间\n",b+1);scanf("%d",&lurua.publitionTime);printf("请输入第%d本图书价格\n",b+1);scanf("%f",&lurua.price);printf("请输入第%d本图书总数量\n",b+1);scanf("%d",&lurua.allNumber);printf("请输入第%d本图书可借出数量\n",b+1);scanf("%d",&lurua.availableNumber);fprintf( fp,"%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",lurua.bookName,lurua.auther,lurua.b ookNumber,lurua.publisher,lurua.publitionTime,lurua.price,lurua.allNumber,lurua.availableNumb er);b=b+1;}fclose(fp);}void liulan(){Books lurua;char fileName[31],*name=fileName;FILE *fp;printf("请输入图书库文件及路径\n");scanf("%s",name);fp=fopen(name,"r");if(fp!=NULL){printf("书名\t\t\t\t作者\t\t编号\t\t出版单位\t\t\t\t出版时间\t\t价格\t总数量\t可借出数量\n");while(!feof(fp)){fscanf(fp,"%s%s%s%s%d%f%d%d\n",lurua.bookName,lurua.auther,lurua.bookNumber,lurua.publi sher,&lurua.publitionTime,&lurua.price,&lurua.allNumber,&lurua.availableNumber);printf("%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",lurua.bookName,lurua.auther,lurua.book Number,lurua.publisher,lurua.publitionTime,lurua.price,lurua.allNumber,lurua.availableNumber);}}else{printf("错误,请重新选择\n");}fclose(fp);}void chaxunz(){char filename[31];printf("请输入图书库文件名及路径(小于30个字符)\n");scanf("%s",filename);FILE *fp;fp=fopen(filename,"r");Books book1;char ch='y';int a;char duqu[21],wenjian[21];/*查询次循环*/while((ch=='y')||(ch=='Y')){printf(" *********************\n");printf(" #1_按书名***2_按作者#\n");printf(" *********************\n");printf("请选择?\n");scanf("%d",&a);printf("请输入关键词;\n");scanf("%s",duqu);printf("书名\t\t\t\t作者\t\t编号\t\t出版单位\t\t\t\t出版时间\t\t价格\t总数量\t 可借出数量\n");switch(a){case 1:{while(!feof(fp)){fscanf(fp,"%s%s%s%s%d%f%d%d\n",book1.bookName,book1.auther,book1.bookNumber,book1. publisher,&book1.publitionTime,&book1.price,&book1.allNumber,&book1.availableNumber);strcpy(wenjian,book1.bookName);if((bijiao(duqu,wenjian))==1)printf("%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",book1.bookName,book1.auther,book1.b ookNumber,book1.publisher,book1.publitionTime,book1.price,book1.allNumber,book1.available Number);}};break;case 2:{while(!feof(fp)){fscanf(fp,"%s%s%s%s%d%f%d%d\n",book1.bookName,book1.auther,book1.bookNumber,book1. publisher,&book1.publitionTime,&book1.price,&book1.allNumber,&book1.availableNumber);strcpy(wenjian,book1.auther);if((bijiao(duqu,wenjian))==1)printf("%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",book1.bookName,book1.auther,book1.b ookNumber,book1.publisher,book1.publitionTime,book1.price,book1.allNumber,book1.available Number);}};break;default:;break;}printf("是否继续查询:y or n");scanf("%c",&ch);scanf("%c",&ch);rewind(fp);}fclose(fp);}int bijiao(char a[],char b[]){char cha[2],chb[2];cha[0]=chb[0]='l';cha[1]=chb[1]='\0';int i=0,n=0,k=0;cha[0]=a[0];chb[0]=b[0];while((cha[0]!='\0')&&(chb[0]!='\0')){if((strcmp(cha,chb))==0){i=i+1;k=k+1;}else{n=n+1;}cha[0]=a[i],chb[0]=b[i+n];}i=0;while(a[i]!='\0')i=i+1;if(i==k)return 1;elsereturn 0;}void xiushan(){FILE *fpa;char bookNumbera[16];int m=0,n,i;Books lurua;char filename[31];printf("请输入库文件名及路径:\n");scanf("%s",filename);fpa=fopen(filename,"r");if(fpa!=NULL){while(!feof(fpa))/*确定书本数*/{fscanf(fpa,"%s%s%s%s%d%f%d%d\n",lurua.bookName,lurua.auther,lurua.bookNumber,lurua.pub lisher,&lurua.publitionTime,&lurua.price,&lurua.allNumber,&lurua.availableNumber);m=m+1;}Books xiushana[m];rewind(fpa);/*全部读取至内存*/for(i=0;i<m;i++){fscanf(fpa,"%s%s%s%s%d%f%d%d\n",xiushana[i].bookName,xiushana[i].auther,xiushana[i].book Number,xiushana[i].publisher,&xiushana[i].publitionTime,&xiushana[i].price,&xiushana[i].allNum ber,&xiushana[i].availableNumber);}/*具体操作*/printf(" *********************\n");printf(" #1_修改*******2_删除#\n");printf(" *********************\n");printf("请选择?\n");scanf("%d",&i);switch(i){case 1:{printf("请输入需修改图书书名\n");scanf("%s",lurua.bookName);printf("请输入需修改图书作者名\n");scanf("%s",lurua.auther);printf("请输入需修改图书编号\n");scanf("%s",lurua.bookNumber);printf("请输入需修改图书出版单位\n");scanf("%s",lurua.publisher);printf("请输入需修改图书出版时间\n");scanf("%d",&lurua.publitionTime);printf("请输入第%d本图书价格\n");scanf("%f",&lurua.price);printf("请输入需修改图书总数量\n");scanf("%d",&lurua.allNumber);printf("请输入需修改图书可借出数量\n");scanf("%d",&lurua.availableNumber);for(i=0;i<m;i++){if((strcmp(lurua.bookNumber,xiushana[i].bookNumber))==0)n=i;}strcpy(xiushana[n].bookName,lurua.bookName);strcpy(xiushana[n].bookNumber,lurua.bookNumber);strcpy(xiushana[n].auther,lurua.auther);strcpy(xiushana[n].publisher,lurua.publisher);xiushana[n].publitionTime=lurua.publitionTime;xiushana[n].price=lurua.price;xiushana[n].allNumber=lurua.allNumber;xiushana[n].availableNumber=lurua.availableNumber;printf("修改成功\n");};break;case 2:{printf("请输入需删图书编号:\n");scanf("%s",bookNumbera);for(i=0;i<m;i++){if(strcmp(bookNumbera,xiushana[i].bookNumber)==0)n=i;}for(i=n;i<m-1;i++){strcpy(xiushana[i].bookName,xiushana[i+1].bookName);strcpy(xiushana[i].bookNumber,xiushana[i+1].bookNumber);strcpy(xiushana[i].auther,xiushana[i+1].auther);strcpy(xiushana[i].publisher,xiushana[i+1].publisher);xiushana[i].publitionTime=xiushana[i+1].publitionTime;xiushana[i].price=xiushana[i+1].price;xiushana[i].allNumber=xiushana[i+1].allNumber;xiushana[i].availableNumber=xiushana[i+1].availableNumber;}fclose(fpa);fpa=fopen(filename,"w");for(i=0;i<m-1;i++)fprintf( fpa,"%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",xiushana[i].bookName,xiushana[i].a uther,xiushana[i].bookNumber,xiushana[i].publisher,xiushana[i].publitionTime,xiushana[i].price,xi ushana[i].allNumber,xiushana[i].availableNumber);printf("删除成功。
C课程设计图书管理系统源代码0204192350
ss,a.time,a.status,a.price,a.count); //-为左对齐,必须是“\n 和+右对齐” ,方便实现 browse()函 数 fclose(fp); } void browse() { FILE *fp; book a={"\0","\0","\0","\0","\0","\0",0.0,0},b=a; if((fp=fopen("bookinf.txt","a+"))==NULL) { printf("file open error!"); exit(0); } fscanf(fp,"%*[^\n]"); //跳过文本的第一行 fscanf(fp,"%*[^\n]%*c");? while(!feof(fp)) { fscanf(fp,"%s%s%s%s%s%s%lf%d",a.num,,a.author,a.press,a.time,a.status,&a.price, &a.count); printf("%-4s%-4s%-4s%-4s%-4s%-4s%-8.2lf%-4d\n",a.num,,a.author,a.press,a.time,a.s tatus,a.price,a.count); a=b; } fclose(fp); } void find() { char str[15]="\0"; FILE *fp; int flag=0; book a={"\0","\0","\0","\0","\0","\0",0.0,0},b=a; printf("请输入所要查找图书的中图分类号:"); scanf("%s",str); if((fp=fopen("bookinf.txt","r"))==NULL) { printf("file open error!\n"); exit(0); } fscanf(fp,"%*[^\n]"); //跳过文本的第一行 fscanf(fp,"%*[^\n]%*c");? while(!feof(fp)) {
c图书管理系统源代码文档
这里是我的毕业设计,用c#编写——学校图书馆管理系统。
全部仿真测试过,毕业论文获得优秀,分享给大家。
1.登陆界面主要代码:public partial class LoginForm : Form{public static string uacc;public static string upsw;public static string uname;public static string usex;public static string upart;public static string uright;public LoginForm(){InitializeComponent();}private void loginbtn_Click(object sender, EventArgs e){if (eracctxt.Text.Trim() == "" && this.pswtxt.Text == ""){MessageBox.Show("请输入您的用户名和密码!", "提示!");return;}try{string sql;sql = "select * from tb_user where uacc='"+ eracctxt.Text + "' and upsw='" + this.pswtxt.Text + "'.feipin100.";OleDbDataReader dr = DBHelp.OleReader(sql);dr.Read();if (dr.HasRows){uacc = eracctxt.Text;upsw = this.pswtxt.Text;uname = dr["uname"].ToString();usex = dr["usex"].ToString();upart = dr["upart"].ToString();uright = dr["uright"].ToString();MainForm af = new MainForm(this);this.Hide();eracctxt.Clear();this.pswtxt.Clear();af.Show();}else{MessageBox.Show("账号或密码错误!", "提示!");eracctxt.Clear();this.pswtxt.Clear();eracctxt.Focus();}}catch (Exception){MessageBox.Show("数据库无法连接!", "警告!");}}private void cancelbtn_Click(object sender, EventArgs e){Application.Exit();}private void LoginForm_Closing(object sender, FormClosingEventArgs e) {Application.Exit();}}2.主界面(图较小,自己可以拉大点)主要代码就不写了,很简单。
C语言图书管理系统代码
#include<stdio.h>欧阳学文#include<stdlib.h>#include<string.h>struct book{int num;char bname[50];char wname[20];char press[50];char sort[50];int time;float price;struct book *next;};struct book *creatbook(); //创建链表struct book *addbook(struct book *head); //添加图书int yanzheng(struct book *head,int m); //验证新添加的图书编码是否已存在void deletebook(struct book *head); //删除图书void fprint(struct book *head); //将链表写入文件struct book *load(); //从文件中读取信息并建成链表void print_book(struct book *head); //将链表信息输出void chaxun(struct book *head); //查询图书信息void num_chaxun(struct book *head); //按图书编号查询图书void wname_chaxun(struct book *head); //按作者名查询图书void sort_chaxun(struct book *head); //按类别查询图书void time_chaxun(struct book *head); //按出版时间查询图书void bname_chaxun(struct book *head); //按图书名查询图书void xiugai(struct book *head); //修改图书信息void paixu(struct book *head); //对图书进行排序void num_paixu(struct book *head); //按图书编号排序void time_paixu(struct book *head); //按图书出版时间排序void price_paixu(struct book *head); //按图书价格排序void bname_paixu(struct book *head); //按图书名排序void wname_paixu(struct book *head); //按作者名排序int main(){int choice,n,x,y=1,c,c1=1234;char a,d,b[10],b1[10]="yjk";struct book *head=NULL;while(y){system("cls");printf("\n\n\n\n\n\n\n");printf(" ********** 欢迎光临**********\n\n");printf(" ********************** 图书信息管理系统 ************************\n\n\n");printf("\n\n");printf(" ============1用户登录===========\n");printf(" ============0退出系统===========\n");printf(" 请输入您的选择:");scanf("%d",&n);printf("\n");getchar();switch(n){case 0:y=0;break;case 1:printf(" 请输入您的用户名:");gets(b);printf("\n");printf(" 请输入您的密码:");scanf("%d",&c);printf("\n");if(strcmp(b,b1)!=0||c!=c1){printf(" 验证失败,请重新输入!\n");scanf("%c",&d);getchar();system("cls");}else{printf(" 验证通过!请按Enter键进入!\n");scanf("%c",&d);getchar();x=1;while(x){system("cls");printf(" \n");printf(" *图书信息管理系统*\n");printf(" \n\n");printf("**********************************************\n\n");printf("**********************************************\n\n");printf(" || 1添加图书 2删除图书 ||\n\n");printf(" || 3图书列表 4图书排序 ||\n\n");printf(" || 5查询图书 6修改图书 ||\n\n");printf(" || 7录入数据 0退出系统 ||\n\n");printf("**********************************************\n\n");printf("**********************************************\n\n");printf("请输入所选择的序号:");scanf("%d",&choice);getchar();system("cls");switch(choice){case 0:x=0;break;case 1:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{head=addbook(head);printf("添加成功!\n");printf("是否将新信息保存到文件?(y/n)\n");scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;}case 2:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{deletebook(head);getchar();break;}break;case 3:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{print_book(head);getchar();break;}case 4:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{paixu(head);getchar();}break;case 5:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{chaxun(head);getchar();}break;case 6:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{xiugai(head);getchar();break;}break;case 7:printf("注意:输入图书编码为0时结束!\n");head=creatbook();printf("是否将输入的信息保存到文件以覆盖文件中已存在的信息?(y/n)\n");getchar();scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;default:printf("您的输入有误,请重新输入!\n");getchar();break;}}}break;default:printf(" 您的输入有误! 请重新输入!\n");getchar();break;}}}//录入数据并形成链表struct book *creatbook(){struct book *head,*tail,*p;int num,time,n;char bname[50],wname[20],press[50],sort[50];float price;int size=sizeof(struct book);head=tail=NULL;printf("请输入图书编号:");scanf("%d",&num);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();while(1){p=(struct book *)malloc(size);p>num=num;strcpy(p>bname,bname);strcpy(p>wname,wname);strcpy(p>press,press);strcpy(p>sort,sort);p>time=time;p>price=price;p>next=NULL;if(head==NULL)head=p;elsetail>next=p;tail=p;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n"); }while(1);if(num==0)break;else{printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();}}return head;}//插入结点,并且插入后仍按一定顺序struct book *addbook(struct book *head){struct book *ptr,*p1,*p2,*p;char bname[50],wname[20],press[50],sort[50];int size=sizeof(struct book);int num,time,n=1;float price;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n");}while(1);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();p=(struct book *)malloc(size); p>num=num;strcpy(p>bname,bname);strcpy(p>wname,wname);strcpy(p>press,press);strcpy(p>sort,sort);p>time=time;p>price=price;p2=head;ptr=p;while((ptr>num>p2>num)&&(p2>next!=NULL)){ p1=p2;p2=p2>next;}if(ptr>num<=p2>num){if(head==p2)head=ptr;else{p1>next=ptr;p>next=p2;}}else{p2>next=ptr;p>next=NULL;}return head;}//验证添加的图书编号是否已存在int yanzheng(struct book *head,int m) {struct book *p;p=head;while(p!=NULL){if(p>num==m)break;p=p>next;}if(p==NULL)return 0;elsereturn 1;}//将新链表写入文件中void fprint(struct book *head){FILE *fp;char ch='1';struct book *p1;if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fputc(ch,fp);for(p1=head;p1;p1=p1>next){fprintf(fp,"%d %s %s %s %s %d %f\n",p1>num,p1>bnam e,p1>wname,p1>press,p1>sort,p1>time,p1>price);}fclose(fp);}//从文件中读取图书信息struct book *load(){FILE *fp;char ch;struct book *head,*tail,*p1;head=tail=NULL;if((fp=fopen("f1.txt","r"))==NULL){printf("File open error!\n");exit(0);}ch=fgetc(fp);if(ch=='1'){while(!feof(fp)){p1=(struct book *)malloc(sizeof(struct book));fscanf(fp,"%d%s%s%s%s%d%f\n",&p1>num,p1>bname,p1>wn ame,p1>press,p1>sort,&p1>time,&p1>price);if(head==NULL)head=p1;elsetail>next=p1;tail=p1;}tail>next=NULL;fclose(fp);return head;}elsereturn NULL;}//将整个链表的信息输出void print_book(struct book *head) {struct book *ptr;if(head==NULL){printf("\n没有信息!\n");return;}printf(" 图书信息列表如下\n");printf("====================================== ====================\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");for(ptr=head;ptr;ptr=ptr>next)printf(" %d %s %s %s %s %d %.2f\n",ptr>num,ptr>bname,ptr>wname,ptr>press,ptr>sort,pt r>time,ptr>price);printf("====================================== ====================\n");}//删除图书信息void deletebook(struct book *head){int a;char b,ch='1';struct book *p1,*p2;FILE *fp;printf("请输入要删除的图书编号:");scanf("%d",&a);p1=head;if(p1>num==a&&p1>next==NULL){ //对于文件中只有一组数据printf("是否清空文件!(y/n)\n");getchar();scanf("%c",&b);getchar();switch(b){case 'n':break;case 'y':if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fclose(fp);printf("文件已清空!\n");}}else{while(p1>num!=a&&p1>next!=NULL){p2=p1;p1=p1>next;}if(p1>next==NULL){if(p1>num==a){p2>next=NULL;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{printf("没有找到要删除的数据!\n");getchar();}}else if(p1==head){head=p1>next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{p2>next=p1>next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}}}//图书查询void chaxun(struct book *head){int a;printf("==========================================================\n");printf(" ** 1按图书编号查询 2按图书名查询 **\n");printf(" ** 3按图书类别查询 4按作者名查询 **\n");printf(" ** 5按出版时间查询 0退出查询**\n");printf("====================================== ====================\n");printf("请输入所选择的编号:");scanf("%d",&a);getchar();switch(a){case 0:break;case 1:num_chaxun(head);break;case 2:bname_chaxun(head);break;case 3:sort_chaxun(head);break;case 4:wname_chaxun(head);break;case 5:time_chaxun(head);break;default:printf("您的输入有误!\n");break;}}//按编号查询图书信息void num_chaxun(struct book *head){int a;struct book *p;printf("请选择您要查询的图书编号:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p>num==a)break;p=p>next;}if(p==NULL){printf("没有找到该编号的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================== ===================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格 **\n");printf("** %d %s %s %s %s %d %.2f **\n",p>num,p>bname,p>wname,p>press,p>sort,p>time,p>pric e);printf("====================================== ===================================\n");}}//按图书名查询图书信息void bname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书名:");gets(a);p=head;while(p!=NULL){if(strcmp(p>bname,a)==0){flag=1;break;}p=p>next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================== ===================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格 **\n");while(p!=NULL){if(strcmp(p>bname,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p>num,p>bname,p>wname,p>press,p>sort,p>time,p>pric e);}p=p>next;}printf("====================================== ===================================\n");}}//按作者名查询图书信息void wname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书作者名:");gets(a);p=head;while(p!=NULL){if(strcmp(p>wname,a)==0){flag=1;break;}p=p>next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================== ===================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格 **\n");while(p!=NULL){if(strcmp(p>wname,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p>num,p>bname,p>wname,p>press,p>sort,p>time,p>pric e);flag=1;}p=p>next;}printf("====================================== ===================================\n");}}//按图书类别查询图书信息void sort_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书类别:");gets(a);p=head;while(p!=NULL){if(strcmp(p>sort,a)==0){flag=1;break;}p=p>next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================== ===================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格 **\n");while(p!=NULL){if(strcmp(p>sort,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p>num,p>bname,p>wname,p>press,p>sort,p>time,p>pric e);flag=1;}p=p>next;}printf("====================================== ===================================\n");}}//按图书出版时间查询图书信息void time_chaxun(struct book *head){int a,flag=0;struct book *p;printf("请选择您要查询的图书出版时间:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p>time==a){flag=1;break;}p=p>next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================== ===================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格 **\n");while(p!=NULL){if(p>time==a){printf("** %d %s %s %s %s %d %.2f **\n",p>num,p>bname,p>wname,p>press,p>sort,p>time,p>pric e);flag=1;}p=p>next;}printf("====================================== ===================================\n");}}//修改图书信息void xiugai(struct book *head){int a,b;char c;struct book *p;printf("请输入要修改的图书编号:");scanf("%d",&a);p=head;while(p!=NULL){if(p>num==a)break;p=p>next;}if(p==NULL){printf("没有找到该编号的图书!\n");getchar();}else{printf("====================================== ======================\n");printf(" ** 1编号2图书名3作者名 **\n");printf(" ** 4出版社5类别6出版时间 **\n");printf(" ** 7价格 8修改全部0放弃修改 **\n");printf("====================================== ======================\n");printf("请选择你要修改的信息编号:");scanf("%d",&b);getchar();switch(b){case 1:printf("请输入新编号:");scanf("%d",&p>num);printf("修改成功!\n");getchar();break;case 2:printf("请输入新图书名:");gets(p>bname);printf("修改成功!\n");break;case 3:printf("请输入新作者名:");gets(p>wname);printf("修改成功!\n");break;case 4:printf("请输入新出版社:");gets(p>press);printf("修改成功!\n");break;case 5:printf("请输入新类别:");gets(p>sort);printf("修改成功!\n");break;case 6:printf("请输入新出版时间:");scanf("%d",&p>time);printf("修改成功!\n");getchar();break;case 7:printf("请输入新价格:");scanf("%f",&p>price);printf("修改成功!\n");getchar();break;case 8:printf("请输入新图书编号:");scanf("%d",&p>num);printf("请输入新图书名:");scanf("%s",p>bname);getchar();printf("请输入新作者名:");scanf("%s",p>wname);getchar();printf("请输入新出版社:");scanf("%s",p>press);getchar();printf("请输入新类别:");scanf("%s",p>sort);getchar();printf("请输入新出版时间:");scanf("%d",&p>time);getchar();printf("请输入新价格:");scanf("%f",&p>price);getchar();printf("修改成功!\n");getchar();break;case 0:break;default :printf("您的输入有误!\n");break;}printf("是否将修改后的信息保存到文件中?(y/n)\n"); scanf("%c",&c);getchar();switch(c){case 'n':break;。
C语言图书管理系统代码(完整资料).doc
【最新整理,下载后即可编辑】#include<stdio.h>#include<stdlib.h>#include<string.h>struct book{int num;char bname[50];char wname[20];char press[50];char sort[50];int time;float price;struct book *next;};struct book *creatbook(); //创建链表struct book *addbook(struct book *head); //添加图书int yanzheng(struct book *head,int m); //验证新添加的图书编码是否已存在void deletebook(struct book *head); //删除图书void fprint(struct book *head); //将链表写入文件struct book *load(); //从文件中读取信息并建成链表void print_book(struct book *head); //将链表信息输出void chaxun(struct book *head); //查询图书信息void num_chaxun(struct book *head); //按图书编号查询图书void wname_chaxun(struct book *head); //按作者名查询图书void sort_chaxun(struct book *head); //按类别查询图书void time_chaxun(struct book *head); //按出版时间查询图书void bname_chaxun(struct book *head); //按图书名查询图书void xiugai(struct book *head); //修改图书信息void paixu(struct book *head); //对图书进行排序void num_paixu(struct book *head); //按图书编号排序void time_paixu(struct book *head); //按图书出版时间排序void price_paixu(struct book *head); //按图书价格排序void bname_paixu(struct book *head); //按图书名排序void wname_paixu(struct book *head); //按作者名排序int main(){int choice,n,x,y=1,c,c1=1234;char a,d,b[10],b1[10]="yjk";struct book *head=NULL;while(y){system("cls");printf("\n\n\n\n\n\n\n");printf(" ********** 欢迎光临**********\n\n");printf(" ********************** 图书信息管理系统************************\n\n\n");printf("\n\n");printf(" ============1-用户登录===========\n");printf(" ============0-退出系统===========\n");printf(" 请输入您的选择:");scanf("%d",&n);printf("\n");getchar();switch(n){case 0:y=0;break;case 1:printf(" 请输入您的用户名:");gets(b);printf("\n");printf(" 请输入您的密码:");scanf("%d",&c);printf("\n");if(strcmp(b,b1)!=0||c!=c1){printf(" 验证失败,请重新输入!\n");scanf("%c",&d);getchar();system("cls");}else{printf(" 验证通过!请按Enter键进入!\n");scanf("%c",&d);getchar();x=1;while(x){system("cls");printf("------------------\n");printf(" *图书信息管理系统*\n");printf("------------------\n\n");printf("**********************************************\n\n");printf("**********************************************\n\n");printf(" || 1-添加图书2-删除图书||\n\n");printf(" || 3-图书列表4-图书排序||\n\n");printf(" || 5-查询图书6-修改图书||\n\n");printf(" || 7-录入数据0-退出系统||\n\n");printf("**********************************************\n\n");printf("**********************************************\n\n");printf("请输入所选择的序号:");scanf("%d",&choice);getchar();system("cls");switch(choice){case 0:x=0;break;case 1:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{head=addbook(head);printf("添加成功!\n");printf("是否将新信息保存到文件?(y/n)\n");scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;}case 2:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{deletebook(head);getchar();break;}break;case 3:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{print_book(head);getchar();break;}case 4:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{paixu(head);getchar();}break;case 5:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{chaxun(head);getchar();}break;case 6:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{xiugai(head);getchar();break;}break;case 7:printf("注意:输入图书编码为0时结束!\n");head=creatbook();printf("是否将输入的信息保存到文件以覆盖文件中已存在的信息?(y/n)\n");getchar();scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;default:printf("您的输入有误,请重新输入!\n");getchar();break;}}}break;default:printf(" 您的输入有误! 请重新输入!\n");getchar();break;}}}//录入数据并形成链表struct book *creatbook(){struct book *head,*tail,*p;int num,time,n;char bname[50],wname[20],press[50],sort[50];float price;int size=sizeof(struct book);head=tail=NULL;printf("请输入图书编号:");scanf("%d",&num);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();while(1){p=(struct book *)malloc(size);p->num=num;strcpy(p->bname,bname);strcpy(p->wname,wname);strcpy(p->press,press);strcpy(p->sort,sort);p->time=time;p->price=price;p->next=NULL;if(head==NULL)head=p;elsetail->next=p;tail=p;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n"); }while(1);if(num==0)break;else{printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();}}return head;}//插入结点,并且插入后仍按一定顺序struct book *addbook(struct book *head){struct book *ptr,*p1,*p2,*p;char bname[50],wname[20],press[50],sort[50];int size=sizeof(struct book);int num,time,n=1;float price;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n"); }while(1);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();p=(struct book *)malloc(size);p->num=num;strcpy(p->bname,bname);strcpy(p->wname,wname);strcpy(p->press,press);strcpy(p->sort,sort);p->time=time;p->price=price;p2=head;ptr=p;while((ptr->num>p2->num)&&(p2->next!=NULL)){ p1=p2;p2=p2->next;}if(ptr->num<=p2->num){if(head==p2)head=ptr;else{p1->next=ptr;p->next=p2;}}else{p2->next=ptr;p->next=NULL;}return head;}//验证添加的图书编号是否已存在int yanzheng(struct book *head,int m){struct book *p;p=head;while(p!=NULL){if(p->num==m)break;p=p->next;}if(p==NULL)return 0;elsereturn 1;}//将新链表写入文件中void fprint(struct book *head){FILE *fp;char ch='1';struct book *p1;if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fputc(ch,fp);for(p1=head;p1;p1=p1->next){fprintf(fp,"%d %s %s %s %s %d %f\n",p1->num,p1->bname,p1->wname,p1->press,p1->sort,p1->time,p1->price);}fclose(fp);}//从文件中读取图书信息struct book *load(){FILE *fp;char ch;struct book *head,*tail,*p1;head=tail=NULL;if((fp=fopen("f1.txt","r"))==NULL){printf("File open error!\n");exit(0);}ch=fgetc(fp);if(ch=='1'){while(!feof(fp)){p1=(struct book *)malloc(sizeof(struct book));fscanf(fp,"%d%s%s%s%s%d%f\n",&p1->num,p1->bname,p1->wna me,p1->press,p1->sort,&p1->time,&p1->price);if(head==NULL)head=p1;elsetail->next=p1;tail=p1;}tail->next=NULL;fclose(fp);return head;}elsereturn NULL;}//将整个链表的信息输出void print_book(struct book *head){struct book *ptr;if(head==NULL){printf("\n没有信息!\n");return;}printf(" 图书信息列表如下\n");printf("========================================= =================\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");for(ptr=head;ptr;ptr=ptr->next)printf(" %d %s %s %s %s %d %.2f\n",ptr->num,ptr->bname,ptr->w name,ptr->press,ptr->sort,ptr->time,ptr->price);printf("========================================= =================\n");}//删除图书信息void deletebook(struct book *head){int a;char b,ch='1';struct book *p1,*p2;FILE *fp;printf("请输入要删除的图书编号:");scanf("%d",&a);p1=head;if(p1->num==a&&p1->next==NULL){ //对于文件中只有一组数据printf("是否清空文件!(y/n)\n");getchar();scanf("%c",&b);getchar();switch(b){case 'n':break;case 'y':if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fclose(fp);printf("文件已清空!\n");}}else{while(p1->num!=a&&p1->next!=NULL){p2=p1;p1=p1->next;}if(p1->next==NULL){if(p1->num==a){p2->next=NULL;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{printf("没有找到要删除的数据!\n");getchar();}}else if(p1==head){head=p1->next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{p2->next=p1->next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}}}//图书查询void chaxun(struct book *head){int a;printf("========================================= =================\n");printf(" ** 1-按图书编号查询2-按图书名查询**\n");printf(" ** 3-按图书类别查询4-按作者名查询**\n");printf(" ** 5-按出版时间查询0-退出查询**\n");printf("========================================= =================\n");printf("请输入所选择的编号:");scanf("%d",&a);getchar();switch(a){case 0:break;case 1:num_chaxun(head);break;case 2:bname_chaxun(head);break;case 3:sort_chaxun(head);break;case 4:wname_chaxun(head);break;case 5:time_chaxun(head);break;default:printf("您的输入有误!\n");break;}}//按编号查询图书信息void num_chaxun(struct book *head){int a;struct book *p;printf("请选择您要查询的图书编号:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p->num==a)break;p=p->next;}if(p==NULL){printf("没有找到该编号的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("========================================= ================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->pri ce);printf("========================================= ================================\n");}}//按图书名查询图书信息void bname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书名:");gets(a);p=head;while(p!=NULL){if(strcmp(p->bname,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}printf(" 你所查询的图书信息如下\n");printf("========================================= ================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->bname,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->pri ce);}p=p->next;}printf("========================================= ================================\n");}}//按作者名查询图书信息void wname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书作者名:");p=head;while(p!=NULL){if(strcmp(p->wname,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("========================================= ================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->wname,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->pri ce);flag=1;}p=p->next;}printf("========================================= ================================\n");}}//按图书类别查询图书信息void sort_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书类别:");gets(a);p=head;while(p!=NULL){if(strcmp(p->sort,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("========================================= ================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->sort,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->pri ce);flag=1;}p=p->next;}printf("========================================= ================================\n");}}//按图书出版时间查询图书信息void time_chaxun(struct book *head){int a,flag=0;struct book *p;printf("请选择您要查询的图书出版时间:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p->time==a){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("========================================= ================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(p->time==a){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->pri ce);flag=1;}p=p->next;}printf("========================================= ================================\n");}}//修改图书信息void xiugai(struct book *head){int a,b;char c;struct book *p;printf("请输入要修改的图书编号:");scanf("%d",&a);p=head;while(p!=NULL){if(p->num==a)break;p=p->next;}if(p==NULL){printf("没有找到该编号的图书!\n");getchar();}else{printf("========================================= ===================\n");printf(" ** 1-编号2-图书名3-作者名**\n");printf(" ** 4-出版社5-类别6-出版时间**\n");printf(" ** 7-价格8-修改全部0-放弃修改**\n");printf("========================================= ===================\n");printf("请选择你要修改的信息编号:");scanf("%d",&b);getchar();switch(b){case 1:printf("请输入新编号:");scanf("%d",&p->num);printf("修改成功!\n");getchar();break;case 2:printf("请输入新图书名:");gets(p->bname);printf("修改成功!\n");break;case 3:printf("请输入新作者名:");gets(p->wname);printf("修改成功!\n");break;case 4:printf("请输入新出版社:");gets(p->press);printf("修改成功!\n");break;case 5:printf("请输入新类别:");gets(p->sort);printf("修改成功!\n");break;case 6:printf("请输入新出版时间:");scanf("%d",&p->time);printf("修改成功!\n");getchar();break;case 7:printf("请输入新价格:");scanf("%f",&p->price);printf("修改成功!\n");getchar();break;case 8:printf("请输入新图书编号:");scanf("%d",&p->num);printf("请输入新图书名:");scanf("%s",p->bname);getchar();printf("请输入新作者名:");scanf("%s",p->wname);getchar();printf("请输入新出版社:");scanf("%s",p->press);getchar();printf("请输入新类别:");scanf("%s",p->sort);getchar();printf("请输入新出版时间:");scanf("%d",&p->time);getchar();printf("请输入新价格:");scanf("%f",&p->price);getchar();printf("修改成功!\n");getchar();break;case 0:break;default :printf("您的输入有误!\n");break;}printf("是否将修改后的信息保存到文件中?(y/n)\n");scanf("%c",&c);getchar();switch(c){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}}}//图书排序void paixu(struct book *head){int a;printf("========================================= =======================\n");printf(" ** 1-按图书编号排序2-按出版时间排序**\n");printf(" ** 3-按图书价格排序4-按图书名排序**\n");printf(" ** 5-按作者名排序0-取消排序操作**\n");printf("========================================= =======================\n");printf("请输入您选择的编号:");scanf("%d",&a);getchar();switch(a){case 0:break;case 1:num_paixu(head);break;case 2:time_paixu(head);break;case 3:price_paixu(head);break;case 4:bname_paixu(head);break;case 5:wname_paixu(head);break;default:printf("您的输入有误!\n");break;}}//按图书编号排序void num_paixu(struct book *head) {struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->num<a[index]->num)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("========================================= =======================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s % d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->t ime,a[i]->price);}printf("========================================= =======================\n");break;default:printf("您的输入有误!\n");break;}}//按出版时间排序void time_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->time<a[index]->time)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s % d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->t ime,a[i]->price);}printf("========================================= ======================\n");break;default:printf("您的输入有误!\n");break;}}//按图书价格排序void price_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->price<a[index]->price)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("========================================= ======================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s % d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->t ime,a[i]->price);}printf("========================================= ======================\n");break;default:printf("您的输入有误!\n");break;}}//按图书名排序void bname_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(strcmp(a[index]->bname,a[i]->bname)>0)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("========================================= ======================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s % d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->t ime,a[i]->price);}printf("========================================= ======================\n");break;default:printf("您的输入有误!\n");break;}}//按作者名排序void wname_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(strcmp(a[index]->wname,a[i]->wname)>0)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("========================================= ======================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s % d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->t ime,a[i]->price);}printf("========================================= ======================\n");break;default:printf("您的输入有误!\n");break;}}【最新整理,下载后即可编辑】。
C语言图书管理系统代码
#include<stdio.h>#include<stdlib.h>#include<string.h>struct book{int num;char bname[50];char wname[20];char press[50];char sort[50];int time;float price;struct book *next;};struct book *creatbook(); //创建链表struct book *addbook(struct book *head); //添加图书int yanzheng(struct book *head,int m); //验证新添加的图书编码是否已存在void deletebook(struct book *head); //删除图书void fprint(struct book *head); //将链表写入文件struct book *load(); //从文件中读取信息并建成链表void print_book(struct book *head); //将链表信息输出void chaxun(struct book *head); //查询图书信息void num_chaxun(struct book *head); //按图书编号查询图书void wname_chaxun(struct book *head); //按作者名查询图书void sort_chaxun(struct book *head); //按类别查询图书void time_chaxun(struct book *head); //按出版时间查询图书void bname_chaxun(struct book *head); //按图书名查询图书void xiugai(struct book *head); //修改图书信息void paixu(struct book *head); //对图书进行排序void num_paixu(struct book *head); //按图书编号排序void time_paixu(struct book *head); //按图书出版时间排序void price_paixu(struct book *head); //按图书价格排序void bname_paixu(struct book *head); //按图书名排序void wname_paixu(struct book *head); //按作者名排序int main(){int choice,n,x,y=1,c,c1=1234;char a,d,b[10],b1[10]="yjk";struct book *head=NULL;while(y){system("cls");printf("\n\n\n\n\n\n\n");printf(" ********** 欢迎光临**********\n\n");printf(" ********************** 图书信息管理系统************************\n\n\n");printf("\n\n");printf(" ============1-用户登录===========\n");printf(" ============0-退出系统===========\n");printf(" 请输入您的选择:");scanf("%d",&n);printf("\n");getchar();switch(n){case 0:y=0;break;case 1:printf(" 请输入您的用户名:");gets(b);printf("\n");printf(" 请输入您的密码:");scanf("%d",&c);printf("\n");if(strcmp(b,b1)!=0||c!=c1){printf(" 验证失败,请重新输入!\n");scanf("%c",&d);getchar();system("cls");}else{printf(" 验证通过!请按Enter键进入!\n");scanf("%c",&d);getchar();x=1;while(x){system("cls");printf(" ------------------\n");printf(" *图书信息管理系统*\n");printf(" ------------------\n\n");printf("**********************************************\n\n");printf("**********************************************\n\n");printf(" || 1-添加图书2-删除图书||\n\n");printf(" || 3-图书列表4-图书排序||\n\n");printf(" || 5-查询图书6-修改图书||\n\n");printf(" || 7-录入数据0-退出系统||\n\n");printf("**********************************************\n\n");printf("**********************************************\n\n");printf("请输入所选择的序号:");scanf("%d",&choice);getchar();system("cls");switch(choice){case 0:x=0;break;case 1:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{head=addbook(head);printf("添加成功!\n");printf("是否将新信息保存到文件?(y/n)\n");scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;}case 2:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{deletebook(head);getchar();break;}break;case 3:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{print_book(head);getchar();break;}case 4:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{paixu(head);getchar();}break;case 5:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{chaxun(head);getchar();}break;case 6:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{xiugai(head);getchar();break;}break;case 7:printf("注意:输入图书编码为0时结束!\n");head=creatbook();printf("是否将输入的信息保存到文件以覆盖文件中已存在的信息?(y/n)\n");getchar();scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;default:printf("您的输入有误,请重新输入!\n");getchar();break;}}}break;default:printf(" 您的输入有误! 请重新输入!\n");getchar();break;}}}//录入数据并形成链表struct book *creatbook(){struct book *head,*tail,*p;int num,time,n;char bname[50],wname[20],press[50],sort[50];float price;int size=sizeof(struct book);head=tail=NULL;printf("请输入图书编号:");scanf("%d",&num);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();while(1){p=(struct book *)malloc(size);p->num=num;strcpy(p->bname,bname);strcpy(p->wname,wname);strcpy(p->press,press);strcpy(p->sort,sort);p->time=time;p->price=price;p->next=NULL;if(head==NULL)head=p;elsetail->next=p;tail=p;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n");}while(1);if(num==0)break;else{printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();}}return head;}//插入结点,并且插入后仍按一定顺序struct book *addbook(struct book *head){struct book *ptr,*p1,*p2,*p;char bname[50],wname[20],press[50],sort[50];int size=sizeof(struct book);int num,time,n=1;float price;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n");}while(1);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();p=(struct book *)malloc(size);p->num=num;strcpy(p->bname,bname);strcpy(p->wname,wname);strcpy(p->press,press);strcpy(p->sort,sort);p->time=time;p->price=price;p2=head;ptr=p;while((ptr->num>p2->num)&&(p2->next!=NULL)){ p1=p2;p2=p2->next;}if(ptr->num<=p2->num){if(head==p2)head=ptr;else{p1->next=ptr;p->next=p2;}}else{p2->next=ptr;p->next=NULL;}return head;}//验证添加的图书编号是否已存在int yanzheng(struct book *head,int m){struct book *p;p=head;while(p!=NULL){if(p->num==m)break;p=p->next;}if(p==NULL)return 0;elsereturn 1;}//将新链表写入文件中void fprint(struct book *head){FILE *fp;char ch='1';struct book *p1;if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fputc(ch,fp);for(p1=head;p1;p1=p1->next){fprintf(fp,"%d %s %s %s %s %d %f\n",p1->num,p1->bname,p1->wname,p1->press,p1->sort ,p1->time,p1->price);}fclose(fp);}//从文件中读取图书信息struct book *load(){FILE *fp;char ch;struct book *head,*tail,*p1;head=tail=NULL;if((fp=fopen("f1.txt","r"))==NULL){printf("File open error!\n");exit(0);}ch=fgetc(fp);if(ch=='1'){while(!feof(fp)){p1=(struct book *)malloc(sizeof(struct book));fscanf(fp,"%d%s%s%s%s%d%f\n",&p1->num,p1->bname,p1->wname,p1->press,p1->sort,&p1-> time,&p1->price);if(head==NULL)head=p1;elsetail->next=p1;tail=p1;}tail->next=NULL;fclose(fp);return head;}elsereturn NULL;}//将整个链表的信息输出void print_book(struct book *head){struct book *ptr;if(head==NULL){printf("\n没有信息!\n");return;}printf(" 图书信息列表如下\n");printf("==========================================================\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");for(ptr=head;ptr;ptr=ptr->next)printf(" %d %s %s %s %s %d %.2f\n",ptr->num,ptr->bname,ptr->wname,ptr->press,ptr->sort,ptr->time,ptr->price);printf("==========================================================\n");}//删除图书信息void deletebook(struct book *head){int a;char b,ch='1';struct book *p1,*p2;FILE *fp;printf("请输入要删除的图书编号:");scanf("%d",&a);p1=head;if(p1->num==a&&p1->next==NULL){ //对于文件中只有一组数据printf("是否清空文件!(y/n)\n");getchar();scanf("%c",&b);getchar();switch(b){case 'n':break;case 'y':if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fclose(fp);printf("文件已清空!\n");}}else{while(p1->num!=a&&p1->next!=NULL){p2=p1;p1=p1->next;}if(p1->next==NULL){if(p1->num==a){p2->next=NULL;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{printf("没有找到要删除的数据!\n");getchar();}}else if(p1==head){head=p1->next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{p2->next=p1->next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}}}//图书查询void chaxun(struct book *head){int a;printf("==========================================================\n");printf(" ** 1-按图书编号查询2-按图书名查询**\n");printf(" ** 3-按图书类别查询4-按作者名查询**\n");printf(" ** 5-按出版时间查询0-退出查询**\n");printf("==========================================================\n");printf("请输入所选择的编号:");scanf("%d",&a);getchar();switch(a){case 0:break;case 1:num_chaxun(head);break;case 2:bname_chaxun(head);break;case 3:sort_chaxun(head);break;case 4:wname_chaxun(head);break;case 5:time_chaxun(head);break;default:printf("您的输入有误!\n");break;}}//按编号查询图书信息void num_chaxun(struct book *head){int a;struct book *p;printf("请选择您要查询的图书编号:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p->num==a)break;p=p->next;}if(p==NULL){printf("没有找到该编号的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);printf("====================================================================== ===\n");}}//按图书名查询图书信息void bname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书名:");gets(a);p=head;while(p!=NULL){if(strcmp(p->bname,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->bname,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);}p=p->next;}printf("====================================================================== ===\n");}}//按作者名查询图书信息void wname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书作者名:");gets(a);p=head;while(p!=NULL){if(strcmp(p->wname,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->wname,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("====================================================================== ===\n");}}//按图书类别查询图书信息void sort_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书类别:");gets(a);p=head;while(p!=NULL){if(strcmp(p->sort,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->sort,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("====================================================================== ===\n");}}//按图书出版时间查询图书信息void time_chaxun(struct book *head){int a,flag=0;struct book *p;printf("请选择您要查询的图书出版时间:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p->time==a){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(p->time==a){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("====================================================================== ===\n");}}//修改图书信息void xiugai(struct book *head){int a,b;char c;struct book *p;printf("请输入要修改的图书编号:");scanf("%d",&a);p=head;while(p!=NULL){if(p->num==a)break;p=p->next;}if(p==NULL){printf("没有找到该编号的图书!\n");getchar();}else{printf("============================================================\n");printf(" ** 1-编号2-图书名3-作者名**\n");printf(" ** 4-出版社5-类别6-出版时间**\n");printf(" ** 7-价格8-修改全部0-放弃修改**\n");printf("============================================================\n");printf("请选择你要修改的信息编号:");scanf("%d",&b);getchar();switch(b){case 1:printf("请输入新编号:");scanf("%d",&p->num);printf("修改成功!\n");getchar();break;case 2:printf("请输入新图书名:");gets(p->bname);printf("修改成功!\n");break;case 3:printf("请输入新作者名:");gets(p->wname);printf("修改成功!\n");break;case 4:printf("请输入新出版社:");gets(p->press);printf("修改成功!\n");break;case 5:printf("请输入新类别:");gets(p->sort);printf("修改成功!\n");break;case 6:printf("请输入新出版时间:");scanf("%d",&p->time);printf("修改成功!\n");getchar();break;case 7:printf("请输入新价格:");scanf("%f",&p->price);printf("修改成功!\n");getchar();break;case 8:printf("请输入新图书编号:");scanf("%d",&p->num);printf("请输入新图书名:");scanf("%s",p->bname);getchar();printf("请输入新作者名:");scanf("%s",p->wname);getchar();printf("请输入新出版社:");scanf("%s",p->press);getchar();printf("请输入新类别:");scanf("%s",p->sort);getchar();printf("请输入新出版时间:");scanf("%d",&p->time);getchar();printf("请输入新价格:");scanf("%f",&p->price);getchar();printf("修改成功!\n");getchar();break;case 0:break;default :printf("您的输入有误!\n");break;}printf("是否将修改后的信息保存到文件中?(y/n)\n");scanf("%c",&c);getchar();switch(c){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}}}//图书排序void paixu(struct book *head){int a;printf("================================================================\n");printf(" ** 1-按图书编号排序2-按出版时间排序**\n");printf(" ** 3-按图书价格排序4-按图书名排序**\n");printf(" ** 5-按作者名排序0-取消排序操作**\n");printf("================================================================\n");printf("请输入您选择的编号:");scanf("%d",&a);getchar();switch(a){case 0:break;case 1:num_paixu(head);break;time_paixu(head);break;case 3:price_paixu(head);break;case 4:bname_paixu(head);break;case 5:wname_paixu(head);break;default:printf("您的输入有误!\n");break;}}//按图书编号排序void num_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->num<a[index]->num)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);switch(b){case 'n':break;case 'y':printf("================================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("================================================================\n");break;default:printf("您的输入有误!\n");break;}}//按出版时间排序void time_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->time<a[index]->time)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("===============================================================\n");break;default:printf("您的输入有误!\n");break;}}//按图书价格排序void price_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->price<a[index]->price)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("===============================================================\n");break;default:printf("您的输入有误!\n");break;}}//按图书名排序void bname_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(strcmp(a[index]->bname,a[i]->bname)>0)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("===============================================================\n");break;default:printf("您的输入有误!\n");break;}}//按作者名排序void wname_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(strcmp(a[index]->wname,a[i]->wname)>0)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("===============================================================\n");break;default:printf("您的输入有误!\n");break;}}。
c_图书管理系统源代码
学计算机的学兄弟姐妹们,下面是我今年的课程设计,做的一个图书馆的管理系统,用c#做的,visual studio2008编写的。
代码经测试全部实现,暂时未发现什么bug,在年纪的评比中得到了第一名的成绩.下面把这些代码分享给你们,希望能对你们有所帮助.1。
登陆界面主要代码:public partial class LoginForm : Form{public static string uacc;public static string upsw;public static string uname;public static string usex;public static string upart;public static string uright;public LoginForm(){InitializeComponent();}private void loginbtn_Click(object sender,EventArgs e){if (this。
useracctxt。
Text。
Trim() == "”&&this.pswtxt.Text == ””){MessageBox。
Show("请输入您的用户名和密码!",”提示!");return;}try{string sql;sql = ”select * from tb_user where uacc='" + this。
useracctxt.Text + "’ and upsw='" + this。
pswtxt.Text + "’";OleDbDataReader dr = DBHelp.OleReader(sql);dr.Read();if(dr。
HasRows){uacc = this。
useracctxt。
Text;upsw = this.pswtxt.Text;uname = dr["uname”].ToString();usex = dr["usex"].ToString();upart = dr[”upart"]。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//本文章来源于网络。
// 图书管理系统.cpp : 定义控制台应用程序的入口点。
////#include "stdafx.h"#include "iostream"#include "fstream"#include "string.h"#include "iomanip"using namespace std;/*int _tmain(int argc, _TCHAR* argv[]){return 0;}*//*int mark0=0;//用于标记是否找到要找的信息int mark1=0;//用于标记是否找到要找的信息*/struct Reathur{//记录书籍的书名信息char bookname[20];//书名struct Reathur* Lnode;//指向下一图书节点};struct Reader{//记录读者信息char Readername[20];//读者名称struct Reathur* next;//指向该读者借的书struct Reader* Lreader,*Right,*Lift;//下一个读者节点};struct Libray{//记录图书的详细信息char bookname[20];//书名char bookno[20];//编号char bookreathur[20];//作者名int booknum;//现有册数struct Libray* Llink,* Rlink,*Lnext;//下一图书的左右节点struct Reader* read;//指向借阅该书的读者};void bsinsert(struct Libray* s,struct Libray* &t)//{将s所指结点插入到根结点指针为t的树中} {if (t==NULL)t=s;elseif(strcmp(s->bookname,t->bookname)==1){bsinsert(s,t->Rlink);}else {bsinsert(s,t->Llink);}}void Rnorder( struct Reader* T){//中序遍历所有的读者链的所有节点if(T!=NULL){Rnorder( T->Lift);struct Reathur* u;u=T->next;cout<<setw(12)<<"读者名称:"<<T->Readername<<"\n";while(u!=NULL){cout<<setw(12)<<"书名:"<<"《"<<u->bookname<<"》"<<"\n";u=u->Lnode;}Rnorder( T->Right);}}/////////////////////////////////////////////////////////////////////////按中序遍历遍历二叉排序树进行检索///////////void Rnorder_name( struct Reader* T,char name[],int &vetex){//中序遍历读者链的所有节点int i=vetex;if(T!=NULL){Rnorder_name( T->Lift,name,i);if(strcmp(T->Readername,name)==0){struct Reathur* u;u=T->next;cout<<setw(12)<<"读者名称:"<<T->Readername<<"\n";while(u!=NULL){cout<<setw(12)<<"书名:"<<"《"<<u->bookname<<"》"<<"\n";u=u->Lnode;}vetex=1;}Rnorder_name( T->Right,name,i);}}/////////////////////////////////////////////////////////////////////////按中序遍历遍历二叉排序树进行检索///////////void Inorder( struct Libray* T){//中序遍历所有的图书节点if(T!=NULL){Inorder( T->Llink);struct Reader* u;u=T->read;cout<<setw(12)<<"书名:"<<"《"<<T->bookname<<"》\n";cout<<setw(12)<<"书目编号:"<<T->bookno<<"\n";cout<<setw(12)<<"作者名称:"<<T->bookreathur<<"\n";while(u!=NULL){cout<<setw(12)<<"读者名称:"<<u->Readername<<"\n";u=u->Lreader;}Inorder( T->Rlink);}}void Inorder_search( struct Libray* T,char bookname[20],int &vetex){//按书名检索int i=vetex;char cname[20];strcpy(cname,bookname);if(T!=NULL){Inorder_search( T->Llink ,cname,i);if(strcmp(cname,T->bookname)==0){struct Reader* u;u=T->read;cout<<setw(12)<<"书名:"<<"《"<<T->bookname<<"》\n";cout<<setw(12)<<"书目编号:"<<T->bookno<<"\n";cout<<setw(12)<<"现有册数:"<<T->booknum<<"\n";cout<<setw(12)<<"作者名称:"<<T->bookreathur<<"\n";while(u!=NULL){cout<<setw(12)<<"读者名称:"<<u->Readername<<"\n";u=u->Lreader;}vetex=1;}Inorder_search( T->Rlink,cname,i);}}void Inorder_searchNo( struct Libray* T,char bookno[20],int &vetex){//按书目编号检索int i=vetex;char cno[20];strcpy(cno,bookno);if(T!=NULL){Inorder_searchNo( T->Llink ,cno,i);if(strcmp(cno,T->bookno)==0){struct Reader* u;u=T->read;cout<<setw(12)<<"书名:"<<"《"<<T->bookname<<"》\n";cout<<setw(12)<<"书目编号:"<<T->bookno<<"\n";cout<<setw(12)<<"作者名称:"<<T->bookreathur<<"\n";while(u!=NULL){cout<<setw(12)<<"读者名称:"<<u->Readername<<"\n";u=u->Lreader;}vetex=1;}Inorder_searchNo( T->Rlink,cno,i);}}struct Libray* sortree(struct Libray* r)//建立一个含有m 个结点的二叉排序树,p为指向二叉树根结点的指针{struct Libray* temp=new struct Libray;struct Libray* p=new struct Libray;struct Libray* q=new struct Libray;if(r->Lnext!=NULL){temp=r->Lnext;strcpy(q->bookname,temp->bookname);strcpy(q->bookno,temp->bookno);strcpy(q->bookreathur,temp->bookreathur);q->booknum=temp->booknum;q->read=temp->read;q->Llink=NULL;q->Rlink=NULL; ;p=q;}temp=temp->Lnext;while(temp!=NULL){struct Libray* q=new struct Libray;strcpy(q->bookname,temp->bookname);strcpy(q->bookno,temp->bookno);strcpy(q->bookreathur,temp->bookreathur);q->booknum=temp->booknum;q->read=temp->read;q->Llink=NULL;q->Rlink=NULL;bsinsert(q,p);temp=temp->Lnext;}return p;}/////////////////////////////////////////////////////////////////////////往二叉排序树中插入记录///////////void Book_insert(struct Libray* &t,char bookname[],char bookno[],char bookreathur[],int booknum){struct Libray* j;int B=1;struct Libray* p=NULL;j=t;while((j!=NULL)&&(B==1)){switch(strcmp(bookname,j->bookname)){case 1:p=j;j=j->Rlink;break;case -1:p=j;j=j->Llink;break;case 0:cout<<"该记录已经存在,无需新建该记录....\n";B=0;break;}}if(B==1) {struct Libray* j=new struct Libray;strcpy(j->bookname,bookname);strcpy(j->bookno,bookno);strcpy(j->bookreathur,bookreathur);j->booknum=booknum;j->Llink=NULL;j->Rlink=NULL;j->read=NULL;if(t==NULL)t=j;if(strcmp(bookname,p->bookname)==1)p->Rlink=j;if(strcmp(bookname,p->bookname)==-1)p->Llink=j;}}/////////////////////////////////////////////////////////////////////////往二叉排序树中删除记录///////////void Book_delete(struct Libray* t,char bookname[])//{j指向被删结点,p指向其双亲,假设树不空}{struct Libray* q,*s;struct Libray* j;struct Libray* p=NULL;int B=1;j=t;while((j!=NULL)&&(B==1)){switch(strcmp(bookname,j->bookname)){case 1:p=j;j=j->Rlink;break;case -1:p=j;j=j->Llink;break;case 0:B=0;break;}}if(B==0) {if(j->Llink==NULL)//{被删结点无左子树}s=j->Rlink;elseif(j->Rlink==NULL)s=j->Llink;else{q=j;s=q->Llink;while(s->Rlink!=NULL){q=s;s=s->Rlink;};s->Rlink=j->Rlink;if (q!=j){q->Rlink=s->Llink;s->Llink=j->Llink;}}if(p==NULL)t=s;elseif (j==p->Llink)p->Llink=s;elsep->Rlink=s;}}//////////////////////////////////////////////////////////////////寻找重复的读者名称////////////////////void search_name(struct Reader* T,char name[],struct Reader* &p){if(T!=NULL){search_name( T->Lift,name,p);if(strcmp(T->Readername,name)==0){p=T;goto mark;}elsep=NULL;search_name( T->Right,name,p);}mark:;}void Rsinsert(struct Reader* s,struct Reader* &t)//{将s所指结点插入到根结点指针为t的树中} {if (t==NULL)t=s;elseif(strcmp(s->Readername,t->Readername)==1){Rsinsert(s,t->Right);}else {Rsinsert(s,t->Lift);}}/////////////////////////////////////////////////////////////////////////建立读者链的二叉排序树///////////struct Reader* Build_reader(struct Libray* book){struct Reader* vetex=new struct Reader;;struct Reader* q;struct Reader* Rroot=new struct Reader;struct Reader* temp=new struct Reader;struct Reathur* u=new struct Reathur;struct Reathur* v;struct Libray* p=new struct Libray;char bname[20];p=book->Lnext;strcpy(u->bookname,p->bookname);u->Lnode=NULL;q=p->read;if(q!=NULL){strcpy(temp->Readername,q->Readername);temp->next=u;temp->Lift=NULL;temp->Right=NULL;}Rroot=temp;q=q->Lreader;while(q!=NULL){struct Reathur* u=new struct Reathur;struct Reader* temp=new struct Reader;u->Lnode=NULL;strcpy(u->bookname,p->bookname);strcpy(temp->Readername,q->Readername);temp->next=u;temp->Lift=NULL;temp->Right=NULL;Rsinsert(temp,Rroot);q=q->Lreader;}p=p->Lnext;while(p!=NULL){q=p->read;while(q!=NULL){search_name(Rroot,q->Readername,vetex);struct Reathur* u=new struct Reathur;strcpy(u->bookname,p->bookname);u->Lnode=NULL;if(vetex!=NULL){u->Lnode=vetex->next;vetex->next=u;q=q->Lreader;continue;}struct Reader* temp=new struct Reader;strcpy(temp->Readername,q->Readername);temp->next=u;temp->Lift=NULL;temp->Right=NULL;Rsinsert(temp,Rroot);q=q->Lreader;}p=p->Lnext;}return Rroot;}////////////////////////////////////////////////////////////////////////////////////寻找读者想借阅的书籍////////////struct Libray* Book_search(struct Libray* &t,char bookname[]){struct Libray* j;struct Libray* p=NULL;int B=1;j=t;while((j!=NULL)&&(B==1)){switch(strcmp(bookname,j->bookname)){case 1:p=j;j=j->Rlink;break;case -1:p=j;j=j->Llink;break;case 0:B=0;break;}}if(B==0&&j->booknum>0){cout<<"已经在到你要寻找的书籍,可以借阅....\n";return j;}if(B==1){cout<<"Sorroy!没有你要寻找的书籍....\n";return NULL;}}////////////////////////////////////////////////////////////////////////////////////寻找读者信息,若无则建立新节点///struct Reader* Reader_sea(struct Reader* &t,char bookname[],char readername[]){ struct Reader* j,*q;struct Reathur* p;int B=1;j=t;while((j!=NULL)&&(B==1)){switch(strcmp(readername,j->Readername)){case 1:q=j;j=j->Right;break;case -1:q=j;j=j->Lift;break;case 0:B=0;break;}}if(B==0){p=j->next;while(p!=NULL){if(strcmp(bookname,p->bookname)==0){cout<<"Sorroy!你已经借阅了该书籍,不能重复借阅....\n";return NULL;}p=p->Lnode;}return j;}else{struct Reader* j=new struct Reader;strcpy(j->Readername,readername);j->Lift=NULL;j->Right=NULL;j->next=NULL;if(t==NULL)t=j;if(strcmp(readername,q->Readername)==1)q->Right=j;if(strcmp(readername,q->Readername)==-1)q->Lift=j;return j;}}/////////////////////////////////////////////////////////////////////////读者借书///////////void Borrow_book(struct Libray* &book,struct Reader* &Readeroot){char Rname[20],Bname[20];struct Libray* p=book;struct Reader* q=Readeroot;struct Libray* u;struct Reader* v;cout<<"请输入用户名!\n";cin>>Rname;cout<<"请输入书籍名!\n";cin>>Bname;u=Book_search(p,Bname);v=Reader_sea(q,Bname,Rname);if(u==NULL){return;}else{if(v==NULL){return;}else{struct Reader* temp=new struct Reader;struct Reathur* tp=new struct Reathur;strcpy(temp->Readername,Rname);u->booknum--;temp->Lreader=u->read;u->read=temp;strcpy(tp->bookname,Bname);tp->Lnode=v->next;v->next=tp;}}}////////////////////////////////////////////////////////////////////////////////////寻找读者想借阅的书籍////////////void B_search(struct Libray* &t,char bookname[],char Rname[]){ struct Libray* j;struct Libray* p=NULL;struct Reader* u,*v;int B=1;j=t;while((j!=NULL)&&(B==1)){switch(strcmp(bookname,j->bookname)){case 1:p=j;j=j->Rlink;break;case -1:p=j;j=j->Llink;break;case 0:B=0;break;}}if(B==0){cout<<"已经找到该书籍的有关记录,更新记录....\n";j->booknum++;u=j->read;if(strcmp(Rname,u->Readername)==0){j->read=u->Lreader;delete(u);return;}v=u;u=u->Lreader;while(u!=NULL){if(strcmp(Rname,u->Readername)==0){v->Lreader=u->Lreader;delete(u);return;}v=u;u=u->Lreader;}if(B==1){cout<<"Sorroy!没有找到该书籍的有关记录....\n";return;}}}//////////////////////////////////////////////////////////寻找读者信息/////////////void R_sea(struct Reader* &t,char readername[],char bname[]){ struct Reader* j,*s,*q;struct Reathur* v,*u;struct Reader* p=NULL;int B=1;j=t;while((j!=NULL)&&(B==1)){switch(strcmp(readername,j->Readername)){case 1:p=j;j=j->Right;break;case -1:p=j;j=j->Lift;break;case 0:B=0;break;}}if(B==0){cout<<"已经找到该读者的有关记录,更新记录....\n";u=j->next;if(strcmp(bname,u->bookname)==0){if(u->Lnode==NULL){if(j->Lift==NULL)//{被删结点无左子树}s=j->Right;elseif(j->Right==NULL)s=j->Lift;else{q=j;s=q->Lift;while(s->Right!=NULL){q=s;s=s->Right;};s->Right=j->Right;if (q!=j){q->Right=s->Lift;s->Lift=j->Lift;}}if(p==NULL)t=s;elseif (j==p->Lift)p->Lift=s;elsep->Right=s;}elsej->next=u->Lnode;delete(u);return;}else{v=u;u=u->Lnode;while(u!=NULL){if(strcmp(bname,u->bookname)==0){v->Lnode=u->Lnode;delete(u);return;}u=u->Lnode;}}}else{cout<<"Sorroy!没有找到该读者的有关记录....\n";return;}}///////////////////////////////////////////////////////////读者还书/////////////////////////void Return_book(struct Libray* &book,struct Reader* &Readeroot){ char Rname[20],Bname[20];struct Libray* p=book;struct Reader* q=Readeroot;cout<<"请输入用户名!\n";cin>>Rname;cout<<"请输入书籍名!\n";cin>>Bname;B_search(p,Bname,Rname);R_sea(q,Rname,Bname);}/////////////////////////////////////////////////////////////////////////将新纪录写入到文件当中///////////void write_file(struct Libray* &T){int i;struct Libray* p=new struct Libray;struct Libray* s[50];fstream ofile;ofile.open("C:\\Documents and Settings\\dufan\\My Documents\\Visual Studio 2008\\Projects\\mdata.txt",ios::out);if(!ofile){cout<<"The file can not open!\n";return;}if(T==NULL)return;else {i=0;p=T;}do{while(p!=NULL){i=i+1;s[i]=p;p=p->Llink;}if(i!=0){p=s[i];i=i-1;struct Reader* u;u=p->read;ofile<<"书名:"<<p->bookname<<"\n";ofile<<"书目编号:"<<p->bookno<<"\n";ofile<<"作者名称:"<<p->bookreathur<<"\n";ofile<<"现有册数:"<<p->booknum<<"\n";while(u!=NULL){ofile<<"借阅读者:"<<u->Readername<<"\n";u=u->Lreader;}p=p->Rlink;}}while (i!=0 || p!=NULL);}int main(){char ch;int cnum,i=0;char temp[5],cname[20],cno[20],creathur[20],cborrow[20];struct Libray* book=new struct Libray;struct Libray* p;struct Reader* r=new struct Reader;//用于指向读者链struct Reader* Readeroot=new struct Reader;//用于指向读者链二叉排序树fstream ifile;ifile.open("C:\\Documents and Settings\\dufan\\My Documents\\Visual Studio 2008\\Projects\\mdata.txt",ios::in);if(!ifile){cout<<"The file can not open!\n";return 0;}p=book;while(!ifile.eof()){struct Libray* booktemp=new struct Libray;struct Reader* rtemp;rtemp=r;ifile.ignore(20,':');ifile.getline(cname,20);strcpy(booktemp->bookname,cname);//读取书籍名称ifile.ignore(20,':');ifile.getline(cno,20);strcpy(booktemp->bookno,cno);//读取书籍编号ifile.ignore(20,':');ifile.getline(creathur,20);strcpy(booktemp->bookreathur,creathur);//读取作者名称ifile.ignore(20,':');ifile.getline(temp,20);cnum=atol(temp);booktemp->booknum=cnum;//读取现有册数while(ifile.get(ch)){//读取借阅者名称if((int)ch==-54)break;ifile.ignore(20,':');struct Reader* q=new struct Reader;//读者节点ifile.getline(cborrow,20);strcpy(q->Readername,cborrow);//读取读者姓名q->Lreader=NULL;rtemp->Lreader=q;rtemp=rtemp->Lreader;}booktemp->read=r->Lreader;booktemp->Lnext=NULL;p->Lnext=booktemp;p=p->Lnext;}ifile.close();delete(r);Readeroot=Build_reader(book);book=sortree(book);//Inorder(book);//Rnorder(Readeroot);int fun;while(1){cout<<"/********** 图书管理系统功能说明表**********\n";cout<<"/** 1添加新书\n";cout<<"/** 2删除旧书\n";cout<<"/** 3按书名检索\n";cout<<"/** 4按书目编号检索\n";cout<<"/** 5查询读者信息\n";cout<<"/** 6读者借书\n";cout<<"/** 7读者还书\n";cout<<"/** 8更新文件记录\n";cout<<"/** 0退出图书管理系统\n";cout<<"/** 请选择要执行的操作\n";cin>>fun;switch(fun){case 1:cout<<"/** 请依次输入书名,书目编号,作者名称,现有册数,并用空格隔开!\n";cin>>cname;cin>>cno;cin>>creathur;cin>>cnum;Book_insert(book,cname,cno,creathur,cnum);break;case 2:cout<<"/** 请输入书名:";cin>>cname;Book_delete(book,cname);break;case 3:cout<<"/** 请输入书名:";cin>>cname;//Inorder(book);Inorder_search( book,cname,i);if(i!=1){cout<<"没有找到符合条件的信息,是否要新建该记录....\n\n";}break;case 4:cout<<"/** 请输入书目编号:";cin>>cno;Inorder_searchNo( book,cno,i);//cout<<i;if(i!=1){cout<<"没有找到符合条件的信息,是否要新建该记录....\n\n";}break;case 5:cout<<"/** 请输入读者名:";cin>>cname;Rnorder_name(Readeroot,cname,i);if(i!=1){cout<<"没有找到符合条件的信息,是否要新建该记录....\n\n";}break;case 6:Borrow_book(book,Readeroot);break;case 7:Return_book(book,Readeroot);break;case 8:write_file(book);cout<<"更新成功!\n";break;case 0:exit(0);break;}}}。