C语言图书管理系统代码

合集下载

C语言课程设计图书馆管理系统程序代码

C语言课程设计图书馆管理系统程序代码

#include〈stdio.h〉#include<windows.h〉#include〈string。

h〉#include<conio。

h>#define M 100struct books{char tsmc[12];inttsbh;float dj;char zz[12];char czzt[12];char xm[12];char xb[12];intxh; }s[M];int N;bool flag;intmain (){intsele;flag=0;sele=1;void sr();void cx();void sc();void js();void hs();void tc();void jsh();//system ("tsgl”);printf("\n\n");printf(" ************************\n"); printf(" 1:输入2:查询3:删除\n");printf(”4:借书5:还书0:退出\n");printf(” ************************\n"); while(1){printf(”\n\n请输入功能序号:");scanf (”%d",&sele);if(sele>=0 && sele<=5){switch(sele){case 1:sr();break;case 2:cx();break;case 3:sc();break;case 4:js();break;case 5:hs();break;case 0:jsh();break;}if(flag)break;printf(”\n\n");printf(” ************************\n”); printf(" 1:输入2:查询3:删除\n");printf(”4:借书5:还书0:退出\n”);printf(” ************************\n”);}else{printf(”输入错误请再次输入|\n\n");printf("\n\n");printf(” ************************\n”);printf(" 1:输入2:查询3:删除\n”);printf(”4:借书5:还书0:退出\n");printf(" ************************\n");}printf("\n\n让任意键继续\n”);} //wr_file();}/******主函数***//*********输入*********/void sr(){intn,i;N=0;printf("可输入的书本数:");scanf("%d",&n);N=n+N;printf("请输入相关信息:\n");for(i=1;i<=n;i++){printf(”图书名称:”);scanf(”%s",s[N-n-1+i]。

图书管理系统c代码

图书管理系统c代码

#include <iostream> #include <iomanip>#include <string>#include <fstream>using namespace std;const int Reader=100;const int Maxb=100;const int Bor=5;class Student{private:int tag;int number;char name[10];int borbook[Bor];public:Student() { }char *getname(){return name;}int gettag(){return tag;}int getnumber(){return number;}void setname(char *na){strcpy(name,na);}void delbook(){tag=1;}void addStudent(int n,char *na) {tag=0;number=n;strcpy(name,na);for(int i=0;i<Bor;i++)borbook[i]=0;}void borrowbook(int bookid)//借书操作{for(int i=0;i<Bor;i++){if (borbook[i]==0){borbook[i]=bookid;return;}}}int retbook(int bookid)//还书操作{for(int i=0;i<Bor;i++){if(borbook[i]==bookid){borbook[i]=0;return 1;}}return 0;}void output()//读出读者信息{cout << setw(5) << number <<setw(10) << name<<"借书编号:["; for(int i=0;i<Bor;i++)if(borbook[i]!=0)cout << borbook[i] << "|";cout << "]"<<endl;}};class RData{private:int top; //读者记录指针Student read[Reader];public:RData() //构造函数,将Student.txt读到read[]中Student s;top=-1;fstream file("Student.txt",ios::in);//打开一个输入文件while (1){file.read((char *)&s,sizeof(s));if (!file)break;top++;read[top]=s;}file.close();}void clear(){top=-1;}int addStudent(int n,char *na)//查找是否存在{Student *p=equal(n);if (p==NULL)top++;read[top].addStudent(n,na);return 1;}return 0;}Student *equal(int Studentid)//按编号查找{for (int i=0;i<=top;i++)if (read[i].getnumber()==Studentid && read[i].gettag()==0){return &read[i];}return NULL;}void output(){for (int i=0;i<=top;i++)read[i].output();void Studentdata();//读者库维护~RData() //析构函数,将read[]写到Student.txt文件中{fstream file("Student.txt",ios::out);for (int i=0;i<=top;i++)if (read[i].gettag()==0)file.write((char *)&read[i],sizeof(read[i]));file.close();}};void RData::Studentdata(){char choice;char rname[20];int Studentid;Student *r;while (choice!='0'){cout<<"┏━━━━━━━━━━━━━┓\n";cout<<"┃读者维护┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃1.新增┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃2.更改┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃3.删除┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃4.查找┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃5.显示┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃6.全删┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃0.退出┃\n";cout<<"┗━━━━━━━━━━━━━┛\n"; //cout<<cin >> choice;switch (choice){case '1':cout << "输入读者编号:";cin >> Studentid;cout << "输入读者姓名:";cin >> rname;addStudent (Studentid,rname); break;case '2':cout << "输入读者编号:";cin >> Studentid;r=equal(Studentid);if (r==NULL){cout << "该读者不存在"<<endl; break;}cout << "输入新的姓名:";cin >> rname;r->setname(rname);break;case '3':cout << "输入读者编号:";cin >> Studentid;r=equal(Studentid);if (r==NULL){cout <<"该读者不存在" << endl; break;}r->delbook();break;case '4':cout << "读入读者编号:";cin >> Studentid;r=equal(Studentid);if (r==NULL){cout <<"该读者不存在"<< endl; break;}r->output();break;case '5':output();break;case '6':clear();break;default:cout<<"退出:\n";system("cls");break; }}}class Book{private:int tag;int number;char name[20];int onshelf;public:Book(){}char *getname(){return name;}int getnumber(){return number;}int gettag(){return tag;}void setname(char na[]) {strcpy(name,na);}void delbook(){tag=1;}void addbook(int n,char *na) {tag=0;number=n;strcpy(name,na);onshelf=1;}int borrowbook()//借书操作{if (onshelf==1){onshelf=0;return 1;}return 0;}void retbook()//还书操作{onshelf=1;}void output()//输出图书{cout << setw(6) << number << setw(18) << name << setw(10) <<(onshelf==1? "在架":"已借") <<endl;}};class BDatabase{private:int top;Book book[Maxb]; //图书记录public:BDatabase()//构造函数,将book.txt读到book[]中{Book b;top=-1;fstream file("book.txt",ios::in);while (1){file.read((char *)&b,sizeof(b));if (!file) break;top++;book[top]=b;}file.close();}void clear(){top=-1;}int addbook(int n,char *na){Book *p=equal(n);if (NULL==p){top++;book[top].addbook(n,na);return 1;}return 0;}Book *equal(int bookid){for (int i=0;i<=top;i++)if (book[i].getnumber()==bookid &&book[i].gettag()==0) {return &book[i];}return NULL;}void bookdata();void output(){for (int i=0;i<=top;i++)if (book[i].gettag()==0)book[i].output();}~BDatabase()//析构函数,将book[]写到book.txt文件中{fstream file("book.txt",ios::out);for (int i=0;i<=top;i++)if (book[i].gettag()==0)file.write((char *)&book[i],sizeof(book[i]));file.close();}};void BDatabase::bookdata(){char choice;char bname[40];int bookid;Book *b;while (choice!='0'){cout<<"┏━━━━━━━━━━━━━┓\n"; cout<<"┃图书维护┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃1.新增┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃2.更改┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃3.删除┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃4.查找┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃5.显示┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃6.全删┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃0.退出┃\n";cout<<"┗━━━━━━━━━━━━━┛\n"; cin >> choice;switch (choice){case '1':cout << "输入图书编号:"<<endl;cin >> bookid;cout << "输入图书书名:"<<endl;cin >> bname;addbook(bookid,bname);break;case '2':cout << "输入图书编号:"<<endl;cin >> bookid;b=equal(bookid);if (b==NULL){cout << "该图书不存在"<<endl;break;}cout << "输入新的书名:"<<endl;cin >> bname;b->setname(bname);break;case '3':cout <<"读入图书编号:"<<endl; cin >> bookid;b=equal(bookid);if (b==NULL){cout <<"该图书不存在" << endl; break;}b->delbook();break;case '4':cout << "读入图书编号:"<<endl; cin >> bookid;b=equal(bookid);if (b==NULL){cout <<"该图书不存在"<< endl;break;}b->output();break;case '5':output();break;case '6':clear();break;default:cout<<"退出\n"; system("cls"); break; }}}void main(){char choice;int bookid,Studentid;RData StudentDB;Student *r;BDatabase BookDB;Book *b;while(choice!='0'){cout<<"┏━━━━━━━━━━━━━┓\n"; cout<<"┃图书管理系统┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃1.借书┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃2.还书┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃3.图书维护┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃4.读者维护┃\n";cout<<"┃━━━━━━━━━━━━━┃\n"; cout<<"┃0.退出┃\n";cout<<"┗━━━━━━━━━━━━━┛\n"; cin >> choice;switch (choice){case '1': system("cls");cout <<"借书读者编号:";cin >>Studentid;cout <<"图书编号:";cin >>bookid;r=StudentDB.equal(Studentid);//按编号查找if (NULL==r){cout <<"不存在该读者,不能借书"<< endl; break;}b=BookDB.equal(bookid);if (b==NULL){cout <<"不存在该图书,不能借书"<< endl; break;}if (b->borrowbook()==0){cout << "该图书已借出,不能借书"<< endl; break;}r->borrowbook(b->getnumber());system("cls");case '2':system("cls");cout<<"还书\n读者编号:";cin >>Studentid;cout << "图书编号:";cin >>bookid;r=StudentDB.equal(Studentid);if (r==NULL){cout <<"不存在该读者,不能还书" << endl; break;}b=BookDB.equal(bookid);if (b==NULL){cout <<"不存在该图书,不能还书" <<endl; break;}b->retbook();r->retbook(b->getnumber());case '3':system("cls"); BookDB.bookdata(); break;case '4':system("cls"); StudentDB.Studentdata(); break;default:cout<<"退出\n"; }}}。

图书馆管理系统 c语言编写

图书馆管理系统   c语言编写

#include "stdio.h"#include "stdlib.h"#include "conio.h"#include "string.h"#include "math.h"#define LEN sizeof(struct library)#define LEN1 sizeof(struct reader)#define NULL 0struct library//图书馆结构体{int shuhao,xcl;char name[20],author[20],chuban[20];struct library *next;};struct reader//读者结构体{int zhenghao;char mingzi[20],riqi[20],zname[20];struct reader *next;};void mainmenu() //显示主菜单{ system ("cls");printf("\n");printf("\t\t\t\t####################\n\n"); printf("\t\t\t\t 1.图书馆信息\n\n");printf("\t\t\t\t 2.借阅系统\n\n");printf("\t\t\t\t 3.退出系统\n\n");printf("\t\t\t 请按键选择,回车确定\n"); printf("\t\t\t\t######################\n"); printf("\n");return ;}void menu1() //显示图书馆信息菜单{ system ("cls");printf("");printf("\t\t\t\t####################\n\n"); printf("\t\t\t\t 1.采编入库\n\n");printf("\t\t\t\t 2.清除库存\n\n");printf("\t\t\t\t 3.图书查询\n\n");printf("\t\t\t\t 4.库存一览\n\n");printf("\t\t\t\t 5.返回上一层\n\n");printf("\t\t\t 请按键选择,回车确定\n");printf("\t\t\t\t#######################\n");printf("\n");return ;}void menu2() //显示查询菜单{ system ("cls");//printf("");printf("\t\t\t\t#######################\n");printf("\t\t\t\t 1.书号查询\n\n");printf("\t\t\t\t 2.书名查询\n\n");printf("\t\t\t\t 3.作者查询\n\n");printf("\t\t\t\t 4.出版社查询\n\n");printf("\t\t\t 请按键选择,回车确定\n");printf("\t\t\t\t#######################\n");//printf("");return ;}void main()//主函数,调用main1{void main1();main1();}void main1()//main1函数{void tsgxx();//声明void jieshuxitong();//声明char choose;mainmenu();scanf("%c",&choose);switch(choose)//功能函数选择{ case '1':tsgxx();break;case '2':jieshuxitong();break;case '3':system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t Byebye...");printf("\n\n\n\n\n\n\n\n\n\t\t\t 欢迎使用本软件!!!");getch();exit(0);system ("cls");break;}}void tsgxx()//图书馆信息函数{ void tsjinku();void shanchu();void chaxunts();void xianshikucun();//函数声明char choose;menu1();//调用菜单函数scanf("%c",&choose);scanf("%c",&choose);for (;;)switch(choose)//功能函数选择{ case '1':tsjinku();break;case '2':shanchu();break;case '3':chaxunts();break;case '4':xianshikucun();break;case '5':main1();break;}}int tjzs()//统计文本个数函数{ FILE *fp;int tshuhao=0,txcl=0,n;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'};fp=fopen("library.txt","r");//打开文件for (n=0;!feof(fp);n++)//逐个读文件fscanf(fp,"%d %s %s %s %d",&tshuhao,tname,tauthor,tchuban,&txcl);n--;fclose(fp);//关闭文件return (n);//返回个数}int tjdzzs()//统计文本个数函数{ FILE *fp;int zhenghao=0,n;char mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};fp=fopen("reader.txt","r");//打开文件for (n=0;!feof(fp);n++)//逐个读文件fscanf(fp,"%d %s %s %s ",&zhenghao,&mingzi,&riqi,&zname);fclose(fp);//关闭文件return (n);//返回个数}void tsjinku()//图书进库函数{ FILE *fp;int shuhao=0,xcl=0,n=0;char name[20]={'\0'},author[20]={'\0'},chuban[20]={'\0'};char hitkey;system ("cls");if ((fp=fopen("library.txt","r"))==NULL)//打开图书馆文件,不存在此文件则新建{ fp=fopen("library.txt","w");fclose(fp);}fp=fopen("library.txt","a");printf("\n\n\n\n\n\n\t\t\t请按以下格式输入图书信息:\t\t\t\t\t\t 书号书名作者出版社进库量\n请输入:");//按格式输入图书馆信息for (;hitkey!=27;)//循环输入{ if (n!=0)printf("请输入:");scanf("%d%s%s%s%d",&shuhao,name,author,chuban,&xcl);fprintf(fp,"%d %s %s %s %d\n",shuhao,name,author,chuban,xcl);printf("继续输入请按回车,结束输入请按esc\n");n++;hitkey=getch();for (;hitkey!=13&&hitkey!=27;)hitkey=getch();}fclose(fp);printf("\n\n\n\n\n\n\t\t\t保存成功,按任意键返回上一层!");getch();tsgxx();//返回上一层}void shanchu()//删除图书信息函数{ struct library *head=NULL;struct library *p,*p1,*p2;int tshuhao=0,txcl=0,n=0,j,i;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};char hitkey;FILE *fp;if ((fp=fopen("library.txt","r"))==NULL)//打开文件{ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文件不存在!按任意键返回...");getch();tsgxx();}else{ system ("cls");printf("\n\n\n\n\n\n\n\n\t\t请输入你要删除的书名:");//输入删除图书书名scanf("%s",&ttname);printf("\t\t确认删除请回车,取消请按esc\n");hitkey=getch();for (;hitkey!=13&&hitkey!=27;)hitkey=getch();if (hitkey==27)tsgxx();fp=fopen("library.txt","r");for (j=0;!feof(fp);)//读文件夹信息,统计个数{ j++;fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);}fclose(fp);fp=fopen("library.txt","r");for (i=1;i<j;i++){ fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl); if (strcmp(ttname,tname))//比较名字,将不同名字的信息复制到链表{ n++;if (n==1)//建立链表{ p1=p2=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建链表}p1->shuhao=tshuhao;//复制书号strcpy(p1->name,tname);//复制书名strcpy(p1->author,tauthor);//复制作者名子strcpy(p1->chuban,tchuban);//复制出版社p1->xcl=txcl;//复制个数}}if (n==0){ head=NULL;}else{p2->next=p1;p1->next=NULL;fclose(fp);}}fp=fopen("library.txt","w");//清空文件fclose(fp);fp=fopen("library.txt","a");//追加文件p=head;for (;p!=NULL;)//把链表内容覆盖到文件{fprintf(fp,"%d %s %s %s %d \n",p->shuhao,p->name,p->author,p->chuban,p->xcl);p=p->next;}fclose(fp);//关闭文件system ("cls");printf("\n\n\n\n\n\n\n\n\t\t 删除成功\n\t\t按任意键返回上一层\n");getch();//返回上一层tsgxx();}void chaxunts()//查询函数{FILE *fp;char choose;int ttshuhao=0,tshuhao=0,txcl=0,n=0,k=0,i,l;chartname[20]={'\0'},ttauthor[20]={'\0'},tauthor[20]={'\0'},ttchuban[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};if ((fp=fopen("library.txt","r"))==NULL)//打开文件{ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文件不存在!按任意键返回...");getch();tsgxx();}l=tjzs();//获得文件个数menu2();//调用菜单函数scanf("%c",&choose);scanf("%c",&choose);//选择查询方式if (choose=='5')return;else if (choose=='1')//书号查询{ system ("cls");printf("请输入书号:");scanf("%d",&ttshuhao);}elseif (choose=='2')//书名查询{ system ("cls");printf("请输入书名:");scanf("%s",ttname);}elseif (choose=='3')//作者查询{ system ("cls");printf("请输入作者:");scanf("%s",ttauthor);}elseif (choose=='4')//出版社查询{ system ("cls");printf("请输入出版社:");scanf("%s",ttchuban);}system ("cls");for (i=0;i<l;i++){ fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);//读文件信息if(ttshuhao==tshuhao||!strcmp(ttname,tname)||!strcmp(ttauthor,tauthor)||!strcmp(ttchuban,tch uban))//输出查询信息{if (k==0){printf("\t\t\t\t查询结果:\n\n");printf("\t 书号书名作者出版社现存量\n");}printf("\t %-4d %-8s %-8s %-8s %-4d \n",tshuhao,tname,tauthor,tchuban,txcl);k++;}}if (k==0)//文件夹为空则输出无记录{ system ("cls");printf("\n\n\n\n\n\n\n\t\t\t\t无符合记录!\n");getch();tsgxx();}fclose(fp);getch();//返回tsgxx();}void xianshikucun()//现实库存信息{FILE *fp;int shuhao=0,xcl=0,n=0,i=0,j=0;char name[20]={'\0'},author[20]={'\0'},chuban[20]={'\0'};if ((fp=fopen("library.txt","r"))==NULL)//打开文件夹{system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文件不存在!");n= tjzs();if (n==0){ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t无任何记录!");}fp=fopen("library.txt","r");system ("cls");printf("************************************************************************* *******");printf("\t 书号书名作者出版社库存量\n");printf("************************************************************************* *******");for (i=0;i<n;i++)//输出信息{fscanf(fp,"%d%s%s%s%d",&shuhao,name,author,chuban,&xcl);printf("\t %-4d %-8s %-8s %-8s %-4d \n",shuhao,name,author,chuban,xcl);}fclose(fp);printf("\t\t\t\t按任意键返回\n");getch();//返回tsgxx();}void menu3() //显示借书系统主菜单{ system ("cls");//printf("*********************************************************************** *********");printf("\t\t\t\t#######################\n");printf("\t\t\t\t 1.借书登记\n\n");printf("\t\t\t\t 2.还书登记\n\n");printf("\t\t\t\t 3.借阅情况查看\n\n");printf("\t\t\t\t 4.返回上一层\n\n");printf("\t\t\t 请按键选择,回车确定\n");printf("\t\t\t\t#######################\n");//printf("*********************************************************************** *********");return ;}void jieshuxitong()//借书系统函数{ void jieshu();void huanshu();void duzheyilang();//函数声明char choose;menu3();scanf("%c",&choose);scanf("%c",&choose);//选择功能for (;;)switch(choose)//调用函数{ case '1':jieshu();break;case '2':huanshu();break;case '3':duzheyilang();break;case '4':main1();break;}}void jieshu()//借书函数{FILE *fp,*fp3;struct library *head=NULL;struct library *p,*p1,*p2;int tshuhao=0,txcl=0,i,loop,zhenghao=0,n=0,k=0,t=0,flag=0;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'},mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};char hitkey=0;system ("cls");{if ((fp=fopen("library.txt","r"))==NULL)//打开图书馆文件{system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t 图书馆无库存!按任意键退出!");getch();exit (0);}else{{printf("\n\n\n\n\n\n\t\t\t请输入借阅书名:\t\t\t\t\t\t \n请输入:");//输入书名scanf("%s",zname);k= tjzs();//统计图书馆文件个数for (i=0;i<k;i++)//读入图书馆信息,存储到链表{fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);n++;if (n==1){ p1=p2=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建链表}p1->shuhao=tshuhao;//复制书号strcpy(p1->name,tname);//复制书名strcpy(p1->author,tauthor);//复制作者strcpy(p1->chuban,tchuban);//复制出版社p1->xcl=txcl;//复制现存量}if (n==0)head=NULL;else{p2->next=p1;p1->next=NULL;fclose(fp);}}}p=head;for (;p!=NULL;)//读链表{if(!(strcmp(p->name,zname)))//名字相同{flag=1;//标记取1loop=p->xcl;//现存量减1(p->xcl)--;}p=p->next;}if(flag&&(loop>0))//存在借书书名且现存量大于0{ fp=fopen("library.txt","w");fclose(fp);fp=fopen("library.txt","a");p=head;for (;p!=NULL;){fprintf(fp,"%d %s %s %s %d \n",p->shuhao,p->name,p->author,p->chuban,p->xcl);p=p->next;}free(p);//把链表内容覆盖文件fclose(fp);}if(flag&&(loop>0))//存在借书书名且现存量大于0{{if ((fp3=fopen("reader.txt","r"))==NULL)//建读者文件夹{ fp3=fopen("reader.txt","w");fclose(fp3);}fp3=fopen("reader.txt","a");}{{ if (n!=0)printf("\n\n\n\n\n\n\t\t\t请按以下格式输入读者信息:\t\t\t\t\t\t 证号姓名归还日期借书书名\n请输入:");//录入读者信息scanf("%d %s %s %s",&zhenghao,&mingzi[20],&riqi[20],&zname[20]);fprintf(fp3,"%d %s %s %s \n",zhenghao,&mingzi[20],&riqi[20],&zname[20]);fp=fopen("library.txt","w");//删除图书馆文件信息fclose(fp);fp=fopen("library.txt","a");//重新追加信息p=head;for (;p!=NULL;)//把链表内容覆盖图书馆文件{fprintf(fp,"%d %s %s %s %d \n",p->shuhao,p->name,p->author,p->chuban,p->xcl);p=p->next;}fclose(fp);fclose(fp3);printf("成功!按任意键返回\n");getch();//返回jieshuxitong();}}jieshuxitong();}elseprintf("此书已被借完!按任意键返回!");//否则输出此书已被接完getch();//返回jieshuxitong();}}void huanshu()//还书函数{FILE *fp,*fp3;struct reader *head=NULL;struct reader *p,*p1,*p2;struct library *lhead1=NULL;struct library *zp1,*lp1,*lp2;int tshuhao=0,txcl=0,i;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};int ttzhenghao=0,tzhenghao=0,n=0,k=0,t=0,flag=0;char tmingzi[20]={'\0'},triqi[20]={'\0'},tzname[20]={'\0'},ttzname[20]={'\0'};char hitkey=0;system ("cls");{if ((fp=fopen("reader.txt","r"))==NULL)//不存在读者文件,则输出不能还书{system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t 不存在借书者!按任意键退出!");getch();exit (0);}else{{printf("\n\n\n\n\n\n\t\t\t请输入读者证号和书名:\t\t\t\t\t\t \n请输入:");scanf("%d %s",&ttzhenghao,ttzname);//输入还书证号和书名k= tjdzzs();//获取读者文件夹信息个数for (i=0;i<k;i++)//读取读者文件夹信息{fscanf(fp,"%d%s%s%s\n ",&tzhenghao,tmingzi,triqi,tzname);if((ttzhenghao==tzhenghao)&&!strcmp(ttzname,tzname))//如果证号书名存在,则标记为1flag=1;}fclose(fp);fp=fopen("reader.txt","r");//打开读者文件if(flag){for (i=0;i<k;i++)//将读者文件复制到链表{fscanf(fp,"%d%s%s%s\n ",&tzhenghao,tmingzi,triqi,tzname);//读取文件信息if(!((ttzhenghao==tzhenghao)&&!strcmp(ttzname,tzname))){ n++;if (n==1){ p1=p2=(struct reader*)malloc(LEN1);//新建链表head=p1;}else{ p2->next=p1;p2=p1;p1=(struct reader*)malloc(LEN1);//新建链表}p1->zhenghao=tzhenghao;//复制证号strcpy(p1->mingzi,tmingzi);//复制读者名字strcpy(p1->riqi,triqi);//复制日期strcpy(p1->zname,tzname);//复制书名}}if (n==0)head=NULL;else{p2->next=p1;p1->next=NULL;fclose(fp);}fp=fopen("reader.txt","w");//清空读者文件fclose(fp);fp=fopen("reader.txt","a");//追加信息p=head;for (;p!=NULL;)//把链表内容覆盖读者文件{fprintf(fp,"%d %s %s %s \n",p->zhenghao,p->mingzi,p->riqi,p->zname);p=p->next;}free(p);fclose(fp);}}}}if(flag)//标记为1,既还书时{{{printf("确认还书请按回车!");for (;hitkey!=13&&hitkey!=27;)hitkey=getch();if (hitkey==13)printf("成功!按任意键返回!");n=0;flag=0;fp3=fopen("library.txt","r");//打开图书馆文件k= tjzs();//获取图书馆文件个数for (i=0;i<k;i++)//将图书馆文件复制到链表{fscanf(fp3,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);//读取信息n++;if (n==1){ lp1=lp2=(struct library*)malloc(LEN);//新建链表lhead1=lp1;}else{ lp2->next=lp1;lp2=lp1;lp1=(struct library*)malloc(LEN);//新建链表}lp1->shuhao=tshuhao;//复制书号strcpy(lp1->name,tname);//复制书名strcpy(lp1->author,tauthor);//复制作者strcpy(lp1->chuban,tchuban);//复制出版社lp1->xcl=txcl; //复制现存量}if (n==0){ lhead1=NULL;}else{lp2->next=lp1;lp1->next=NULL;fclose(fp3);}}}zp1=lhead1;for (;zp1!=NULL;){if(!(strcmp(zp1->name,ttzname)))//寻找书名相同++(zp1->xcl);//现存量加1zp1=zp1->next;}fp3=fopen("library.txt","w");//清空图书馆文件fclose(fp);fp3=fopen("library.txt","a");//追加信息zp1=lhead1;for (;zp1!=NULL;)//把链表内容覆盖图书馆文件{fprintf(fp3,"%d %s %s %s %d \n",zp1->shuhao,zp1->name,zp1->author,zp1->chuban,zp1->xcl);//录入信息zp1=zp1->next;}fclose(fp3);getch();//返回jieshuxitong();}elseprintf("不存在此信息!按任意键返回!");getch();//返回jieshuxitong();}void duzheyilang()//显示借书情况函数{FILE *fp;int zhenghao=0,xcl=0,n=0,i=0,j=0;char mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};if ((fp=fopen("reader.txt","r"))==NULL)//打开读者文件夹{system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文件不存在!");}n=tjdzzs();if (n==0){ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t无任何记录!");}fp=fopen("reader.txt","r");system ("cls");printf("************************************************************************* *******");printf("\t 证号读者姓名还书日期书名\n");printf("************************************************************************* *******");for (i=0;i<n;i++)//输出文件信息{fscanf(fp,"%d%s%s%s\n ",&zhenghao,mingzi,riqi,zname);printf("\t %-4d %-8s %-8s %-8s \n", zhenghao,mingzi,riqi,zname);}fclose(fp);printf("\t\t\t\t按任意键返回\n");getch();//返回jieshuxitong();}。

图书馆管理系统 c语言编写

图书馆管理系统   c语言编写

#include "stdio.h"#include "stdlib.h"#include "conio.h"#include "string.h"#include "math.h"#define LEN sizeof(struct library)#define LEN1 sizeof(struct reader)#define NULL 0struct library//图书馆结构体{int shuhao,xcl;char name[20],author[20],chuban[20];struct library *next;};struct reader//读者结构体{int zhenghao;char mingzi[20],riqi[20],zname[20];struct reader *next;};void mainmenu() //显示主菜单{ system ("cls");printf("\n");printf("\t\t\t\t####################\n\n"); printf("\t\t\t\t 1.图书馆信息\n\n");printf("\t\t\t\t 2.借阅系统\n\n");printf("\t\t\t\t 3.退出系统\n\n");printf("\t\t\t 请按键选择,回车确定\n"); printf("\t\t\t\t######################\n"); printf("\n");return ;}void menu1() //显示图书馆信息菜单{ system ("cls");printf("");printf("\t\t\t\t####################\n\n"); printf("\t\t\t\t 1.采编入库\n\n");printf("\t\t\t\t 2.清除库存\n\n");printf("\t\t\t\t 3.图书查询\n\n");printf("\t\t\t\t 4.库存一览\n\n");printf("\t\t\t\t 5.返回上一层\n\n");printf("\t\t\t 请按键选择,回车确定\n");printf("\t\t\t\t#######################\n");printf("\n");return ;}void menu2() //显示查询菜单{ system ("cls");//printf("");printf("\t\t\t\t#######################\n");printf("\t\t\t\t 1.书号查询\n\n");printf("\t\t\t\t 2.书名查询\n\n");printf("\t\t\t\t 3.作者查询\n\n");printf("\t\t\t\t 4.出版社查询\n\n");printf("\t\t\t 请按键选择,回车确定\n");printf("\t\t\t\t#######################\n");//printf("");return ;}void main()//主函数,调用main1{void main1();main1();}void main1()//main1函数{void tsgxx();//声明void jieshuxitong();//声明char choose;mainmenu();scanf("%c",&choose);switch(choose)//功能函数选择{ case '1':tsgxx();break;case '2':jieshuxitong();break;case '3':system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t Byebye...");printf("\n\n\n\n\n\n\n\n\n\t\t\t 欢迎使用本软件!!!");getch();exit(0);system ("cls");break;}}void tsgxx()//图书馆信息函数{ void tsjinku();void shanchu();void chaxunts();void xianshikucun();//函数声明char choose;menu1();//调用菜单函数scanf("%c",&choose);scanf("%c",&choose);for (;;)switch(choose)//功能函数选择{ case '1':tsjinku();break;case '2':shanchu();break;case '3':chaxunts();break;case '4':xianshikucun();break;case '5':main1();break;}}int tjzs()//统计文本个数函数{ FILE *fp;int tshuhao=0,txcl=0,n;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'};fp=fopen("library.txt","r");//打开文件for (n=0;!feof(fp);n++)//逐个读文件fscanf(fp,"%d %s %s %s %d",&tshuhao,tname,tauthor,tchuban,&txcl);n--;fclose(fp);//关闭文件return (n);//返回个数}int tjdzzs()//统计文本个数函数{ FILE *fp;int zhenghao=0,n;char mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};fp=fopen("reader.txt","r");//打开文件for (n=0;!feof(fp);n++)//逐个读文件fscanf(fp,"%d %s %s %s ",&zhenghao,&mingzi,&riqi,&zname);fclose(fp);//关闭文件return (n);//返回个数}void tsjinku()//图书进库函数{ FILE *fp;int shuhao=0,xcl=0,n=0;char name[20]={'\0'},author[20]={'\0'},chuban[20]={'\0'};char hitkey;system ("cls");if ((fp=fopen("library.txt","r"))==NULL)//打开图书馆文件,不存在此文件则新建{ fp=fopen("library.txt","w");fclose(fp);}fp=fopen("library.txt","a");printf("\n\n\n\n\n\n\t\t\t请按以下格式输入图书信息:\t\t\t\t\t\t 书号书名作者出版社进库量\n请输入:");//按格式输入图书馆信息for (;hitkey!=27;)//循环输入{ if (n!=0)printf("请输入:");scanf("%d%s%s%s%d",&shuhao,name,author,chuban,&xcl);fprintf(fp,"%d %s %s %s %d\n",shuhao,name,author,chuban,xcl);printf("继续输入请按回车,结束输入请按esc\n");n++;hitkey=getch();for (;hitkey!=13&&hitkey!=27;)hitkey=getch();}fclose(fp);printf("\n\n\n\n\n\n\t\t\t保存成功,按任意键返回上一层!");getch();tsgxx();//返回上一层}void shanchu()//删除图书信息函数{ struct library *head=NULL;struct library *p,*p1,*p2;int tshuhao=0,txcl=0,n=0,j,i;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};char hitkey;FILE *fp;if ((fp=fopen("library.txt","r"))==NULL)//打开文件{ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文件不存在!按任意键返回...");getch();tsgxx();}else{ system ("cls");printf("\n\n\n\n\n\n\n\n\t\t请输入你要删除的书名:");//输入删除图书书名scanf("%s",&ttname);printf("\t\t确认删除请回车,取消请按esc\n");hitkey=getch();for (;hitkey!=13&&hitkey!=27;)hitkey=getch();if (hitkey==27)tsgxx();fp=fopen("library.txt","r");for (j=0;!feof(fp);)//读文件夹信息,统计个数{ j++;fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);}fclose(fp);fp=fopen("library.txt","r");for (i=1;i<j;i++){ fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl); if (strcmp(ttname,tname))//比较名字,将不同名字的信息复制到链表{ n++;if (n==1)//建立链表{ p1=p2=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建链表}p1->shuhao=tshuhao;//复制书号strcpy(p1->name,tname);//复制书名strcpy(p1->author,tauthor);//复制作者名子strcpy(p1->chuban,tchuban);//复制出版社p1->xcl=txcl;//复制个数}}if (n==0){ head=NULL;}else{p2->next=p1;p1->next=NULL;fclose(fp);}}fp=fopen("library.txt","w");//清空文件fclose(fp);fp=fopen("library.txt","a");//追加文件p=head;for (;p!=NULL;)//把链表内容覆盖到文件{fprintf(fp,"%d %s %s %s %d \n",p->shuhao,p->name,p->author,p->chuban,p->xcl);p=p->next;}fclose(fp);//关闭文件system ("cls");printf("\n\n\n\n\n\n\n\n\t\t 删除成功\n\t\t按任意键返回上一层\n");getch();//返回上一层tsgxx();}void chaxunts()//查询函数{FILE *fp;char choose;int ttshuhao=0,tshuhao=0,txcl=0,n=0,k=0,i,l;chartname[20]={'\0'},ttauthor[20]={'\0'},tauthor[20]={'\0'},ttchuban[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};if ((fp=fopen("library.txt","r"))==NULL)//打开文件{ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文件不存在!按任意键返回...");getch();tsgxx();}l=tjzs();//获得文件个数menu2();//调用菜单函数scanf("%c",&choose);scanf("%c",&choose);//选择查询方式if (choose=='5')return;else if (choose=='1')//书号查询{ system ("cls");printf("请输入书号:");scanf("%d",&ttshuhao);}elseif (choose=='2')//书名查询{ system ("cls");printf("请输入书名:");scanf("%s",ttname);}elseif (choose=='3')//作者查询{ system ("cls");printf("请输入作者:");scanf("%s",ttauthor);}elseif (choose=='4')//出版社查询{ system ("cls");printf("请输入出版社:");scanf("%s",ttchuban);}system ("cls");for (i=0;i<l;i++){ fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);//读文件信息if(ttshuhao==tshuhao||!strcmp(ttname,tname)||!strcmp(ttauthor,tauthor)||!strcmp(ttchuban,tch uban))//输出查询信息{if (k==0){printf("\t\t\t\t查询结果:\n\n");printf("\t 书号书名作者出版社现存量\n");}printf("\t %-4d %-8s %-8s %-8s %-4d \n",tshuhao,tname,tauthor,tchuban,txcl);k++;}}if (k==0)//文件夹为空则输出无记录{ system ("cls");printf("\n\n\n\n\n\n\n\t\t\t\t无符合记录!\n");getch();tsgxx();}fclose(fp);getch();//返回tsgxx();}void xianshikucun()//现实库存信息{FILE *fp;int shuhao=0,xcl=0,n=0,i=0,j=0;char name[20]={'\0'},author[20]={'\0'},chuban[20]={'\0'};if ((fp=fopen("library.txt","r"))==NULL)//打开文件夹{system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文件不存在!");n= tjzs();if (n==0){ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t无任何记录!");}fp=fopen("library.txt","r");system ("cls");printf("************************************************************************* *******");printf("\t 书号书名作者出版社库存量\n");printf("************************************************************************* *******");for (i=0;i<n;i++)//输出信息{fscanf(fp,"%d%s%s%s%d",&shuhao,name,author,chuban,&xcl);printf("\t %-4d %-8s %-8s %-8s %-4d \n",shuhao,name,author,chuban,xcl);}fclose(fp);printf("\t\t\t\t按任意键返回\n");getch();//返回tsgxx();}void menu3() //显示借书系统主菜单{ system ("cls");//printf("*********************************************************************** *********");printf("\t\t\t\t#######################\n");printf("\t\t\t\t 1.借书登记\n\n");printf("\t\t\t\t 2.还书登记\n\n");printf("\t\t\t\t 3.借阅情况查看\n\n");printf("\t\t\t\t 4.返回上一层\n\n");printf("\t\t\t 请按键选择,回车确定\n");printf("\t\t\t\t#######################\n");//printf("*********************************************************************** *********");return ;}void jieshuxitong()//借书系统函数{ void jieshu();void huanshu();void duzheyilang();//函数声明char choose;menu3();scanf("%c",&choose);scanf("%c",&choose);//选择功能for (;;)switch(choose)//调用函数{ case '1':jieshu();break;case '2':huanshu();break;case '3':duzheyilang();break;case '4':main1();break;}}void jieshu()//借书函数{FILE *fp,*fp3;struct library *head=NULL;struct library *p,*p1,*p2;int tshuhao=0,txcl=0,i,loop,zhenghao=0,n=0,k=0,t=0,flag=0;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'},mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};char hitkey=0;system ("cls");{if ((fp=fopen("library.txt","r"))==NULL)//打开图书馆文件{system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t 图书馆无库存!按任意键退出!");getch();exit (0);}else{{printf("\n\n\n\n\n\n\t\t\t请输入借阅书名:\t\t\t\t\t\t \n请输入:");//输入书名scanf("%s",zname);k= tjzs();//统计图书馆文件个数for (i=0;i<k;i++)//读入图书馆信息,存储到链表{fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);n++;if (n==1){ p1=p2=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建链表}p1->shuhao=tshuhao;//复制书号strcpy(p1->name,tname);//复制书名strcpy(p1->author,tauthor);//复制作者strcpy(p1->chuban,tchuban);//复制出版社p1->xcl=txcl;//复制现存量}if (n==0)head=NULL;else{p2->next=p1;p1->next=NULL;fclose(fp);}}}p=head;for (;p!=NULL;)//读链表{if(!(strcmp(p->name,zname)))//名字相同{flag=1;//标记取1loop=p->xcl;//现存量减1(p->xcl)--;}p=p->next;}if(flag&&(loop>0))//存在借书书名且现存量大于0{ fp=fopen("library.txt","w");fclose(fp);fp=fopen("library.txt","a");p=head;for (;p!=NULL;){fprintf(fp,"%d %s %s %s %d \n",p->shuhao,p->name,p->author,p->chuban,p->xcl);p=p->next;}free(p);//把链表内容覆盖文件fclose(fp);}if(flag&&(loop>0))//存在借书书名且现存量大于0{{if ((fp3=fopen("reader.txt","r"))==NULL)//建读者文件夹{ fp3=fopen("reader.txt","w");fclose(fp3);}fp3=fopen("reader.txt","a");}{{ if (n!=0)printf("\n\n\n\n\n\n\t\t\t请按以下格式输入读者信息:\t\t\t\t\t\t 证号姓名归还日期借书书名\n请输入:");//录入读者信息scanf("%d %s %s %s",&zhenghao,&mingzi[20],&riqi[20],&zname[20]);fprintf(fp3,"%d %s %s %s \n",zhenghao,&mingzi[20],&riqi[20],&zname[20]);fp=fopen("library.txt","w");//删除图书馆文件信息fclose(fp);fp=fopen("library.txt","a");//重新追加信息p=head;for (;p!=NULL;)//把链表内容覆盖图书馆文件{fprintf(fp,"%d %s %s %s %d \n",p->shuhao,p->name,p->author,p->chuban,p->xcl);p=p->next;}fclose(fp);fclose(fp3);printf("成功!按任意键返回\n");getch();//返回jieshuxitong();}}jieshuxitong();}elseprintf("此书已被借完!按任意键返回!");//否则输出此书已被接完getch();//返回jieshuxitong();}}void huanshu()//还书函数{FILE *fp,*fp3;struct reader *head=NULL;struct reader *p,*p1,*p2;struct library *lhead1=NULL;struct library *zp1,*lp1,*lp2;int tshuhao=0,txcl=0,i;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};int ttzhenghao=0,tzhenghao=0,n=0,k=0,t=0,flag=0;char tmingzi[20]={'\0'},triqi[20]={'\0'},tzname[20]={'\0'},ttzname[20]={'\0'};char hitkey=0;system ("cls");{if ((fp=fopen("reader.txt","r"))==NULL)//不存在读者文件,则输出不能还书{system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t 不存在借书者!按任意键退出!");getch();exit (0);}else{{printf("\n\n\n\n\n\n\t\t\t请输入读者证号和书名:\t\t\t\t\t\t \n请输入:");scanf("%d %s",&ttzhenghao,ttzname);//输入还书证号和书名k= tjdzzs();//获取读者文件夹信息个数for (i=0;i<k;i++)//读取读者文件夹信息{fscanf(fp,"%d%s%s%s\n ",&tzhenghao,tmingzi,triqi,tzname);if((ttzhenghao==tzhenghao)&&!strcmp(ttzname,tzname))//如果证号书名存在,则标记为1flag=1;}fclose(fp);fp=fopen("reader.txt","r");//打开读者文件if(flag){for (i=0;i<k;i++)//将读者文件复制到链表{fscanf(fp,"%d%s%s%s\n ",&tzhenghao,tmingzi,triqi,tzname);//读取文件信息if(!((ttzhenghao==tzhenghao)&&!strcmp(ttzname,tzname))){ n++;if (n==1){ p1=p2=(struct reader*)malloc(LEN1);//新建链表head=p1;}else{ p2->next=p1;p2=p1;p1=(struct reader*)malloc(LEN1);//新建链表}p1->zhenghao=tzhenghao;//复制证号strcpy(p1->mingzi,tmingzi);//复制读者名字strcpy(p1->riqi,triqi);//复制日期strcpy(p1->zname,tzname);//复制书名}}if (n==0)head=NULL;else{p2->next=p1;p1->next=NULL;fclose(fp);}fp=fopen("reader.txt","w");//清空读者文件fclose(fp);fp=fopen("reader.txt","a");//追加信息p=head;for (;p!=NULL;)//把链表内容覆盖读者文件{fprintf(fp,"%d %s %s %s \n",p->zhenghao,p->mingzi,p->riqi,p->zname);p=p->next;}free(p);fclose(fp);}}}}if(flag)//标记为1,既还书时{{{printf("确认还书请按回车!");for (;hitkey!=13&&hitkey!=27;)hitkey=getch();if (hitkey==13)printf("成功!按任意键返回!");n=0;flag=0;fp3=fopen("library.txt","r");//打开图书馆文件k= tjzs();//获取图书馆文件个数for (i=0;i<k;i++)//将图书馆文件复制到链表{fscanf(fp3,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);//读取信息n++;if (n==1){ lp1=lp2=(struct library*)malloc(LEN);//新建链表lhead1=lp1;}else{ lp2->next=lp1;lp2=lp1;lp1=(struct library*)malloc(LEN);//新建链表}lp1->shuhao=tshuhao;//复制书号strcpy(lp1->name,tname);//复制书名strcpy(lp1->author,tauthor);//复制作者strcpy(lp1->chuban,tchuban);//复制出版社lp1->xcl=txcl; //复制现存量}if (n==0){ lhead1=NULL;}else{lp2->next=lp1;lp1->next=NULL;fclose(fp3);}}}zp1=lhead1;for (;zp1!=NULL;){if(!(strcmp(zp1->name,ttzname)))//寻找书名相同++(zp1->xcl);//现存量加1zp1=zp1->next;}fp3=fopen("library.txt","w");//清空图书馆文件fclose(fp);fp3=fopen("library.txt","a");//追加信息zp1=lhead1;for (;zp1!=NULL;)//把链表内容覆盖图书馆文件{fprintf(fp3,"%d %s %s %s %d \n",zp1->shuhao,zp1->name,zp1->author,zp1->chuban,zp1->xcl);//录入信息zp1=zp1->next;}fclose(fp3);getch();//返回jieshuxitong();}elseprintf("不存在此信息!按任意键返回!");getch();//返回jieshuxitong();}void duzheyilang()//显示借书情况函数{FILE *fp;int zhenghao=0,xcl=0,n=0,i=0,j=0;char mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};if ((fp=fopen("reader.txt","r"))==NULL)//打开读者文件夹{system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文件不存在!");}n=tjdzzs();if (n==0){ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t无任何记录!");}fp=fopen("reader.txt","r");system ("cls");printf("************************************************************************* *******");printf("\t 证号读者姓名还书日期书名\n");printf("************************************************************************* *******");for (i=0;i<n;i++)//输出文件信息{fscanf(fp,"%d%s%s%s\n ",&zhenghao,mingzi,riqi,zname);printf("\t %-4d %-8s %-8s %-8s \n", zhenghao,mingzi,riqi,zname);}fclose(fp);printf("\t\t\t\t按任意键返回\n");getch();//返回jieshuxitong();}。

图书管理系统 C语言程序

图书管理系统  C语言程序

#include<stdio.h>/*输入输出函数*/#include<string.h>/*字符串操作函数*/#include<stdlib.h>/*数值转换函数*///#include<conio.h>/*控制台输入输出函数*/#define MAX 100/*宏定义,参数为形参*/struct book/*图书信息结构定义*/{intnum;/*图书编号*/char name[100];/*书名*/char author[100];/*作者名*/char fn[100];/*分类号*/char place[100];/*出版单位*/char day[100];/*出版时间*/float money;/*价格*/}book[MAX],temp;main()/*主函数*/{void Input();/*输入*/void Output();/*输出*/void Find();/*查找*/void Delete();/*删除*/void Change();/*修改*/void Paixu();/*排序*/int n;printf("\n");printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n");printf("※※\n");printf("※欢迎来河南工业大学图书信息管理系统※\n");printf("※※\n");printf("※※\n");printf("※★1.图书管理员系统★※\n");printf("※※\n");printf("※★2.读者系统★※\n");printf("※※\n");printf("※▲退出(输入其他数字)※\n");printf("※※\n");printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n");printf("请输入选择项(1-2):");scanf("%d",&n);printf("\n\n\n\n");if(n==1){int m;printf("请输入图书管理系统的密码:");scanf("%d",&m);if(m==1002){for(;;)/*省略"初始化"、"条件表达式"和"增量"*/{int s;printf("\n");printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n");printf("※※\n");printf("※欢迎来河南工业大学图书信息管理系统※\n");printf("※※\n");printf("※※\n");printf("※主菜单※\n");printf("※※\n");printf("※★1.图书信息录入★※\n");printf("※※\n");printf("※★2.图书信息浏览★※\n");printf("※※\n");printf("※★3.图书信息查询★※\n");printf("※※\n");printf("※★4.图书信息删除★※\n");printf("※※\n");printf("※★5.图书信息修改★※\n");printf("※※\n");printf("※★6.图书排序★※\n");printf("※※\n");printf("※★7.退出系统★※\n");printf("※※\n");printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n\n");printf("请输入选择项(1-7):");scanf("%d",&s);printf("\n\n\n\n");if(s>0&&s<8){switch(s){case 1:Input();break;case 2:Output();break;case 3:Find();break;case 4:Delete();break;case 5:Change();break;case 6:Paixu();break;case 7:printf("※※※※※※※※※※※※※※※※※※※※※※※※\n");printf("※※\n");printf("※谢谢使用! ※\n");printf("※再见! ※\n");printf("※※\n");printf("※※※※※※※※※※※※※※※※※※※※※※※※\n");exit(0);}}}}elseprintf("密码错误,请您重新进入系统\n");return 0;}else if(n==2){int t;printf("请输入读者密码:");scanf("%d",&t);if(t==.320){for(;;)/*省略"初始化"、"条件表达式"和"增量"*/{int h;printf("\n");printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n");printf("※※\n");printf("※欢迎来河南工业大学图书服务系统※\n");printf("※※\n");printf("※※\n");printf("※主菜单※\n");printf("※※\n");printf("※★1.图书信息浏览★※\n");printf("※※\n");printf("※★2.图书信息查询★※\n");printf("※※\n");printf("※★3.图书排序★※\n");printf("※※\n");printf("※★4.退出系统★※\n");printf("※※\n");printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n\n");printf("请输入选择项(1-4):");scanf("%d",&h);printf("\n\n\n\n");if(h>0&&h<5){switch(h){case 1:Output();break;case 2:Find();break;case 3:Paixu();break;case 4:printf("※※※※※※※※※※※※※※※※※※※※※※※※\n");printf("※※\n");printf("※谢谢使用! ※\n");printf("※再见! ※\n");printf("※※\n");printf("※※※※※※※※※※※※※※※※※※※※※※※※\n");exit(0);}}}}elseprintf("密码错误,请您重新进入系统\n");return 0;}else return 0;}void Find()/*查找*/{int i;intchoose,t;charans[100];do{printf("※※※※※※※※※※※※※※※※※※※※※※※※\n");printf("※※\n");printf("※ 1.按书名查找※\n");printf("※ 2.按作者名查找※\n");printf("※▲返回主菜单(输入其他数字)※\n");printf("※※\n");printf("※※※※※※※※※※※※※※※※※※※※※※※※\n");printf("输入选项代号:");scanf("%d",&choose);if(choose==1){printf("输入所查书名:\n");scanf("%s",ans);t=-1;if(choose==1){for(i=0;i<MAX;i++)if(strcmp(ans,book[i].name)==0){t=i;printf("%d %s %s %s %s %s %2f\n",book[t].num,book[t].name,book[t].author,bo ok[t].fn,book[t].place,book[t].day,book[t].money);}}if(t==-1)printf("不存在该信息\n");}else if(choose==2){printf("输入所查作者名:\n");scanf("%s",ans);t=-1;if(choose==2){for(i=0;i<MAX;i++)if(strcmp(ans,book[i].author)==0){t=i;printf("%d %s %s %s %s %s %2f\n",book[t].num,book[t].name,book[t].author,bo ok[t].fn,book[t].place,book[t].day,book[t].money);}}if(t==-1) printf("不存在该信息\n");}else return;}while(1);}void Output()/*输出*/{FILE *fp;int i;fp=fopen("book","rb");printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n");printf(" 图书列表\n");printf("-----------------------------------------------------------\n");printf("图书编号书名作者名分类号出版单位出版时间价格\n");printf("-----------------------------------------------------------\n");for(i=0;fread(&book[i],sizeof(struct book),1,fp)==1;i++){printf("%6d %8s %8s %8s %8s %8s %10.2f\n",book[i].num,book[i].name,book[i]. author,book[i].fn,book[i].place,book[i].day,book[i].money);}fclose(fp);}void Input()/*输入*/{FILE *fp;int n;fp=fopen("book","ab");/*建立一个新二进制文件*/for(n=0;n<MAX;n++){printf("n=%d 输入序号n(当输入n=-1时,返回),n=",n++);scanf("%d",&n);if(n==-1){fclose(fp);return;/*默认不返回值*/}else{printf("请输入图书编号书名作者名分类号出版单位出版时间价格\n");scanf("%d%s%s%s%s%s%f",&book[n].num,book[n].name,book[n].author,book[n ].fn,book[n].place,book[n].day,&book[n].money);fwrite(&book[n],sizeof(struct book),1,fp);/*写入文件*/}}fclose(fp);}void Delete()/*删除*/{FILE *fp;inti,flag,n,s,j;fp=fopen("book","rb+");rewind(fp);printf(" 图书列表\n");printf("-----------------------------------------------------------\n");printf("图书编号书名作者名分类号出版单位出版时间价格\n");printf("-----------------------------------------------------------\n");for(i=0;fread(&book[i],sizeof(struct book),1,fp)==1;i++){printf("%6d %8s %8s %8s %8s %8s %10.2f\n",book[i].num,book[i].name,book[i].auth or,book[i].fn,book[i].place,book[i].day,book[i].money);printf("\n");}n=i;printf("输入待删除图书编号:\n");scanf("%d",&s);for(i=0,flag=1;flag&&i<n;i++){if(s==book[i].num){for(j=i;j<n-1;j++){book[j].num=book[j+1].num;strcpy(book[j].name,book[j+1].name);strcpy(book[j].author,book[j+1].author);strcpy(book[j].fn,book[j+1].fn);strcpy(book[j].place,book[j+1].place);strcpy(book[j].day,book[j+1].day);book[j].money=book[j+1].money;}flag=0;}}if(!flag)n=n-1;elseprintf("没有此号\n");fp=fopen("book","wb");for(i=0;i<n;i++)fwrite(&book[i],sizeof(struct book),1,fp);fclose(fp);fp=fopen("book","r");printf(" 图书列表\n");printf("-----------------------------------------------------------\n");printf("图书编号书名作者名分类号出版单位出版时间价格\n");printf("-----------------------------------------------------------\n");for(i=0;i<n;i++){fread(&book[i],sizeof(struct book),1,fp);printf("%6d %8s %8s %8s %8s %8s %10.2f\n",book[i].num,book[i].name,book[i].auth or,book[i].fn,book[i].place,book[i].day,book[i].money);printf("\n");}fclose(fp);}void Change()/*修改*/{FILE *fp;inti,num,n;int flag=0;printf("请输入要修改的图书编号:");scanf("%d",&num);for(i=0;i<=MAX;i++)if(book[i].num==num){printf(" 图书列表\n");printf("-----------------------------------------------------------\n");printf("图书编号书名作者名分类号出版单位出版时间价格\n");printf("-----------------------------------------------------------\n");printf("%6d %8s %8s %8s %8s %8s %10.2f\n",book[i].num,book[i].name,book[i].auth or,book[i].fn,book[i].place,book[i].day,book[i].money);printf("-----------------------------------------------------------\n\n");n=i;flag=1;break;}if(flag==0){printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n");printf("※输入错误! ※\n");printf("※请返回! ※\n");printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n");return;}printf("\n\n\n");fp=fopen("book","rb+");fseek(fp,n*sizeof(struct book),0);printf("图书编号书名作者名分类号出版单位出版时间价格\n");scanf("%d%s%s%s%s%s%f",&book[n].num,book[n].name,book[n].author,book[n].fn, book[n].place,book[n].day,&book[n].money);fwrite(&book[i],sizeof(struct book),1,fp);fclose(fp);fp=fopen("book","rb");printf(" 图书列表\n");printf("-----------------------------------------------------------\n");printf("图书编号书名作者名分类号出版单位出版时间价格\n");printf("-----------------------------------------------------------\n");for(i=0;fread(&book[i],sizeof(struct book),1,fp)==1;i++){printf("%6d %8s %8s %8s %8s %8s %10.2f\n",book[i].num,book[i].name,book[i].auth or,book[i].fn,book[i].place,book[i].day,book[i].money);}printf("-----------------------------------------------------------\n\n");fclose(fp);}void Paixu()/*排序*/{FILE *fp;inti,max,s;fp=fopen("book","rb");for(s=0;fread(&book[s],sizeof(struct book),1,fp)==1;s++);for(i=0;i<s-i;i++){if(book[i].money>book[i+1].money){max=i;temp=book[i];book[i]=book[i+1];book[i+1]=temp;}}printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n");printf(" 图书列表\n");printf("-----------------------------------------------------------\n");printf("图书编号书名作者名分类号出版单位出版时间价格\n");for(i=0;i<s;i++){printf("%6d %8s %8s %8s %8s %8s %10.2f\n",book[i].num,book[i].name,book[i]. author,book[i].fn,book[i].place,book[i].day,book[i].money);}printf("-----------------------------------------------------------\n");getchar();}。

C语言图书管理系统源代码

C语言图书管理系统源代码

/*需要在源代码相同目录下创建四个txt文件:,,,*/#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语言图书管理系统代码

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); //删除图书页脚内容1void 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()页脚内容2{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();页脚内容3switch(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");}页脚内容4else{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");页脚内容5printf(" **********************************************\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;}页脚内容6else{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;}页脚内容7case 2:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{deletebook(head);getchar();break;}break;case 3:head=load();if(head==NULL){页脚内容8printf("文件为空,请先录入数据!\n");getchar();break;}else{print_book(head);getchar();break;}case 4:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{页脚内容9paixu(head);getchar();}break;case 5:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{chaxun(head);getchar();}break;case 6:页脚内容10head=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();页脚内容11scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;default:printf("您的输入有误,请重新输入!\n");getchar();break;}页脚内容12}}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];页脚内容13float 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();页脚内容14printf("请输入出版时间:");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)页脚内容15head=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{页脚内容16printf("请输入图书名:");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);页脚内容17getchar();}}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);页脚内容18n=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);页脚内容19getchar();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;页脚内容20while((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;页脚内容21}//验证添加的图书编号是否已存在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;}页脚内容22//将新链表写入文件中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->p rice);}fclose(fp);}页脚内容23//从文件中读取图书信息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页脚内容24);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)页脚内容25{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->bna me,ptr->wname,ptr->press,ptr->sort,ptr->time,ptr->price);printf("==========================================================\n");}//删除图书信息页脚内容26void 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;页脚内容27case '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){页脚内容28p2->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");页脚内容29getchar();}}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;页脚内容30}}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;}页脚内容31}}}//图书查询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();页脚内容32switch(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);页脚内容33break;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)页脚内容34break;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");}页脚内容35}//按图书名查询图书信息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;}页脚内容36if(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("==================================================================页脚内容37=======\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;页脚内容38}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;页脚内容39}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;页脚内容40while(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){页脚内容41if(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("请选择您要查询的图书出版时间:");页脚内容42scanf("%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("==================================================================页脚内容43=======\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){页脚内容44int 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("页脚内容45============================================================\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:页脚内容46printf("请输入新图书名:");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);页脚内容47printf("修改成功!\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);页脚内容48printf("请输入新图书名:");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);页脚内容49getchar();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':页脚内容50。

C语言 图书信息管理系统 最终源代码

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语言图书管理系统代码

C语言图书管理系统代码

C语言图书管理系统代码WTD standardization office【WTD 5AB- WTDK 08- WTD 2C】#i n c l u d e<> #include<>#include<>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(); f\n",ptr->num,ptr->bname,ptr->wname,ptr->press,ptr->sort,ptr->time,ptr->price);printf("==========================================================\n");}f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);printf("================================================================== =======\n");}}f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);}p=p->next;}printf("================================================================== =======\n");}}f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("================================================================== =======\n");}}f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("================================================================== =======\n");}}f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("================================================================== =======\n");}}f **\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;}}f **\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;}}f **\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;}}f **\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;}}f **\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语言课程设计图书馆管理系统程序代码

#include<stdio.h>#include<windows.h>#include<string.h>#include<conio.h>#define M 100struct books{char tsmc[12];int tsbh;float dj;char zz[12];char czzt[12];char xm[12];char xb[12];int xh; }s[M];int N;bool flag;intmain (){int sele;flag=0;sele=1;void sr();void cx();void sc();void js();void hs();void tc();void jsh();//system ("tsgl");printf("\n\n");printf(" ************************\n");printf(" 1:输入2:查询3:删除\n");printf(" 4:借书5:还书0:退出\n");printf(" ************************\n"); while(1){printf("\n\n请输入功能序号:");scanf ("%d",&sele);if(sele>=0 && sele<=5){switch(sele){ case 1:sr();break;case 2:cx();break;case 3:sc();break;case 4:js();break;case 5:hs();break;case 0:jsh();break;}if(flag)break;printf("\n\n");printf(" ************************\n");printf(" 1:输入2:查询3:删除\n");printf(" 4:借书5:还书0:退出\n");printf(" ************************\n");}else{printf("输入错误请再次输入|\n\n");printf("\n\n");printf(" ************************\n");printf(" 1:输入2:查询3:删除\n");printf(" 4:借书5:还书0:退出\n");printf(" ************************\n");}printf("\n\n让任意键继续\n");} //wr_file();} /******主函数***//*********输入*********/void sr(){int n,i;N=0;printf("可输入的书本数:");scanf("%d",&n);N=n+N;printf("请输入相关信息:\n");for(i=1;i<=n;i++){printf("图书名称:");scanf("%s",s[N-n-1+i].tsmc);printf("图书编号:");scanf("%d",&s[N-n-1+i].tsbh);printf("单价:");scanf("%f",&s[N-n-1+i].dj);printf("作者:");scanf("%s",&s[N-n-1+i].zz);strcpy(s[N-n-1+i].czzt,"未借出");strcpy(s[N-n-1+i].xm,"无"); } }/********查询**********/void cx(){int i,j[100]={-1},d,k,t=0;char m[20];printf("查询:");printf("1:图书名称2:图书编号");printf("\n\n请输入查询选项:");scanf("%d",&k);if(k==1){printf("请输入图书名称:");scanf("%s",m);for(i=0;i<N;i++)if(strcmp(m,s[i].tsmc)==0){j[t]=i;t=t+1;}}else if(k==2){printf("请输入图书编号:");scanf("%d",&d);for(i=0;i<N;i++)if(d==s[i].tsbh){j[t]=i;t++;}}if(j[0]==-1&&t==0)printf("没有找到!\n");if(j[0]!=-1 && t!=0){printf("\t图书名称\t图书编号\t单价\t作者\t存在状态\t借书人姓名\t性别\t学号\n");for(i=0;i<t;i++)printf("\t%s \t%d \t%f \t%s \t%s \t%s \t%s \t%d ", s[j[i]].tsmc,s[j[i]].tsbh,s[j[i]].dj,s[j[i]].zz,s[j[i]].czzt,s[j[i]].xm,s[j[i]].xb,s[j[i]].xh);}}/********删除模块*********/void sc(){int i,d,k,t=0;char ms[20];int ja=-1;printf("查询:");printf("1:图书名称2:图书编号");printf("\n\n请输入查询选项:");scanf("%d",&k);if(k==1){printf("请输入图书名称:");scanf("%s",ms);for(i=0;i<N;i++)if(strcmp(ms,s[i].tsmc)==0){ja=i; break;}}else if(k==2){printf("请输入图书编号:");scanf("%d",&d);for(i=0;i<N;i++)if(d==s[i].tsbh){ja=i;break;}}printf("确定删除该图书吗?1表示Yes,其他No");int p;scanf("%d",&p);if(p==1)printf("Congratulations,删除成功||\n");if(ja!=-1 && p){N=N-1;for(i=ja;i<N;i++){strcpy(s[i].tsmc,s[i+1].tsmc);s[i].tsbh=s[i+1].tsbh;s[i].dj=s[i+1].dj;strcpy(s[i].zz,s[i+1].zz);strcpy(s[i].czzt,s[i+1].czzt);strcpy(s[i].xm,s[i+1].xm);strcpy(s[i].xb,s[i+1].xb);s[i].xh=s[i+1].xh;}}else if(ja==-1)printf ("没有找到!\n"); }/**********借书模块***********/void js(){int i,j[100]={-1},d,k,t=0;char m[20];printf("查询:");printf("1:图书名称2:图书编号");printf("\n\n请输入查询选项:");scanf("%d",&k); if(k==1){printf("请输入图书名称:");scanf("%s",&m);for(i=0;i<N;i++)if(strcmp(m,s[i].tsmc)==0){j[t]=i;t=t+1;}}else if(k==2){printf("请输入图书编号:");scanf("%d",&d);for(i=0;i<N;i++)if(d==s[i].tsbh){j[t]=i;t++;}}if(j[0]==-1&&t==0)printf("没有找到!\n");strcpy(s[j[i]].czzt,"已借出");printf("此书已借出\n");if(j[0]!=-1&&t!=0&&s[j[i]].czzt==" 未借出"){printf("%s %d %f %s %s %s %s %d ", s[j[i]].tsmc,s[j[i]].tsbh,s[j[i]].dj,s[j[i]].zz,s[j[i]].czzt,s[j[i]].xm,s[j[i]].xb,s[j[i]].xh); }printf("1:确定借阅2:退出\n");scanf("%d",&k);switch(k){case 1:printf("请输入学号:\n");scanf("%d",&s[j[i]].xh);printf("请输入姓名:\n");scanf("%s",&s[j[i]].xm);printf("请输入性别:\n");scanf("%s",&s[j[i]].xb);strcpy(s[j[i]].czzt,"已借出");printf("已借出,按任意键继续\n");//getch();case 2:break;}}/*************还书模块***************/void hs(){int i,j[100]={-1},d,k,t=0;char m[20];printf("查询:");printf("1:图书名称2:图书编号");printf("\n\n请输入查询选项:");scanf("%d",&k);if(k==1){printf("请输入图书名称:");scanf("%s",&m);for(i=0;i<N;i++)if(strcmp(m,s[i].tsmc)==0){j[t]=i;t++;break;}}else if(k==2){printf("请输入图书编号:");scanf("%d",&d);for(i=0;i<N;i++)if(d==s[i].tsbh){j[t]=i;t++;break;}}if(t==0)printf("没有找到!\n");else{printf("%s %f %s %s %s %s %d \n",s[j[i]].tsmc,s[j[i]].dj,s[j[i]].zz,s[j[i]].czzt,s[j[i]].xm,s[j[i]].xb,s[j[i]].xh);printf("1:确定归还2:退出\n");int p;scanf("%d",&p);if(p==1){strcpy(s[j[i]].czzt,"未借出");strcpy(s[j[i]].xm,"无");s[j[i]].xh=0;printf("已归还,按任意键继续\n");}//getch();}}/*************结束模块***************/void jsh(){flag=1;}。

C语言图书管理系统代码

C语言图书管理系统代码

C语言图书管理系统代码 Last updated on the afternoon of January 3, 2021#i n c l u d e<> #include<>#include<>structbook{intnum;charbname[50];charwname[20];charpress[50];charsort[50];inttime;floatprice;structbook*next;};structbook*creatbook();f\n",ptr->num,ptr->bname,ptr->wname,ptr->press,ptr->sort,ptr->time,ptr->price);printf("======================================================= ===\n");}f**\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);printf("======================================================= ==================\n");}}f**\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);}p=p->next;}printf("============================================================ =============\n");}}f**\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("============================================================ =============\n");}}f**\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("============================================================ =============\n");}}f**\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("============================================================ =============\n");}}f**\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;}}f**\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;}}f**\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;}}f**\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;}}f**\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语言)

图书管理系统代码(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 (structbook *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) ; //按作者名查询图书voidsort_chaxun(struct book *head) ; //按类另lj查询图书void time_chaxun(structbook *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=l, c, cl=123456;char a, d, b[10], bl[10]="201102520116";struct book *head=NULL;while(y){system("cis");printf ("\n\n\n\n\n\n\n");printf (z ********** 欢迎光临**********\n\n,z);printf (,z ********************** 图书信息管理系统printf C\n\n');printf C ™=_1—用户登录=_==\十);二二二二二二二二二二二二0-退出系统二二二二二二二二二二二\『);printf Cprintf f请输入您的选择「);scanf (,z%d,z, &n);printf("\n");getchar ();switch(n) {case 0:y 二0;break;case 1:printf C请输入您的用户名:〃);gets(b);printf C\n");printf C请输入您的密码:“);scanf("%d", &c);printf("\n");if(strcmp(b, bl)!=0 |c!=cl){printf C验证失败,请重新输入!\n〃);scanf &d);getchar ();system("cls");}else {printf ("验证通过!请按Enter键进入!\n"); scanf("%c", &d);getchar ();x二1;while(x){ system("cis");printf C --------------------- \n"); printff *图书信息管理系统*\n 〃); printf C --------------------- \n\rT); • I • '.I"■、』•-1"• I • '.I" ■、』•-1"■、/• I • '.I" ■、』•-1"■、/• I • '.I" ■、』•-1"■、/• I • '.I" ■、』•-1" ■、/ • I • '.I" \ \1 •viw vaw vVw vTw vVwvaw vgW viw vaw vVw vTw vVwvaw vgW viw vaw vVw vTw vVwvaw vgW viw vaw vVw vTw vVwvaw vgW viw vaw vVw vTw vVw vaw vgW viw vaw vVw vTw viw »Tw 、『(、『]•、.• \ \ 1 • viw viw vaw vTw viw viw viw viw vTW viwvaw vaw viw viw viw viw vTW viw vaw vaw viw viw viw viw vTW viw vaw vaw viw viw viw viw vTW viw vaw vaw viw viw viw viw vTW viw vaw vaw viw »Tw•”f.・•工・•」・• —I" ■、尸■、■•■、丿•工・•」・• —I"■、尸■、■•■、丿•工・•」・• —I"■、尸■、■•■、丿•工・•」・• —I" ■、尸■、■• ■、丿•工・•」・• —I"■、尸■、■• ■、丿•工・•」・• —I"■、,\ \1 •VBW VIW VIW VSW VBW VCW VIW VIW VIW VIW VBW VBW vYw VIW VIW VIW VIW VBW VBW vYwVIW VIW VIW VIW VBW VBW vYw V IW VIW VIW VIW VBW VBW vYwVIW VIW VIW VIW VBW VIW»Tw 、『(、[]• (_•・.l ・■、』•工・•丄• •」•• •丄••丄• •■l ・■、』•工・•丄• •」•• •丄••丄• •■1・■、』•工・•丄• •」•• •丄• •丄• •■1・■、』•工・•丄••」•• •丄••丄• •■1・■、』•工・•丄• •」•• •丄• •丄•■、』•工・•丄• •」.• \ \ 1 •v^w viw vaw vTw vawv^w viw vaw vaw vawv^w viw vaw vaw vawv^w viw vaw vaw vawv^w viw vaw vaw vawv^w viw vaw viw ^«w | I 、了]printf C 请输入所选择的序号:〃); scanf("%d", &choice); getchar (); system("cls"); switch(choice) case 0: x=0;break; case 1: head=load(); if (head=NULL) {printf C 文件为空,请先录入数据! \n 〃); getchar (); break; } else {head=addbook(head); printf ("添加成功! \n");printff 是否将新信息保存到文件?(y/n)\n 〃); scanf&a);printf (”II 1-添加图书 2-删除图书I\n\n");printf (" II 3-图书列表 4-图书排序 I \n\rT); printf (“II 3-查询图书 6-修改图书 I \n\rT); printf (“ II 7-录入数据 0-退岀系统 I \n\rT);printf Cprintf (”printf ("printf (”getchar ();switch(a){case , n,:break;case ' y‘ :fprint(head);printf ("保存成功! \n");getchar ();break;}break;}case 2:head=load();if (head=NULL) {printf C文件为空,请先录入数据! \n〃);getchar ();break;}else{deletebook(head);getchar ();break;}break;case 3:head=load();辻(head==NULL){printf ("文件为空,请先录入数据!\n");getchar ();break;}else{print_book(head);getchar ();break;}case 4:head二load ();辻(head==NULL) {printf ("文件为空,请先录入数据! \『);getchar ();break;}else{paixu (head);getchar ();}break;case 5:head二load ();辻(head==NULL){printf ("文件为空,请先录入数据!\n");getchar ();break;}else{chaxun(head);getchar ();}break;case 6:head=load();辻(head二二NULL){printf C文件为空,请先录入数据!\n");getchar ();break;}else {xiugai(head);getchar ();break;}break;case 7:printf (〃注意:输入图书编码为0时结束! \rT);head=creatbook ();printf r是否将输入的信息保存到文件以覆盖文件中已存在的信息?(y/n)\n");getchar ();scanf (“%c", &a);getchar ();switch(a){case ' n :break;case ' y‘ :fprint(head);printf ("保存成功! \n");getchar ();break;}break;default:printff您的输入有误,请重新输入! \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; printfC请输入图书编号:〃);scanf&num);printff请输入图书名:〃);scanfbname);getchar ();printff请输入作者名:〃);scanf wname);getchar ();printfC请输入出版社:“);scanfpress);getchar ();printfC请输入类别:“);scanf (〃%s: sort);getchar ();printfC请输入出版时间:“);scanf&time);getchar ();printf ("请输入价格:");scanf("%f", &price);getchar ();while(l) {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{printff请输入图书编号:〃);scanf&num);n=yanzheng(head, num);辻(n=0)break;elseprintff您输入的编号已存在,请重新输入! \n〃); }while(1);if(num==0) break;else printfC请输入图书名:〃);scanfbname);getchar ();printff请输入作者名:〃);scanf wname);getchar ();printff请输入出版社:“);scanfpress);getchar ();printfC请输入类别:");scanfsort);getchar ();printfC请输入出版时间:”); scanf ("%d", &time);getchar ();printf ("请输入价格:”);scanf("%f", &price);getchar ();}}return head;}〃插入结点,并且插入后仍按一定顺序struct book *addbook (struct book *head) struct book *ptr, *pl, *p2, *p;char bname[50], wname[20], press[50_, sort[50];int size=sizeof(struct book):int num, time, n=l:float price;do{printff请输入图书编号:“);scanf&num);n=yanzheng(head, num);if (n=0)break;elseprintf (〃您输入的编号已存在,请重新输入! \n〃);}while(1);printf C请输入图书名:〃);scanfbname);getchar ();printf r请输入作者名:〃);scanf wname);getchar ();printf C请输入出版社:〃);scanfpress);getchar ();printfC请输入类别:〃);scanf(〃%s〃, sort);getchar ();printfC请输入出版时间:“);scanf &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)){pl二p2;p2二p2-〉next;}if(ptr->num<=p2->num){if (head=p2)head二ptr;else {pl->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-'nunFp)break;p=p->next;}辻(p二二NULL)return 0;elsereturn 1;}//将新链表写入文件中void fprint (struct book *head){FILE *f p;char ch二'1’ ;struct book *pl;if ((fp 二 f open ("fl. txt", "w"))=NULL) {printf (,z File open error!\n z/):exit(0);}fputc(ch, fp);for(pl二head;pl;pl二pl->next) {fprintf (fp,,z%d %s %s %s %s %d %f\n,z, pl->num, pl->bname, pl->wname, pl->press,pl-〉sort,pl-〉time, pl-〉price);}fclose (fp);}//从文件中读取图书信息struct book *load()FILE *fp;char ch;struct book *head,*tail,*pl:head二tail二NULL;if ((fp 二 f open ("fl. txt", "r"))=NULL) {printf (,z File open error!\n z/):exit(O);}ch=fgetc (fp);辻(ch='l'){while(!feof(fp)) {pl=(struct book *)malloc(sizeof(struct book)):fscanf (fp, z,%d%s%s%s%s%d%f\n, &pl->num, pl->bname, pl->wname, pl- >press,pl-〉sort, &pl-〉time, &pl->price);辻(head二二NULL)head=pl;elsetail->next=pl;tail=pl;}tail-〉next二NULL;fclose (fp);return head;}elsereturn NULL;}〃将整个链表的信息输出void print_book(struct book *head) {struct book *ptr;辻(head=NULL) {printf ("\n 没有信息!\n");return;}printf r图书信息列表如下\n);printf C============================+)printfC编号图书名作者名出版社类别出版时间价格\n〃);for(ptr=head;ptr;ptr=ptr->next)printf (,z %d %s %s %s %s %d%・ 2f\n z/, ptr->num, ptr->bname, ptr->wname, ptr-〉press, ptr-〉sort, ptr->time, ptr-〉price);}printf CW);}//删除图书信息void deletebook(struct book *head) {int a;char b, ch二'1’ ;struct book *pl,*p2;FILE *fp;printff请输入要删除的图书编号:〃);scanf&a);pl=head;if (pl->num~a&&pl->next==NULL) { //对于文件中只有一组数据printfC是否清空文件!(y/n)\『);getchar ();scanf&b);getchar ();switch (b) {case ' n :break;case ' y‘ :if ((fp 二 f open ("fl. txt", "w"))=NULL) {printf (,z File open error!\n z,):exit(O);}fclose (fp);printf C文件已清空! \rT);}}else {while (pl->num!二a&&pl-〉next!二NULL) {p2二pl;pl=pl->next;}if (pl->next=NULL) {if (pl->num==a){p2-〉next二NULL;printfC是否确定从文件中彻底删除该图书?(y/n)\n,z); getchar ();scanf&b);switch (b) {case ' n :break;case ' y‘ :fprint(head);printf ("删除成功!\n");getchar ();break;}}else {printf (〃没有找到要删除的数据! \『);getchar ();}}else if(pl==head) {head=pl~>next:printf("是否确定从文件中彻底删除该图书?(y/n)\n"); getchar (); scanf &b);switch(b){case ' n :break;case ' y‘ :fprint (head);PrintfC 删除成功!\n〃);getchar ():break;}}else{p2-〉next二pl->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 C ** 1-按图书编号查询2-按图书名查询和<\『);printf (,z ** 3-按图书类别查询4-按作者名查询和<\n〃);printf C ** 5-按出版时间査询0-退出查询**\n");printf C============================\n );printf C请输入所选择的编号:〃);scanf&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:t ime_chaxun(head); break;default:printf ("您的输入有误! \n"); break;}//按编号查询图书信息void num_chaxun(struct book *head){int a;struct book *p;printff请选择您要查询的图书编号:〃); scanf&a);getchar ();p二head;while(p!=NULL){if (p->num==a)break;p=p->next;}辻(p二二NULL){printfC没有找到该编号的图书!\n〃);}else {printfC你所查询的图书信息如下\n〃); printf C二二二\『);printfC * *编号图书名作者名岀版社类别岀版时间}价格**\n9 ;printf("** %d %s %s %s %s %d %. 2fp->num, p->bname, p->wname, p->press, p->sort, p->time, p->price); printf C=\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=l;break;p=p->next; }}辻(flag=O) {printff没有找到该图书名的图书!\n〃);}else {printf(〃你所查询的图书信息如下\n〃);printf C二二二\『);printf (〃桂编号图书名作者名出版社类别出版时间价格桂\n〃);while(p!=NULL){if(strcmp(p->bname, a)==0){printf("** %d %s %s %s %s %d %. 2f**\n,z, p->num, p->bname, p->wname, p->press, p->sort, p->time, p->price); }p=p->next;}printf C}===\n,z); }〃按作者名查询图书信息void wname_chaxun(struct book *head) { char a[50];int flag^O;struct book *p;printff请选择您要查询的图书作者名:〃); gets (a);p二head;while(p!=NULL){if (strcmp (p->wname, a) ==0) {flag=l;break;}p=p->next;}if(flag=0) {printff没有找到该图书名的图书!\n〃);}printf Celse {printfC你所查询的图书信息如下\n〃);printf C=\n〃);printfC **编号图书名作者名出版社类别出版时间价格while(p!=NULL){if (strcmp (p->wname, a) ==0) {printf("** %d %s %s %s %s %d %. 2fp->num, p->bname, p->wname, p->press, p->sort, p->time, p->price); flag=l;}p=p->next;}printf C=\n〃);}}〃按图书类别查询图书信息void sort_chaxun(struct book *head) {char a[50];int flag=0;struct book *p;printf C请选择您要查询的图书类别:〃);gets (a);p=head;while(p!=NULL){if(strcmp(p->sort, a)==0) {flag=l;break;}p二p->next;}辻(flag=O) {printff没有找到该图书名的图书!\n〃);}else {printf ("你所查询的图书信息如下\n〃);printf C=\『);printf (,z **编号图书名作者名出版社类别出版时间价格杯\n"); while(p!=NULL){if(strcmp(p->sort, a)==0) {printf C** %d %s %s %s %s %d %. 2f**\n,z, p->num, p->bname, p->wname, p->press, p->sort, p->time, p->price); flag=l;}p=p->next;}printf C=\『);}}〃按图书出版时间查询图书信息void time^chaxun(struct book *head) {int a,flag=0;struct book *p;printf r请选择您要查询的图书出版时间:〃);scanf("%d", &a);getchar ();p=head;while(p!=NULL){if (p->time==a) {flag=l;}break; }p=p->next;}if(flag=O) {printff没有找到该图书名的图书!\n〃);}else {printff你所查询的图书信息如下\n〃);printf(”=\n");printf (〃桂编号图书名作者名出版社类别出版时间价格while(p!=NULL){if(p->time==a){printf("** %d %s %s %s %s %d %. 2fp->num, p->bname, p->wname, p->press, p-〉sort, p->time, p-〉price);flag=l;}p二p-〉next;printf("}=\n");}}//修改图书信息void xiugai(struct book *head) {int a, b;char c;struct book *p;printfC请输入要修改的图书编号:〃);scanf&a);p=head;while(p!=NULL){if (p->num==a)break;p=p->next;}if(p二二NULL){printfC没有找到该编号的图书!\n〃); getchar ();}else {printf CW);printf r ** 1-编号2-图书名3-作者名printf C ** 4-出版社5-类别6-出版时间*水\n");printf C ** 7-价格8-修改全部0-放弃修改**\n");printf C============================\n");printf C请选择你要修改的信息编号:〃);scanf&b);getchar ();switch (b) {case 1:printf r请输入新编号:“);scanf&p->num);printf ("修改成功! \n");getchar ();break;case 2:printf r请输入新图书名:“);gets (p->bname);printf ("修改成功! \n");break;case 3:printff请输入新作者名:“);gets(p->wname);printf ("修改成功!\n"); break;case 4:printf r请输入新出版社:”);gets(p->press);printf ("修改成功! \n"); break;case 5:printf r请输入新类别:”);gets(p->sort);printf ("修改成功! \n"); break;case 6:printf r请输入新出版时间:“); scanf&p~>time);printf ("修改成功!\n"); getchar ();break;case 7:printf r请输入新价格:“); scanf ("%f", &p->price); printf ("修改成功! \n");getchar ();break;case 8:printf r请输入新图书编号:“);scanf&p->num);printf C请输入新图书名:“);scanf p->bname);getchar ();printf C请输入新作者名:“);scanf p->wname);getchar ();printf r请输入新出版社:”);scanfp->press);getchar ();printf r请输入新类别:“);scanf(〃%s: p->sort);getchar ();printf r请输入新出版时间:“);scanf&p->time);getchar ();printf r请输入新价格:〃);scanf ("%f", &p->price);getchar ();printf ("修改成功! \n");getchar ();break;case 0:break;default :printf C您的输入有误! \n");break;}printf C是否将修改后的信息保存到文件中?(y/n)\rT); scanf&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 r ** 1-按图书编号排序2-按出版时间排序**\n");printf C ** 3-按图书价格排序4-按图书名排序**\n z/);printf C ** 5-按作者名排序0-取消排序操作材\n");printf (”___________________________________________________________________ \〃\ . \AX / f printf C请输入您选择的编号:〃);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 C您的输入有误! \n");break;}}〃按图书编号排序void num_paixu(struct book *head) {struct book *a[1000], *p, *pl, *temp; int i, k, index, n=0;for(p=head;p;p=p->next)n++;。

图书管理系统C语言实现源代码

图书管理系统C语言实现源代码
} } return 0; }
//建立链表,并输入数据 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;

C语言编写的图书借阅管理系统源代码

C语言编写的图书借阅管理系统源代码

C语言编写的图书借阅管理系统源代码C语言编写的图书借阅管理系统源代码#include <dos.h>#include <bios.h>#include <conio.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#define LEFT 0x4b00 /*左*/#define RIGHT 0x4d00 /*右*/#define DOWN 0x5000 /*下*/#define UP 0x4800 /*上*/#define SPACE 0x3920 /*空格*/#define ESC 0x011b /* ESC键*/#define ENTER 0x1c0d /*回车键*/#define Backspace 0xe08 /*擦除键*/#define ALT_B 12288 /*组合键ALT_B */#define ALT_M 12800/*组合键ALT_M */#define ALT_H 8960/*组合键ALT_H */int key;/*按键变量*/int textx,texty;/*光标坐标,x行,y列*/struct menustruct/*菜单用的结构体*/{char name[10];/*主菜单名*/char str[10][20];/*选项*/int n;/*选项数*/}ml[3];/*使用了3个,可根据需要增删*/typedef struct BookList/*书的结构体*/{char num[20];/*图书编号*/char name[20];/*书名*/int price;/*书的价格*/char person[20];/*借阅人*/int yes;/*判断书是否存在或者已经借出,1存在,0借出*/ struct BookList *next;}Book;typedef struct MemberList/*会员的结构体*/{char name[20];/*会员的姓名*/char sex[2];/*会员的性别*/int age;/*会员的年龄*/struct MemberList *next;}Member;char save[4096];/*保存文本区域空间*//*char sav1[4096];*/char c[4096];/*清屏专用空间*/int i,j;/*常见变量*/void Menu();/*初始化界面*/void Selectitem();/*定义菜单*/void DrawSelectitem();/*显示主菜单*/void BlackText(int x,int y,char *z);/*选中菜单*/ void RedText(int x,int y,char *z);/*正常菜单*/ void Run();/*具体操作过程*/void DrawMl(int n);/*显示下拉菜单*/void MoveMl(int n,int x);/*菜单选项的控制*/ void Enter(int m,int n);/*菜单选项的具体功能*/ void BookAdd();/*添加图书*/void BookConsult();/*图书查询*/void BookDel();/*删除图书资料*/void BookBorrow();/*借书*/void BookReturn(); /*还书*/void MemberAdd(); /*增加会员*/void MemberConsult();/*查询会员*/void MemberDel(); /*删除会员*/void MemberBook(); /*查询会员借书信息*/ void Help(); /*帮助*/void Ver(); /*版本信息*/void ClrScr();/*自定义清屏函数*/void DrawFrame(int left,int up,int right,int down,int textcolor,int backgroundcolor);/*画边框*//***主函数****/void main(void){Menu();/*初始化界面*/Run();/*具体操作过程*/}/*初始化界面*/void Menu(){system("cls"); /*调用系统的清屏命令*/textbackground(BLUE);/*将背景设置为蓝色*/window(1,1,25,80);clrscr();textx=3;/*光标初始化位置*/texty=2;gotoxy(1,2);printf("%c",218);/*画左上角*/for(i=0;i<78;i++)printf("%c",196); /*画水平直线*/printf("%c",191);/*画右上角*/for(i=3;i<=23;i++){gotoxy(1,i);printf("%c",179); /*画垂直线*/gotoxy(80,i);printf("%c",179);}printf("%c",192); /*画左下角*/for(i=0;i<78;i++)printf("%c",196);printf("%c",217); /*画右下角*/gotoxy(1,1);textcolor(7); /*设置灰色*/for(i=0;i<80;i++)cprintf("%c",219);/*用符号实现画主菜单的灰色背景区*/ Selectitem(); /*调用选项函数*/DrawSelectitem(); /*画选项*/gettext(2,3,78,23,c); /*保存当前文本区域*/}/*定义菜单*/void Selectitem(){strcpy(ml[0].name,"Book");/*下面的具体选项补空格是为了各菜单黑色背景相同*/strcpy(ml[0].str[0],"Add ");/*添加图书*/strcpy(ml[0].str[1],"Consult ");/*查询图书*/strcpy(ml[0].str[2],"Del ");/*删除图书资料*/strcpy(ml[0].str[3],"Borrow ");/*借书*/strcpy(ml[0].str[4],"Return ");/*还书*/strcpy(ml[0].str[5],"Exit ");/*退出系统*/ml[0].n=6; /*保存菜单的项数*/strcpy(ml[1].name,"Member");strcpy(ml[1].str[0],"Add ");/*添加新会员*/strcpy(ml[1].str[1],"Consult ");/*查询会员资料*/strcpy(ml[1].str[2],"Del ");/*删除会员资料*/strcpy(ml[1].str[3],"Member&book ");ml[1].n=4;strcpy(ml[2].name,"Help");/*系统帮助*/strcpy(ml[2].str[0],"This System ");strcpy(ml[2].str[1],"Ver ");ml[2].n=2;}/*显示主单名*/void DrawSelectitem(){for(i=0;i<3;i++)RedText(i,1,ml[i].name); /*显示主菜单名,且首字母为红色*/ }/*正常显示菜单*/void RedText(int x,int y,char *z){textbackground(7); /*设置背景颜色为浅灰色*/gotoxy(3+x*20,y);for(j=0;z[j];j++){if(j==0)textcolor(RED);/*第一个字母显示红色*/elsetextcolor(BLACK); /*设置黑色*/cprintf("%c",z[j]); /*输出菜单名*/}}/*显示选中菜单*/void BlackText(int x,int y,char *z){textbackground(0); /*设置背景颜色为黑色*/textcolor(15); /*设置文本颜色为白色*/gotoxy(3+20*x,y);/*定位坐标*/cputs(z); /*输出菜单名字符串*/}/*按键操作过程*/void Run(){while(1){gotoxy(texty,textx);key=bioskey(0);/*接收按键*/switch(key){case ALT_B:case ESC: DrawMl(0);break; /*显示下拉菜单1*/case ALT_M: DrawMl(1);break;/*显示下拉菜单2*/case ALT_H: DrawMl(2);/*显示下拉菜单3*/case UP: /*上光标键的操作控制*/{if(textx==3)textx=23;textx--;gotoxy(texty,textx);}break;case DOWN: /*下光标键的操作控制*/ {if(textx==23)textx=3;textx++;gotoxy(texty,textx);}break;case LEFT: /*左光标键的操作控制*/ {if(texty==2)texty=79;texty--;gotoxy(texty,textx);}break;case Backspace: /*擦除键的设置*/{if(texty==2&&textx==3)continue;else{if(texty!=2)texty--; /*擦除键的细节问题,先擦去东西,然后光标还要往后退一格*/elseif(texty==2){texty=78;textx--;}gotoxy(texty,textx);printf(" ");gotoxy(texty,textx);}}break;/*end case 0xe08*/case RIGHT: /*右光标键的操作控制*/{if(texty==79)texty=2;texty++;gotoxy(texty,textx);}break;case SPACE: /*空格键的操作*/{if(texty==79)continue;else{gotoxy(texty,textx); /*空格的细节操作*/printf(" ");texty++;gotoxy(texty,textx);}}break;case ENTER: /*回车的控制操作*/{if(textx==23)continue;textx++;texty=2;gotoxy(texty,textx);}break;default : /*非控制键的结果*/{if(texty==79&&textx==23)/*到达最后就不再输出*/continue;elseif(texty==79&&textx!=23) /*到行的最后*/{textx++;texty=2;}gotoxy(texty,textx);/*输出结果*/printf("%c",key);if(texty==79) /*如果texty==79就不执行*/continue;else /*如果没到行尾就继续执行,使光标向前移动一位*/ texty++;}}}/*大循环的大括号*/}/*画边框函数*/void DrawFrame(int l,int u,int r,int d,int tcolor,int bcolor){textbackground(bcolor); /*背景颜色*/textcolor(bcolor); /*文本颜色*/for(i=l;i<=r;i++) /*输出背景区域*/{for(j=u;j<=d;j++){gotoxy(i,j);printf("%c",219); /*输出背景字符*/}}textcolor(tcolor);/*边框颜色*/for(i=u+1;i<d;i++) /*在背景区域内输出边框线*/ {gotoxy(l,i);cprintf("%c",179); /*垂直线*/gotoxy(r,i);cprintf("%c",179);}for(i=l+1;i<r;i++){gotoxy(i,u);cprintf("%c",196); /*水平线*/gotoxy(i,d);cprintf("%c",196);}gotoxy(l,u);cprintf("%c",218);/*左上角*/gotoxy(r,u);cprintf("%c",191);/*右上角*/gotoxy(l,d);cprintf("%c",192);/*左下角*/gotoxy(r,d);cprintf("%c",217); /*右下角*//* gettext(l+1,u+1,r-1,d-1,save1);*//*保存边框内区域*/}/*显示具体下拉选择项目*/void DrawMl(int n){gettext(1,1,80,25,save);/*保存被掩盖的地方*/BlackText(n,1,ml[n].name);/*反选显示主菜单*/DrawFrame(3+20*n-1,2,3+20*n+19,3+ml[n].n,0,7);/*下拉菜单的边框*/for(i=3;i<3+ml[n].n;i++)/*输出所选菜单各选项*/{if(i==3)BlackText(n,i,ml[n].str[i-3]);/*默认选中第一项*/elseRedText(n,i,ml[n].str[i-3]);/*其余各项首字符红色显示*/}gotoxy(79,1);MoveMl(n,3);/*菜单选项的控制*/}/*菜单选项的控制,n决定水平项,x决定下拉的选项*/void MoveMl(int n,int x){int flag=1;while(flag){gotoxy(79,1);key=bioskey(0);/*接收按键*/gotoxy(79,1);switch(key){case ESC:/*退出循环*/puttext(1,1,80,25,save);/*恢复打开菜单前的样子*/flag=0;break;case LEFT:/*移到左边的选项*/puttext(1,1,80,25,save);/*恢复打开菜单前的样子*/if(n==0)/*往左移动越界的话移到最后一个选项*/DrawMl(2);elseDrawMl(n-1);flag=0;break;case RIGHT:/*移动右边的选项*/puttext(1,1,80,25,save);/*恢复打开菜单前的样子*/if(n==2)/*往右移动越界的话移到第一个选项*/DrawMl(0);elseDrawMl(n+1);flag=0;break;case UP:/*具体选项往上移动*/RedText(n,x,ml[n].str[x-3]);/*输出红色字体*/if(x==3)/*移到最上面再按上键,就移到最下面*/x=3+ml[n].n-1;elsex--;/*移动到新的要显示的内容*/BlackText(n,x,ml[n].str[x-3]);/*输出黑色字体*/flag=1;break;case DOWN:/*具体选项往下移动*/RedText(n,x,ml[n].str[x-3]);if(x==(3+ml[n].n-1))/*移动到最底下再按下键就移到最上面*/x=3;elsex++;/*移动到新的要显示的内容*/BlackText(n,x,ml[n].str[x-3]);flag=1;break;case ENTER:puttext(1,1,80,25,save);/*恢复打开菜单前的样子*/Enter(n,x-3);/*菜单选项的具体功能*/flag=0;break;}gotoxy(79,1);}}/*菜单选项的具体功能*/void Enter(int m,int n){switch(m){case 0:switch(n) /*选择了图书菜单选项*/{case 0:BookAdd();break;/*添加图书*/case 1:BookConsult();break;/*图书查询*/case 2:BookDel();break;/*删除一本图书资料*/case 3:BookBorrow();break;/*借书*/case 4:BookReturn();break;/*还书*/case 5:exit(0);break;} break;/*退出系统*/case 1: switch(n) /*选择了会员菜单选项*/{case 0: MemberAdd();break;/*添加会员*/case 1: MemberConsult();break;/*会员查询*/case 2:MemberDel();break;/*删除一个会员资料*/case 3:MemberBook();/*查询某个会员所借图书情况*/}break;case 2:switch(n) /*选择了帮助菜单选项*/ {case 0:Help();break;case 1:Ver();}}/*结束外switch*/}。

C语言实现图书管理系统代码

C语言实现图书管理系统代码
void storagebook(struct bookinf *b); /*将链表信息存至文件*/
void statistic(); /*统计功能*/
void fine(); /*超期罚款函数*/
case 1:head1=delperson(head1);break; /*删除用户*/
struct bookinf *begin(); /*初始化链表函数*/
void borrowbook(struct bookinf *b1,struct readerinf *p); /*借书*/
void renewbook(struct readerinf *p); /*续借*/
{
char name[30];
char sex[4];
char birthday[20]; /*出生年月*/
char college[20]; /*学院*/
char secretnum[10]; /*secretnum=(密码-20)*2 */
long int ID; /*学号*/
char type[20]; /*读者类型*/
int balance; /*账户余额*/
int bornum; /*当前借阅数*/
char pubdate[20]; /*出版时间*/
int price; /*价格*/
long int ISBN; /*图书编号*/
char category[30]; /*分类*/
int condition; /*是否在架 1:在架 0:已借 2:再借*/
int borrowednum; /*借阅次数*/
struct bookinf *next;

图书管理系统C语言实现代码

图书管理系统C语言实现代码
int number;
char telephone[20];
int NO;
char bookname[20];
int borrowdate;
int returndate;
if((fp=fopen("jieshujilu.txt","r"))==NULL){
scanf("%s",);
fprintf(fp,"%s",);
printf("请输入借书人班级:");
scanf("%s",p.classes);
fprintf(fp," %s",p.classes);
printf("请输入借书人学号:");
scanf("%d",&p.number);
/*随代码必须新建一下文件:jieshujilu.txt shuku.txt tempbook.txt tempshuku.txt */
#include<stdio.h>
#include<stdlib.h>
struct book{
char bookname[20]; //书名
exit(0);
}
printf("请输入此次收到的书本总数:");
scanf("%d",&i);
for(j=0;j<i;j++){
printf("请输入书名:");
scanf("%s",b.bookname);
fprintf(fp,"%s",b.bookname);

c语言图书管理系统源代码

c语言图书管理系统源代码

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");printf("请输入入库数量\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.bookNumber,lurua.publi sher,lurua.publitionTime,lurua.price,lurua.allNumber,lurua.availableNumber);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,lu rua.publisher,&lurua.publitionTime,&lurua.price,&lurua.allNumber,&lurua.availableNumbe r);printf("%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",lurua.bookName,lurua.auther,lurua.bookNumber,lurua.publi sher,lurua.publitionTime,lurua.price,lurua.allNumber,lurua.availableNumber); }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.available Number); 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.bookNumber,book1.p ublisher,book1.publitionTime,book1.price,book1.allNumber,book1.availableNumber);};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.available Number); 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.bookNumber,book1.p ublisher,book1.publitionTime,book1.price,book1.allNumber,book1.availableNumber); 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,l urua.publisher,&lurua.publitionTime,&lurua.price,&lurua.allNumber,&lurua.availableNum ber); 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,xiushan a[i].bookNumber,xiushana[i].publisher,&xiushana[i].publitionTime,&xiushana[i].price,&xiu shana[i].allNumber,&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)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].auther,xiushana[i].bookN umber,xiushana[i].publisher,xiushana[i].publitionTime,xiushana[i].price,xiushana[i].allNu mber,xiushana[i].availableNumber);printf("删除成功。

C语言图书管理系统源代码

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 图书管理系统printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n"); printf(" ┃●[0]退出系统┃\n");printf(” ┃┃\n”);prin tf(” ┃●[1]帮助┃\n");printf(” ┃┃\n”);printf(” ┃●[2]浏览图书┃\n");printf(” ┃┃\n");printf(” ┃●[3]统计图书数目┃\n”);printf(" ┃┃\n”);printf(” ┃●[4]查询┃\n”);printf(” ┃printf(” ┃●[5]添加┃\n");printf(” ┃┃\n”);printf(” ┃●[6]排序┃\n");printf(” ┃┃\n");printf(" ┃●[7]修改┃\n”);printf(” ┃┃\n");printf(" ┃●[8]删除┃\n”);printf(" ┃┃\n”);printf(" ┃●[9]修改账号及密码┃\n");printf(” ┃┃\n”);printf(” ┃●[10]学生信息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.txt添加!\n”); sys tem(”pause”);system(”cls”);menu();}for(p=head1;p!=NULL;p=p—>next){printf(”学生学号密码\n”);printf("%d %s\n",p->snum,p—>mima);}system(”pause”);system("cls”);menu();}else if(choice==0)system(”cls");printf(”\n\n\n\n”);printf(” ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n”);exit(0);}else{system("cls");printf(”\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ");system("pause”);system(”cls”);n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出!━━━━━━━━\n\n\n”);printf(" ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n");system(”pause");exit(0);}goto there;}}void xmenu()/*学生主菜单(学生进入可对图书,密码进行操作)*/{struct tushu *head;struct stu *head1;int choice,n=0;there:printf(”┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n");printf(” ┃┃socat 图书借阅系统┃┃\n");printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n"); printf(” ┃●[0]退出系统┃\n”);printf(” ┃printf(” ┃●[1]帮助┃\n”);printf(” ┃┃\n”);printf(” ┃●[2]浏览图书┃\n");printf(” ┃┃\n”);printf(" ┃●[3]查询┃\n”);printf(” ┃┃\n”);printf(” ┃●[4]借书┃\n");printf(” ┃┃\n”);printf(" ┃●[5]还书┃\n");printf(" ┃┃\n”);printf(” ┃●[6]修改密码printf("┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”); printf(" 请选择:");fflush(stdin);head=create();scanf("%d”,&choice);if(choice==1){//xhelp();printf(”没有内容!\n");system(”pa use");system(”cls”);xmenu();}else if(choice==2){system("cls");if(head==NULL){printf(”没有图书!\n");system("pause”);xmenu();}xBrowse(head);}else if(choice==3){if(head==NULL){printf(”没有图书!\n”);system(”pause”);system(”cls”);xmenu();}xfind();}else if(choice==4){if(head==NULL){printf(”没有图书!\n");system(”pause”);xmenu();}borrow(head);}else if(choice==5){huanshu(head);}else if(choice==6){system("cls”);head1=xcreate();if(head1==NULL){printf(”学生信息被清空!!\n”);system("pause");system("cls”);xmenu();}xmima(head1); ;}else if(choice==0){system("cls");printf(”\n\n\n\n”);printf(” ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n");exit(0);}else{system("cls”);printf("\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system(”pause”);system(”cls”);n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出!━━━━━━━━\n\n\n”);printf(” ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n”);system("pause”);exit(0);}goto there;}}void gfind()/*管理员查询(管理员可按一定的方式查询图书)*/{int choice,n=0;struct tushu *head;there:system(”cls”);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(" ┃● ┃\n”);printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”);printf(" 请选择:”);fflush(stdin);head=create();scanf(”%d”,&choice);if(choice==1){system(”cls");Findofname(head); }else if(choice==2){system(”cls”); Findofwriter(head); }else if(choice==3){system(”cls");Findofkind(head); }else if(choice==0){system(”cls”);menu();}else{system(”cls”);printf(”\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system("pause");system(”cls");n++;if(n==3){printf(" \n\n\n ━━━━━━━━你错误次数太多,自动退出! ━━━━━━━━\n\n\n”);printf(" ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n”);system(”pause”);exit(0);}goto there;}}void xfind()/*学生查询(学生可按一定的方式查询图书)*/ {struct tushu *head;int choice,n=0;there:system("cls”);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(" ┃● ┃\n");printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n"); printf(” 请选择:");fflush(stdin);head=create();scanf(”%d",&choice);if(choice==1){system(”cls”);xFindofname(head);}else if(choice==2){system(”cls”);xFindofwriter(head);}else if(choice==3){system("cls");xFindofkind(head);}else if(choice==0){system(”cls");xmenu();}else{system("cls");printf("\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system(”pause”);system(”cls");n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出!━━━━━━━━\n\n\n”);printf(” ━━━━━━━━感谢使用图书借阅系统━━━━━━━━\n\n\n”);system("pause”);exit(0);}goto there;}}void sort(){struct tushu *head;int choice,n=0;there:system("cls”);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(” ┃●┃\n”);printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”);printf(" 请选择:”);fflush(stdin);head=create();scanf("%d",&choice);if(choice==1){system("cls”); Sort_time(head);}else if(choice==2){sys tem(”cls");Sort_price(head);}else if(choice==3){system(”cls”);Sort_num(head); }else if(choice==0){system("cls”); menu();}else{system(”cls");printf("\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system(”pause”);system(”cls”);n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出! ━━━━━━━━\n\n\n”);printf(” ━━━━━━━━感谢使用图书借阅系统━━━━━━━━\n\n\n”);system("pause”);exit(0);}goto there;}}struct tushu *Input(){struct tushu *p1,*p2,*head,*ptr;char num;int x,i=0;system("cls”);p1=(struct tushu *)malloc(sizeof(struct tushu));head=p1;p1-〉price=—1;while(i!=1){printf(”请输入编号,以’#’结束\n”);scanf("%s",p1—>num);if(strcmp(p1-〉num,”#")==0)i=1;while(i!=1){printf(”请依次输入书名作者出版社类别出版时间价格\n”); scanf(”%s%s%s%s%lf%lf”,p1—>name,p1—>writer,p1—〉press,p1-〉kind,&p1-〉time,&p1—〉price);p2=p1;p1=(struct tushu *)malloc(sizeof(struct tushu));p2—〉next=p1;break;}}if(p1-〉price!=-1)p2—〉next=NULL;elsehead=NULL;system("cls”);printf("\n\n\n\t\t\t图书信息输入结束!\n\n\n”);system(”pause”);system(”cls”);printf(”\n\n\n\t\t\t是否保存图书信息?(1。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#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,&p 1->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;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]->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;}}。

相关文档
最新文档