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课程设计图书管理系统源代码

#include "stdio.h"#include "stdlib.h"#include "string.h"#include "io.h"typedef struct book{char num[15]; //中图分类号char name[20]; //书名char author[20]; //作者char press[20]; //出版单位char time[15]; //出版时间char status[10]; //是否可借double price; //价格int count; //库存量}book;void menu(); //图书馆系统界面void insert(); //插入图书信息记录void browse(); //浏览图书信息void find(); //查找图书信息void deleter(); //删除图书信息void modify(); //修改图书信息void leave(); //退出图书系统void main(){int choice;do{menu();printf("请选择服务项目:");scanf("%d",&choice);switch(choice){case 1:insert();break;case 2:browse();break;case 3:find();break;case 4:deleter();break;case 5:modify();break;case 6:leave();break;default:printf("输入数据错误,请从新输入!");}}while(1);}void menu(){printf("\t====================欢迎进入图书馆系统!=============================\n\n");printf("\t\t*****************1.录入图书信息********************\n");printf("\t\t*****************2.浏览图书信息********************\n");printf("\t\t*****************3.查找图书信息********************\n");printf("\t\t*****************4.删除图书信息********************\n");printf("\t\t*****************5.修改图书信息********************\n");printf("\t\t********************6.退出*************************\n");}void insert(){FILE *fp;book a={"\0","\0","\0","\0","\0","\0",0.0,0};if(access("bookinf.txt",0)) //如果文件不存在,则初始化文件格式{if((fp=fopen("bookinf.txt","w"))==NULL){printf("file creat failure!");exit(0);}fprintf(fp,"中图分类好书名作者出版社出版时间状态价格数量");}else //如果文件存在,则打开文件追加信息{if((fp=fopen("bookinf.txt","a+"))==NULL){printf("file open error!");exit(0);}}printf("请输入图书信息\n");printf("中图分类好书名作者出版社出版时间状态价格数量\n");scanf("%s%s%s%s%s%s%lf%d",a.num,,a.author,a.press,a.time,a.status,&a.price,&a.c ount);printf("%s %s %s %s %s %s %lf %d\n",a.num,,a.author,a.press,a.time,a. status,a.price,a.count);fprintf(fp,"\n%-15s%-20s%-20s%-20s%-15s%-10s%-8.2lf%4d",a.num,,a.author,a.pre ss,a.time,a.status,a.price,a.count); //-为左对齐,必须是“\n和+右对齐”,方便实现browse()函数fclose(fp);}void browse(){FILE *fp;book a={"\0","\0","\0","\0","\0","\0",0.0,0},b=a;if((fp=fopen("bookinf.txt","a+"))==NULL){printf("file open error!");exit(0);}fscanf(fp,"%*[^\n]"); //跳过文本的第一行fscanf(fp,"%*[^\n]%*c");?while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%lf%d",a.num,,a.author,a.press,a.time,a.status,&a.price, &a.count);printf("%-4s%-4s%-4s%-4s%-4s%-4s%-8.2lf%-4d\n",a.num,,a.author,a.press,a.time,a .status,a.price,a.count);a=b;}fclose(fp);}void find(){char str[15]="\0";FILE *fp;int flag=0;book a={"\0","\0","\0","\0","\0","\0",0.0,0},b=a;printf("请输入所要查找图书的中图分类号:");scanf("%s",str);if((fp=fopen("bookinf.txt","r"))==NULL){printf("file open error!\n");exit(0);}fscanf(fp,"%*[^\n]"); //跳过文本的第一行fscanf(fp,"%*[^\n]%*c");?while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%lf%d",a.num,,a.author,a.press,a.time,a.status,&a.price, &a.count);if(!strcmp(a.num,str)){flag=1;printf("所找图书信息为:");printf("%-4s%-4s%-4s%-4s%-4s%-4s%-8.2lf%-4d\n",a.num,,a.author,a.press,a.time,a .status,a.price,a.count);break;}a=b; //b的用处}if(flag==0)printf("您所找的图书不存在!\n");fclose(fp);}void deleter(){char str[15]="\0";int flag=0;FILE *fp,*fp1;book a={"\0","\0","\0","\0","\0","\0",0.0,0},b=a;printf("请输入所要删除图书的中图分类号:");scanf("%s",str);if((fp=fopen("bookinf.txt","r"))==NULL){printf("file open error!");exit(0);}if((fp1=fopen("f.txt","w"))==NULL){printf("file open error!");exit(0);}fprintf(fp1,"中图分类好书名作者出版社出版时间状态价格数量");fscanf(fp,"%*[^\n]"); //跳过文本的第一行fscanf(fp,"%*[^\n]%*c");?while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%lf%d",a.num,,a.author,a.press,a.time,a.status,&a.price, &a.count);if(!strcmp(str,a.num)){flag=1;continue;}fprintf(fp1,"\n%-15s%-20s%-20s%-20s%-15s%-10s%-8.2lf%4d",a.num,,a.author,a.pr ess,a.time,a.status,a.price,a.count);a=b;}fclose(fp1);fclose(fp);remove("bookinf.txt");rename("f.txt","bookinf.txt");if(flag==0)printf("所要删除的图书不存在!\n");elseprintf("删除成功!\n");}void modify(){char str[15]="\0";FILE *fp,*fp1;char s[120]="\0";book a={"\0","\0","\0","\0","\0","\0",0.0,0};printf("请输入所要修改图书的中图分类号:");scanf("%s",str);if((fp=fopen("bookinf.txt","r+"))==NULL){printf("file open error!");exit(0);}if((fp1=fopen("f.txt","w"))==NULL){printf("file open error!");exit(0);}fgets(s,120,fp); //读取bookinf.txt第一行的信息,使读取位置移动到第二行fprintf(fp1,"中图分类好书名作者出版社出版时间状态价格数量");//初始化新文件f.txtwhile(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%lf%d",a.num,,a.author,a.press,a.time,a.status,&a.price, &a.count);if(!strcmp(str,a.num)) //如果遇到所要修改的记录,则从新输入图书信息{printf("请输入图书信息,即将记录修改为:\n");printf("中图分类好书名作者出版社出版时间状态价格数量\n");scanf("%s%s%s%s%s%s%lf%d",a.num,,a.author,a.press,a.time,a.status,&a.price,&a.c ount);}fprintf(fp1,"\n%-15s%-20s%-20s%-20s%-15s%-10s%-8.2lf%4d",a.num,,a.author,a.pr ess,a.time,a.status,a.price,a.count);}fclose(fp1);fclose(fp);remove("bookinf.txt");rename("f.txt","bookinf.txt");}void leave(){exit(0);}。
图书馆管理系统C语言_附完整源码

if (m == 5) { bnode* temp; head = NULL; sum = ReadSum(); head=ReadFile(sum); SelectSort(sum, head); //OutToFileArray(temp, sum); system("pause"); system("cls"); menu(); cin >> m; } if (m == 6) { bnode* temp; head = NULL; sum = ReadSum(); head=ReadFile(sum); BubbleSortName(sum, head); //OutToFileArray(temp, sum); system("pause"); system("cls"); menu(); cin >> m; } if (m == 7) { bnode* temp; head = NULL; sum = ReadSum(); head=ReadFile(sum); SelectSortWord(sum, head); //OutToFileArray(temp, sum); system("pause"); system("cls"); menu(); cin >> m; }
图书馆管理系统
#include< iostream > #include< string > #include< fstream > using namespace std; typedef struct node { char name[20]; char writter[30]; char publish[30]; int date; int word; double price; int number; struct node* next; }bnode; bnode* head = NULL; int sum = 1; void WriteSum(int mysum); int ReadSum(); void menu(); //对书库的操作 void InputInfo(); void SearchBook(bnode* myhead); void ChangeBook(bnode* myhead); int DeleteBook(bnode* myhead); //文件操作 void OutputToFile(); void OutToFileArray(bnode *temp, int mysum); bnode* ReadFile(int mysum); 在屏幕上 //排序 bnode* SelectSort(int mysum, bnode* myhead); bnode* SelectSortWord(int mysum, bnode* myhead); bnode* SelectSortDate(int mysum, bnode* myhead); bnode* BubbleSortName(int mysum, bnode* myhead);
图书管理系统源代码--纯C语言.

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<ctype.h>#define NULL 0#define LEN sizeof(Book)struct A{char Name[20];int all,left,borrow;struct A *next;};typedef struct A Book;int Display_Main_Menu(); /*主菜单显示*/Book *Create(); /*功能函数声明*/void Display(Book *head);Book *Insert(Book *head,Book *s);Book *Insert_a_record(Book *head);Book *Delete(Book *head,char *name);Book *Delete_a_record(Book *head);Book *Borrow(Book *head,char *name,int sum);Book *Borrow_a_Book(Book *head);Book *Return(Book *head,char *name,int sum);Book *Return_a_Book(Book *head);Book *Query(Book *head,char *name);void Query_a_record(Book *head);Book *AddfromText(Book *head,char *filename);Book *WritetoText(Book *head,char *filename);void Quit(Book *head);void main() /*主函数部分*/{Book *head; /*定义变量*/char filename[20];int keyword=111,a;printf("Please input keyword:");scanf("%d",&a);if(a!=keyword) exit(0);else printf("Welcome!");head=NULL; /*置首指针为空*/for(;;){switch(Display_MainMenu()){case 1:printf("1.Create BookList\n"); /*调用Create函数创建链表*/ head=Create();system("pause");break;case 2:printf("Display All Books\n");Display(head); /*调用Display函数显示所有*/system("pause");break;case 3:printf("Insert a Record\n");head=Insert_a_record(head);/*调用Insert_a_record函数插入*/system("pause");break;case 4:printf("Delete a Book\n");head=Delete_a_record(head);/*调用Delete_a_record函数删除*/ system("pause");break;case 5:printf("Borrow a Book\nInput BookName and sum you borrow:");head=Borrow_a_Book(head);system("pause");break;case 6:printf("Return a Book\nInput BookName and sum you return:");head=Return_a_Book(head);system("pause");break;case 7:printf("Query\nInput the BookName you want:");Query_a_record(head);/*调用查询函数*/system("pause");break;case 8:printf("Input the name of Text File\n");scanf("%s",filename);/*输入文件名*/head=AddfromText(head,filename);system("pause");break;case 9:printf("Input the name of the NewText File\n");scanf("%s",filename);/*输入要写入的文件名*/head=WritetoText(head,filename);system("pause");break;case 0:printf("Goodbye\n");Quit(head);exit(0);}}}int Display_MainMenu() /*显示菜单的函数*/{char x;do{system("cls");printf("************************\n");printf("1.Create BookList\n");printf("2.Display All Books\n");printf("3.Insert a BookInformation\n");printf("4.Delete a Book\n");printf("5.Borrow a Book\n");printf("6.Return a Book\n");printf("7.Query\n");printf("8.Add Records From a File\n");printf("9.Write to a File\n");printf("0.Goodbye\n");printf("************************\n");printf("Please choose from 0-9:");printf("\n");x=getchar();}while(x<'0'||x>'9');return(x-'0');}Book *Create() /*创建链表的函数,返回首指针*/{Book *head,*newrecord;char ch;printf("Input a Book\n");head=NULL;/*首指针置空*/do{newrecord=(Book *)malloc(LEN); /*动态分配存储空间*/scanf("%s%d",newrecord->Name,&newrecord->all);newrecord->left=newrecord->all;newrecord->borrow=0;head=Insert(head,newrecord); /*调用Insert函数判断位置插入*/getchar(); / *接收最后输入的回车符*/printf("Add another Book Y/N?\n");ch=getchar();getchar(); /*接收回车符*/ }while(ch!='n'&&ch!='N'); /*判断是否继续*/return(head);}Book *Insert(Book *head,Book *s)/*插入结点的函数*/{ Book *p0,*p1,*p2;p1=head;p0=s;if(head==NULL){head=p0;p0->next=NULL;}while(strcmp(p0->Name,p1->Name)>0&&(p1->next!=NULL)){p2=p p1=p1->next;}if(strcmp(p0->Name,p1->Name)<=0){p0->next=p1;if(head==p1) head=p0;else p2->next=p0;}else{p1->next=p0;p0->next=NULL;}return(head);}Book *Insert_a_record(Book *head){ Book *newrecord;newrecord=(Book *)malloc(LEN); /*动态分配存储空间*/scanf("%s%d",newrecord->Name,&newrecord->all);newrecord->borrow=0;newrecord->left=newrecord->all;head=Insert(head,newrecord);printf("Insert successfully\n");/*输出插入成功的信息*/return(head);}Book *Delete(Book *head,char *name) /*删除功能函数*/{ Book *p1,*p2;if(head==NULL)printf("Sorry No record!\n");p1=head;while(strcmp(p1->Name,name)!=0&&p1->next!=NULL) / {p2=p1;p1=p1->next;} if(strcmp(p1->Name,name)==0){if(p1==head)head=p1->next;else {p2->next=p1->next;printf("delete %s successfully\n",name);}}return(head);}Book *Delete_a_record(Book *head){ char name[20],ch;Book *p;scanf("%s",name);getchar();p=Query(head,name);if(p==NULL) printf("Cannot Find %s\n",name);else {printf("Delete %s, Y/N?\n",name);ch=getchar();system("pause");if(ch=='y'||ch=='Y')while(p!=NULL){head=Delete(head,name);p=Query(head,name);}}return(head);}Book *Borrow_a_Book(Book *head){ char name[20],ch;int n;Book *p;scanf("%s%d",name,&n);getchar(); /p=Query(head,name);if(p==NULL) printf("Cannot Find %s\n",name);else printf("Are you sure to borrow? %s, Y/N?\n",name);ch=getchar();system("pause");if(ch=='y'||ch=='Y')head=Borrow(head,name,n);return(head);}Book *Borrow(Book *head,char *name,int sum){ Book *p1;p1=head;while(strcmp(p1->Name,name)!=0&&p1->next!=NULL){p1=p1->next;}if(strcmp(p1->Name,name)==0)p1->borrow=sum;p1->left=p1->all-sum;return(head);}Book *Return_a_Book(Book *head){ char name[20],ch;int n;Book *p;scanf("%s%d",name,&n);getchar(); /*接收回车*/ p=Query(head,name);if(p==NULL) printf("Cannot Find %s\n",name); /*找不到结点*/ else printf("Are you sure to return? %s, Y/N?\n",name);ch=getchar();system("pause");if(ch=='y'||ch=='Y')head=Return(head,name,n);return(head);}Book *Return(Book *head,char *name,int sum){ Book *p1;p1=head;while(strcmp(p1->Name,name)!=0&&p1->next!=NULL) /*p1不是要找的结点,且后面还有结点*/{p1=p1->next;} /*p1后移一个结点*/if(strcmp(p1->Name,name)==0) /*找到了*/p1->borrow=p1->borrow-sum;p1->left=p1->left+sum;return(head);}void Display(Book *head){ Book *p;int i;p=head;printf("Num BookName Total Left Borrow\n");for(i=1;p!=NULL;i++){printf("%-5d%-14s%-10d%-10d%-5d\n",i,p->Name,p->all,p->left,p->borrow);p=p->next;if(i%10==0){system("pause"); /*按回车继续显示*/printf("Num BookName total left borrow\n");}}}Book *Query(Book *head,char *name){ Book *p;p=head;while(strcmp(name,p->Name)!=0&&p->next!=NULL)p=p->next;if(strcmp(name,p->Name)==0) /*找到了,返回结点地址*/return(p);else /*找不到返回空指针*/return(NULL);}void Query_a_record(Book *head){ char name[20];Book *p;scanf("%s",name);p=Query(head,name);if(p!=NULL) /*找到了*/{ printf("Find successfully\n%s total:%d left:%d borrow:%d\n",p->Name,p->all,p->left,p->borrow);}elseprintf("Can't find the records of %s\n",name); /*找不到*/}Book *AddfromText(Book *head,char *filename){ FILE *fp;int n,i;if((fp=fopen(filename,"r"))==NULL){printf("Cannot find file:%s\n",filename); /*打不开所指定文件*/return(head);}fscanf(fp,"%d",&n); /*待插入记录个数*/for(i=0;i<n;i++){Book *p;p=(Book *)malloc(LEN);fgetc(fp); /*读取换行符*/fscanf(fp,"%s%d%d%d",p->Name,&p->all,&p->left,&p->borrow);head=Insert(head,p); /*插入结点*/}printf("Add from %s successfully\n",filename);fclose(fp);return(head);}Book *WritetoText(Book *head,char *filename){FILE *fp;Book *p;if(head==NULL){printf("No Record!\n");return(head);}fp=fopen(filename,"w"); /*打开文件*/p=head;while(p!=NULL){ fprintf(fp,"%-14s%-10d%-10d%-10d\n\n",p->Name,p->all,p->left,p->borrow); /*文件输出*/p=p->next;}printf("Write to %s successfully\n",filename); /*输出写到文件完毕的信息*/ fclose(fp);return(head);}void Quit(Book *head){Book *p,*p1,*p2;FILE *fp;char filename[]="last";p2=p1=head;if(head!=NULL){fp=fopen(filename,"w"); /*打开文件*/p=head;while(p!=NULL){ fprintf(fp,"%s %d %d %d\n",p->Name,p->all,p->left,p->borrow); /*文件输出*/p=p->next;}printf("Write to %s successfully\n",filename); /*输出写到文件完毕的信息*/ fclose(fp);}while(p1!=NULL) /*p1指向的结点不是空指针*/{p2=p1->next;free(p1); /*释放存储空间*/p1=p2; /*p1后移一个结点*/}}。
C语言 图书信息管理系统 最终源代码

C语言图书信息管理系统最终源代码#include<stdio.h>#include"string.h"struct book /* book2 是用来装用户要录入图书的信息*/{long num,time;char name[12],writer[12],fenlei[8],danwei[10];int pay;}stu[100];struct book1{long num,time;char name[12],writer[12],fenlei[8],danwei[10];int pay;}stu1[100];struct book2 /* book 是用来装cc.dat 文件中的图书信息*/{long num,time;char name[12],writer[12],fenlei[8],danwei[10];int pay;}stu2[100];denglu(){char a[15]="drzhang",b[15]="29257966",c[15],d[15];L3:system("cls");printf(" 欢迎登陆图书管理系统\n\n");printf("请输入姓名:");gets(c);printf("请输入密码:");gets(d);if(strcmp(a,c)==0&&strcmp(b,d)==0)return 0;else{printf("输入错误请重新输入\n\n");printf("1.重新输入 2.退出系统\n\n");printf("请输入.....");switch(getch()){case 49: goto L3;break;default: return 56;break;}}}/*此功能实现的是开始菜单的显示和具体功能的选择*/start(){printf("******************************欢迎使用图书管理系统******************************");printf("* 功能目录:*");printf("* |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| *");printf("* || || *");`printf("* || 1、图书查询2、图书浏览3、录入图书4、删除与修改5、备份与还原|| *");printf("* || || *");printf("* || || *");printf("* || || *");printf("* |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| *");printf("* 使用说明:如要选择“图书查询”,直接输入:1 退出:0 *");printf("************************************************************************* *******");printf("你想要做什么:");return getch(); /*输入选择对应功能的值,返回输入的值,即:用于判断选择的功能*/ }/*实现备份功能,以防图书信息出错带来的麻烦,不必看懂*/beifen(){FILE *fp1,*fp2;int i,a;jieshuo();system("cls");printf("\n\n请选择\\ 备份(B)| 浏览备份(L)/ \\ 还原(H)/ \\ 退出(Q)/ \n");switch(getch()){case 'B':case 'b':if((fp1=fopen("cc","r"))==NULL){printf("不能打开次文件\n");exit(0);}if((fp2=fopen("cc01","w"))==NULL){printf("不能打开次文件\n");exit(0);}fscanf(fp1,"%d",&a);fprintf(fp2,"%d\n",a);printf("\n\n确认备份吗?(Y/N)");switch(getch()){case 'Y':case 'y':for(i=0;i<a;i++){fscanf(fp1,"%ld %s %s %s %s %ld %d",&stu[i].num,stu[i].name,stu[i].writer,stu[i].fenlei,stu[i] .danwei,&stu[i].time,&stu[i].pay);fprintf(fp2,"%ld\t%s\t%s\t%s\t%s\t%ld\t%d\n",stu[i].num,stu[i].name,stu[i].writer,stu[i].fenlei,st u[i].danwei,stu[i].time,stu[i].pay);}printf("\n\n备份成功!\n\n是否打开浏览备份文件?(Y/N)");switch(getch()){case 'Y':case 'y':fclose(fp1);fclose(fp2);liulan02();break;case 'N':case 'n':break;}break;case 'N':case 'n':break;}fclose(fp1);fclose(fp2);break;case 'H':case 'h':if((fp1=fopen("cc01","r"))==NULL){printf("不能打开此文件\n");exit(0);}if((fp2=fopen("cc","w"))==NULL){printf("不能打开此文件\n");exit(0);}fscanf(fp1,"%d",&a);fprintf(fp2,"%d\n",a);printf("\n\n确认还原吗?(Y/N)");switch(getch()){case 'Y':case 'y':for(i=0;i<a;i++){fscanf(fp1,"%ld %s %s %s %s %ld %d",&stu[i].num,stu[i].name,stu[i].writer,stu[i].fenlei,stu[i] .danwei,&stu[i].time,&stu[i].pay);fprintf(fp2,"%ld\t%s\t%s\t%s\t%s\t%ld\t%d\n",stu[i].num,stu[i].name,stu[i].writer,stu[i].fenlei,st u[i].danwei,stu[i].time,stu[i].pay);}printf("\n\n还原成功!\n\n是否打开浏览还原文件?(Y/N)");switch(getch()){case 'Y':case 'y':fclose(fp1);fclose(fp2);liulan();break;case 'N':case 'n':break;}break;case 'N':case 'n':break;}fclose(fp1);fclose(fp2);break;case 'l':case 'L':liulan02();break;case 'Q':case 'q':break;}}/* 在屏幕上打印查询菜单*/chaxun(){jieshuo();system("cls");printf("******************************欢迎使用图书查询系统******************************");printf("* 查询方式:*");printf("**");printf("* 1、书名2、作者名3、出版时间*");printf("**");printf("* 4、价格5、分类号6、出版单位*");printf("**");printf("* 使用说明:如要选择“书名”,直接输入:1 退出:0 *");printf("************************************************************************* *******");printf("\n请输入你要怎么查询:");chaxun01(); /*打印完毕后,进入chaxun()函数,执行用户需要的查询功能*/}/*此程序段实行查询的各种功能*/chaxun01(){FILE *fp;char ch[8];int a=0,i,j,k,n=0,c,d;long b;if((fp=fopen("cc","r"))==NULL) /*说明:cc.dat 文件装着图书的信息,*/ {printf("不能打开此文件\n");exit(0);} /*并且文件开记录的是图书的书量,后*/ fscanf(fp,"%d",&a); /*从文件中读出图书数*/ /*面依次才是具体信息。
C语言图书管理系统源代码

#include<stdio。
h〉#include<stdlib。
h〉#include<string.h〉struct tushu{/*图书结构体*/ char num[10];/*编号*/char name[20];/*书名*/char writer[20];/*作者*/char press[20];/*出版社*/char kind[20];/*类别*/double time;/*时间*/double price;/*价格*/struct tushu *next;};struct stu /*学生结构体*/ {int snum;/*学号*/char mima[10]; /*密码*/struct stu *next;};FILE *fp; /*图书文件*/FILE *fp1;/*管理员信息文件*/ FILE *fp2; /*学生信息文件*/void menu(); /*管理员主菜单(管理员进入对图书及学生信息进行管理操作)*/void xmenu();/*学生主菜单(学生进入可对图书,密码进行操作)*/void gfind(); /*管理员查询(管理员可按一定的方式查询图书)*/void xfind(); /*学生查询(学生可按一定的方式查询图书)*/void secret();/*管理员权限(管理员登陆所用,输入错误次数过多自动退出)*/void sort(); /*排序(管理员可按一定的方式对图书进行排序,排序完之后可选择文件进行保存)*/void fprint(struct tushu *head);/*保存(可追加的保存,如添加可用)*/void fprint_(struct tushu *head);/*保存(可覆盖保存如修改,删除,排序后用)*/void hfprint(struct tushu *head); /*还书保存(还书成功后自动保存到文件)*/void jfprint_(struct tushu *head); /*借书保存(借书成功之后自动从图书馆删除)*/struct tushu * Input();/*图书添加(可进行图书的添加)*/struct tushu *create(); /*从文件创建链表(从文件中读出信息,建立单链表)*/void gBrowse(struct tushu *head);/*管理员浏览(对图书进行遍历)*/void xBrowse(struct tushu *head);/*学生浏览(学生对图书进行遍历)*/void count(struct tushu *head);/*统计数量(管理员可对图书进行统计)*/void Findofname(struct tushu *head); /*按书名查找*/ void Findofwriter(struct tushu *head);/*按作者查找*/ void Findofkind(struct tushu *head);/*按类别查找*/ void xFindofname(struct tushu *head); /*学生按书名查找*/void xFindofwriter(struct tushu *head);/*学生按作者查找*/ void xFindofkind(struct tushu *head); /*学生按类别查找*/ void Sort_time(struct tushu * head);/*按时间排序(管理员按时间对图书进行排序,排序完之后可选择文件进行保存)*/ void Sort_price(struct tushu *head); /*按价格排序*/void Sort_num(struct tushu * head);/*按编号排序*/ void Delete(struct tushu * head,char m[15]);/*按编号删除(管理员可按编号删除图书)*/void Revise(struct tushu *head); /*修改(管理员可对图书进行修改,并选择是否保存)*/void borrow(struct tushu *head);/*借书*/void huanshu(); /*还书(学生借完书之后进行还书,若没有图书则不能借)*/void gxinxi(); /*管理员信息(有管理员的账号及密码,可进行修改)*/void xmima(struct stu *head1);/*学生密码修改(学生可对自己的密码进行修改)*/struct stu *xcreate();/*从文件创建学生信息(从文件读出学生信息,建立学生链表)*/void xsecret(struct stu *head1); /*学生权限(学生登陆所用)*/void menu()/*管理员主菜单(管理员进入对图书及学生信息进行管理操作)*/{int choice,n=0;struct tushu *head;struct stu *head1,*p;char m[15];there:printf(”┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n”);printf(” ┃┃socat 图书管理系统┃┃\n”);printf(" ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n”);printf(” ┃●[0]退出系统┃\n");printf(" ┃┃\n");printf(” ┃●[1]帮助┃\n");printf(” ┃┃\n”);printf(" ┃●[2]浏览图书┃\n");printf(” ┃┃\n”);printf(" ┃●[3]统计图书数目┃\n”);printf(” ┃┃\n”);printf(” ┃●[4]查询printf(" ┃┃\n");printf(" ┃●[5]添加┃\n");printf(" ┃┃\n");printf(" ┃●[6]排序┃\n”);printf(” ┃┃\n”);printf(” ┃●[7]修改┃\n”);printf(” ┃┃\n”);printf(” ┃●[8]删除┃\n");printf(" ┃┃\n”);printf(" ┃●[9]修改账号及密码┃\n");print f(” ┃printf(" ┃●[10]学生信息┃\n");printf(" ┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”);printf(” 请选择:");fflush(stdin);head=create();scanf(”%d",&choice);if(choice==1){//help();printf(”没有内容!\n");system(”pause");system("cls”);menu();}else if(choice==2){system("cls");if(head==NULL){printf(”没有图书,请先添加图书!\n");system("pause");system("cls”);menu();}gBrowse(head);}else if(choice==3){system(”cls");count(head);}else if(choice==4){system("cls");if(head==NULL){printf(”没有图书,请先添加图书!\n”);system("pause”);system(”cls”);menu();}gfind();}else if(choice==5){Input();}else if(choice==6){system(”cls”);if(head==NULL){printf(”没有图书,请先添加图书!\n”);system(”pause”);system(”cls”);menu();}sort(head);}else if(choice==7){system(”cls");if(head==NULL){printf("没有图书,请先添加图书!\n");system(”pause”);system("cls");menu();}Revise(head) ;}else if(choice==8){if(head==NULL){printf("没有图书,请先添加图书!\n");system(”pause”);system("cls”);menu();}printf(” 请输入想要删除的图书编号:");scanf(”%s",m);Delete(head,m);}else if(choice==9)gxinxi();}else if(choice==10){system("cls”);head1=xcreate();if(head1==NULL){printf("没有学生信息,请到xuesheng_list。
C语言图书管理系统代码

C语言图书管理系统代码 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 大型实验之图书管理系统源代码(仅供参考)

//===================================
void DBFile::Write_borrowdata_infile(){
ofstream outfile("BorrowData.dat",ios::trunc);
//覆盖写入模式,因为中间有修改变量
infile>>(m->ID);
if((m->ID)[0]=='\0')break;
infile>>(m->Password);
infile>>(m->Name);
infile>>(m->Sex);
if(managers==0)
managers=m;
string bname;//书名
string author;//作者
string press;//出版社
int storenum;//现有藏书量
int borrownum;//借出数
Book *next;
Book();
void print();
};
#endif
//DBFile.h//数据操作类
//====================
#ifndef HEADER_DBFILE
#define HEADER_DBFILE
#include <iostream>
#include <fstream>
#include <string>
#include "Reader.h"
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
/*查询次循环*/ while((ch=='y')||(ch=='Y')) { printf(" printf(" printf(" printf("请选择?\n"); scanf("%d",&a); printf("请输入关键词;\n"); scanf("%s",duqu);
*********************\n"); #1_按书名***2_按作者#\n"); *********************\n");
};break; default:;break; } printf("是否继续查询: scanf("%c",&ch); scanf("%c",&ch); rewind(fp); } fclose(fp); } int bijiao(char a[],char b[]) { char cha[2],chb[2]; cha[0]=chb[0]='l'; cha[1]=chb[1]='\0'; int i=0,n=0,k=0; cha[0]=a[0]; chb[0]=b[0]; while((cha[0]!='\0')&&(chb[0]!='\0')) { if((strcmp(cha,chb))==0) { i=i+1; k=k+1; } else { n=n+1; } cha[0]=a[i],chb[0]=b[i+n]; } i=0; while(a[i]!='\0') i=i+1; if(i==k) return 1; else return 0; } void xiushan() { y or n");
/*执行主循环*/ while((ch=='y')||(ch=='Y')) { printf(" printf(" printf(" printf(" printf("
===============================\n"); *1_信息录入====*====2_信息浏览*\n"); *==============*==============*\n"); *3_信息查询====*====4_信息修删*\n"); ===============================\n");
fclose(fp); } void liulan() { Books lurua; char fileName[31],*name=fileName; FILE *fp; printf("请输入图书库文件及路径\n"); scanf("%s",name); fp=fopen(name,"r"); if(fp!=NULL) { printf("书名\t\t\t\t 作者\t\t 编号\t\t 出版单位\t\t\t\t 出版时间\t\t 价格\t 总数 量\t 可借出数量\n"); while(!feof(fp)) {
fscanf(fp,"%s%s%s%s%d%f%d%d\n",lurua.bookName,lurua.auther,lurua.bookNumber,lurua.publi sher,&lurua.publitionTime,&lurua.price,&lurua.allNumber,&lurua.availableNumber); printf("%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",lurua.bookName,lurua.auther,lurua.book Number,lurua.publisher,lurua.publitionTime,lurua.price,lurua.allNumber,lurua.availableNumber); } } else { printf("错误,请重新选择\n"); } fclose(fp); } void chaxunz() { char filename[31]; printf("请输入图书库文件名及路径(小于 30 个字符)\n"); scanf("%s",filename); FILE *fp; fp=fopen(filename,"r"); Books book1; char ch='y'; int a; char duqu[21],wenjian[21];
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"); else 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.b ookNumber,lurua.publisher,lurua.publitionTime,lurua.price,lurua.allNumber,lurua.availableNumb er); b=b+1; }
printf("书名\t\t\t\t 作者\t\t 编号\t\t 出版单位\t\t\t\t 出版时间\t\t 价格\t 总数量\t 可借出数量\n"); switch(a) { case 1: { while(!feof(fp)) { fscanf(fp,"%s%s%s%s%d%f%d%d\n",book1.bookName,book1.auther,book1.bookNumber,book1. publisher,&book1.publitionTime,&book1.price,&book1.allNumber,&book1.availableNumber); strcpy(wenjian,book1.bookName); if((bijiao(duqu,wenjian))==1) printf("%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",book1.bookName,book1.auther,book1.b ookNumber,book1.publisher,book1.publitionTime,book1.price,book1.allNumber,book1.available Number); } };break; case 2: { while(!feof(fp)) { fscanf(fp,"%s%s%s%s%d%f%d%d\n",book1.bookName,book1.auther,book1.bookNumber,book1. publisher,&book1.publitionTime,&book1.price,&book1.allNumber,&book1.availableNumber); strcpy(wenjian,book1.auther); if((bijiao(duqu,wenjian))==1) printf("%-32s%-16s%-16s%-32s%d\t\t%.2f\t%d\t%d\n",book1.bookName,book1.auther,book1.b ookNumber,book1.publisher,book1.publitionTime,book1.price,book1.allNumber,book1.available Number); }