图书管理系统的C 代码 完整版

合集下载

图书管理系统的C代码完整版精编版

图书管理系统的C代码完整版精编版

图书管理系统的C代码完整版GE GROUP system office room 【GEIHUA16H-GEIHUA GEIHUA8Q8-C#代码清单共1个项目,包含5个类。

项目: librarysystem类: Program.cs Readers.cs Manage.cs Menu.cs Publications.cs 主类代码:namespace librarysystem{ ///<summary>///类名:Program///功能:项目主类///时间:2015-11-19///</summary>class Program{static void Main(string[] args){Menu meu = new Menu(); meu.ShowMainMenu();Console.ReadLine();}}}出版物类代码:namespace librarysystem{ ///<summary>///类名:Publications///功能:馆藏出版物信息///时间:2015-11-19///</summary>class Publications{/*出版物编号*/private string PublicationISBN;public string PublicationIsbn{get{return PublicationISBN; }set{PublicationISBN = value; }}/*出版物名称*/public string PublicationName;/*出版物作者或出版机构*/public string PublicationAuthor;/*出版物在架状态*/public bool PublicationStatus;/*出版物类型*/public string PublicationType;public Publications(){}public Publications(string PublicationISBN,string PublicationName,string PublicationAuthor,string PublicationType,bool PublicationStatus){this. PublicationISBN = PublicationISBN;this.PublicationName = PublicationName;this.PublicationAuthor = PublicationAuthor;this.PublicationType = PublicationType;this.PublicationStatus = PublicationStatus;}}}读者类代码:namespace librarysystem{ ///<summary>///类名:Readers///功能:已获取权限读者的信息///时间:2015-11-19///</summary>class Readers{private string ReaderID;public string ReaderId{get{return ReaderID;}set{ReaderID = value;}}public string ReaderName;public string ReaderSex;public string ReaderDepartment;public string ReaderMajor;public string[] BowPublication = new string[10]{"","","","","","","","","",""};public Readers(){}public Readers(string ReaderID, string ReaderName, string ReaderSex, string ReaderDepartment, string ReaderMajor){this.ReaderID = ReaderID;this.ReaderName = ReaderName;this.ReaderSex = ReaderSex;this.ReaderDepartment = ReaderDepartment;this.ReaderMajor = ReaderMajor;}}}管理类代码:namespace librarysystem{ ///<summary>///类名:Manage///功能:管理员执行图书管理操作///时间:2015-11-19///</summary>class Manage{public bool BorrowFlag = false;/*借阅操作成功标志*/public bool ReturnFlag = false;/*归还操作成功标志*/public Publications pub_search;/*保存查询到的出版物*/public Readers Red_valid;/*保存查询到的合法用户*//*声明馆藏出版物数组*/public Publications[] pubs=new Publications[200];/*声明注册读者数组*/public Readers[] reds=new Readers[30];/*实例化馆藏出版物对象*/public Publications pub0 = new Publications("000000","C#从入门到精通","明日科技","书籍",true);public Publications pub1 = new Publications("000001", "数值分析", "李清朗", "书籍", true);public Publications pub2 = new Publications("000002", "模式识别", "张学工", "书籍", true);public Publications pub3 = new Publications("000003", "中国国家地理", "地理科学院", "杂志", true);public Publications pub4 = new Publications("000004", "意林", "长春市文学艺术界联合会 ", "杂志", true);public Publications pub5 = new Publications("000005", "四川大学报", "四川大学", "报纸", true);public Publications pub6 = new Publications("000006", "经济学人", "伦敦经济学人报纸有限公司", "杂志", true);public Publications pub7 = new Publications("000007", "计算机网络", "谢希仁", "书籍", true);public Publications pub8 = new Publications("000008", "红楼梦", "曹雪芹", "书籍", true);public Publications pub9 = new Publications("000009", "新东方雅思培训课程", "俞敏洪", "音像制品", true);public Publications pub10 = new Publications("000010", "MATLAB实用教程", "张世杰", "音像制品", true);/*实例化已注册读者对象*/public Readers red0 = new Readers(, "李华", "男", "电子信息学院", "电子与通信工程");public Readers red1 = new Readers(, "王鹏", "男", "物理学院", "微电子学");public Readers red2 = new Readers(, "张建豪", "男", "数学学院", "现代数学分析");public Readers red3 = new Readers(, "陈莉", "女", "化学化工学院", "化学分析");public Readers red4 = new Readers(, "吴娜", "女", "医学院", "口腔医学");public Readers red5 = new Readers(, "宋雅茹", "女", "电子信息学院", "光学工程");/*初始化出版物数组*/public void PublicationsInitial(){pubs[0] = pub0;pubs[1] = pub1;pubs[2] = pub2;pubs[3] = pub3;pubs[4] = pub4;pubs[5] = pub5;pubs[6] = pub6;pubs[7] = pub7;pubs[8] = pub8;pubs[9] = pub9;pubs[10] = pub10;}/*初始化读者数组*/public void ReadersInitial() {reds[0] = red0;reds[1] = red1;reds[2] = red2;reds[3] = red3;reds[4] = red4;reds[5] = red5;}/*查询图书操作*/public bool SearchPublications(){string Pub_Name;bool SearchFlag = false;Pub_Name = Console.ReadLine();foreach (Publications pub in pubs){if (pub != null && pub.PublicationName == Pub_Name) {SearchFlag = true;pub_search = pub;}}return SearchFlag;}/*借阅图书操作*/public void Borrow(){string Red_Name;string Pub_Name;bool ReaderFlag = false;Red_Name = Console.ReadLine();foreach (Readers red in reds){if (red != null && red.ReaderName == Red_Name){ReaderFlag = true;Red_valid = red;}}if (ReaderFlag){Console.Write("请输入您需要借阅出版物的名称:");Pub_Name = Console.ReadLine();foreach (Publications pub in pubs){if (pub != null && pub.PublicationName == Pub_Name) {BorrowFlag = true;pub.PublicationStatus = false;AddToReders(pub.PublicationName, Red_valid);}}}else{Console.WriteLine("抱歉,您是非法读者,不能借阅图书"); }}/*归还图书操作*/public void Return(){string Red_Name;string Pub_Name;bool ReaderFlag = false;Red_Name = Console.ReadLine();foreach (Readers red in reds){if (red != null && red.ReaderName == Red_Name){ReaderFlag = true;Red_valid = red;}}if (ReaderFlag){Console.Write("请输入您需要归还出版物的名称:");Pub_Name = Console.ReadLine();foreach (Publications pub in pubs){if (pub != null && pub.PublicationName == Pub_Name) {for (int i = 0; i < 10;i++ ){if (Red_valid.BowPublication[i] == Pub_Name) {ReturnFlag = true;pub.PublicationStatus = true;RemoveFromReders(Pub_Name, Red_valid); }}}}}else{Console.WriteLine("抱歉,您是非法读者,无归还图书信息"); }}/*添加图书到读者*/private void AddToReders(string PublicationName, Readers red) {/*设置借阅上限为10本*/for (int i = 0; i < 10; i++){if (red != null && red.BowPublication[i]==""){red.BowPublication[i] = PublicationName;break;}}}/*从读者对象中移除图书*/private void RemoveFromReders(string PublicationName, Readers red){/*设置借阅上限为10本*/for (int i = 0; i < 10; i++){if (red != null && red.BowPublication[i] == PublicationName){red.BowPublication[i] = red.BowPublication[i+1]; }}}/*新书入库操作*/public void AddPublications(Publications pub){for (int i = 11; i < 200; i++){if(pubs[i]==null){pubs[i] = pub;}}}/*添加新读者操作*/public void AddReaders(Readers red) {for (int i = 6; i < 30; i++){if (reds[i] == null){reds[i] = red;}}}/*查询读者信息*/public void RedIndex(){string Red_Name;bool ReaderFlag = false;Red_Name = Console.ReadLine();foreach (Readers red in reds){if (red != null && red.ReaderName == Red_Name) {ReaderFlag = true;Red_valid = red;}}if (!ReaderFlag){Console.WriteLine("抱歉,您是非法读者,无法查到您的借阅信息");}}}}菜单类代码:namespace librarysystem{ ///<summary>///类名:Menu///功能:显示服务页面///时间:2015-11-19///</summary>class Menu{//创建一个具体的管理对象Manage mag = new Manage();//声明一个读者对象Readers red;//声明一个出版物对象Publications pub;public void ShowMainMenu(){mag.PublicationsInitial();mag.ReadersInitial();Console.WriteLine("欢迎使用图书管理系统V1.0");Console.WriteLine("-------------------------------------------------------------------");Console.WriteLine("1.查询图书");Console.WriteLine("2.借书服务");Console.WriteLine("3.还书服务");Console.WriteLine("4.新出版物入库");Console.WriteLine("5.录入新读者");Console.WriteLine("6.查询读者的借阅信息");Console.WriteLine("7.退出管理系统");Console.WriteLine("-------------------------------------------------------------------");bool flag;do{flag = false;Console.WriteLine("请选择:");string key = Console.ReadLine();switch (key){case"1":Console.Write("请输入需要查询图书的书名:");ShowPubInfo();break;case"2":Console.Write("请输入您的姓名:");mag.Borrow();ShowBorrowInfo();break;case"3":Console.Write("请输入您的姓名:");mag.Return();ShowReturnInfo();break;case"4":Console.WriteLine("请按照提示逐步输入需要入库出版物的信息……");ShowAddPublications();break;case"5":Console.WriteLine("请按照提示逐步输入新注册读者的信息……");ShowAddReaders();break;case"6":Console.Write("请输入您的姓名: ");mag.RedIndex();ShowRedPubInfo(mag.Red_valid);break;case"7":flag = false;break;default:Console.WriteLine("无此业务,是否重新选择(y/n)");string answer = Console.ReadLine();if (answer != "y"){flag = false;}else{flag = true;}break;}} while (flag);}/*显示查询到的出版物信息*/public void ShowPubInfo(){if (mag.SearchPublications()){Console.WriteLine("您要查询的出版物信息:");Console.WriteLine("-------------------------------------------------------------------");Console.WriteLine("编号: " +mag.pub_search.PublicationIsbn);Console.WriteLine("出版物名字: " +mag.pub_search.PublicationName);Console.WriteLine("出版物作者: " +mag.pub_search.PublicationAuthor);Console.WriteLine("出版物类型: " +mag.pub_search.PublicationType);if (mag.pub_search.PublicationStatus){Console.WriteLine("出版物状态:在架,可借");}else{Console.WriteLine("出版物状态:未在架,不可借");}Console.WriteLine("-------------------------------------------------------------------");Console.WriteLine("");Console.WriteLine("");Console.WriteLine("是否办理其他业务(y/n)");string answer = Console.ReadLine();if (answer == "y"){ShowMainMenu();Console.WriteLine();}else{Console.WriteLine("结束");}}else{Console.WriteLine("抱歉,未找到该图书!");Console.WriteLine("是否办理其他业务(y/n) ");string answer = Console.ReadLine();if (answer == "y"){ShowMainMenu();Console.WriteLine();Console.WriteLine();}else{Console.WriteLine("结束");}}}/*显示借阅操作结果*/public void ShowBorrowInfo(){if (mag.BorrowFlag){Console.WriteLine("恭喜,借阅成功!"); ShowRedPubInfo(mag.Red_valid);}else{Console.WriteLine("抱歉,借阅失败!");Console.WriteLine("是否办理其他业务(y/n) ");string answer = Console.ReadLine();if (answer == "y"){ShowMainMenu();}else{Console.WriteLine("结束");}}}/*显示归还操作结果*/public void ShowReturnInfo(){if (mag.ReturnFlag){Console.WriteLine("恭喜,归还成功!");ShowRedPubInfo(mag.Red_valid);}else{Console.WriteLine("抱歉,归还失败!");Console.WriteLine("是否办理其他业务(y/n) ");string answer = Console.ReadLine();if (answer == "y"){ShowMainMenu();}else{Console.WriteLine("结束");}}}public void ShowRedPubInfo(Readers red){Console.WriteLine("当前你的借阅信息如下:");Console.WriteLine("--------------------------------------------------------------------");Console.WriteLine("编号: " + red.ReaderId);Console.WriteLine("姓名: " + red.ReaderName);Console.WriteLine("性别: " + red.ReaderSex);Console.WriteLine("所在院系: " + red.ReaderDepartment);Console.WriteLine("主修专业: " + red.ReaderMajor);Console.Write("已借图书: ");for (int{if (red.BowPublication[i] != ""){Console.Write(" "+red.BowPublication[i]);}}Console.WriteLine("");Console.WriteLine("--------------------------------------------------------------------");Console.WriteLine("");Console.WriteLine("是否办理其他业务(y/n)");string answer = Console.ReadLine();if (answer == "y"){ShowMainMenu();}else{Console.WriteLine("结束");}}/*显示新出版物入库的信息*/public void ShowAddPublications(){pub = new Publications();Console.Write("请输入出版物的编号: "); pub.PublicationIsbn=Console.ReadLine();Console.Write("请输入出版物的名称: ");pub.PublicationName = Console.ReadLine();Console.Write("请输入出版物的编者: ");pub.PublicationAuthor = Console.ReadLine();Console.Write("请输入出版物的类型: ");pub.PublicationType = Console.ReadLine(); pub.PublicationStatus = true;mag.AddPublications(pub);Console.WriteLine("新出版物入库成功!");Console.WriteLine("是否办理其他业务(y/n) ");string answer = Console.ReadLine();if (answer == "y"){ShowMainMenu();Console.WriteLine();Console.WriteLine();}else{Console.WriteLine("结束");}}/*显示新读者注册的信息*/public void ShowAddReaders(){red = new Readers();Console.Write("请输入新注册读者的编号: "); red.ReaderId = Console.ReadLine();Console.Write("请输入新注册读者的姓名: "); red.ReaderName= Console.ReadLine();Console.Write("请输入新注册读者的性别: ");red.ReaderSex = Console.ReadLine();Console.Write("请输入新注册读者的院系: "); red.ReaderDepartment = Console.ReadLine();Console.Write("请输入新注册读者的专业: "); red.ReaderMajor = Console.ReadLine();for(int i=0;i<10;i++){red.BowPublication[i]="";}mag.AddReaders(red);Console.WriteLine("新读者注册成功!");Console.WriteLine("是否办理其他业务(y/n) ");string answer = Console.ReadLine();if (answer == "y"){ShowMainMenu();Console.WriteLine();Console.WriteLine();}else{Console.WriteLine("结束"); }}}}。

C#图书管理系统程序代码

C#图书管理系统程序代码

/* Note:Your choice is C IDE */#include<graphics.h>#include "conio.h"#include<stdlib.h>#include<string.h>void main(){void adm1(),adm2(),build(),huan(),borrow(),dele();adm1();}void adm1(){ FILE *fp,*p ;char adp[20],password[20];int i,n=0;textbackground(2);clrscr();gotoxy(25,12);fp=fopen("pass","r");if(fp==NULL){printf("no exit ");getch()();exit(0);}printf("input password:");for(;;){window(42,12,53,12);textbackground(0);clrscr();gets(adp);for(i=0;adp[i]!='\0';i++);fgets(password,i+1,fp);gotoxy(55,12);if(strcmp(password,adp)==0){window(55,12,70,12);clrscr();cprintf("YES");getch()();adm2();getch()();exit(0);}else{ n++;window(55,12,60,12);clrscr();gotoxy(55,12);cprintf("error");for(i=0;i<30;i++) delay(8000);if(n==2){window(55,12,70,12);clrscr();gotoxy(55,12);cprintf("once again");for(i=0;i<=30;i++)delay(8000);}if(n==3){window(55,12,70,12);clrscr();gotoxy(55,12);cprintf("3 second out");for(i=0;i<=30;i++){delay(8000);}exit(0);}}fclose(fp);clrscr();}}void adm2(){char a;window(1,1,80,25);clrscr();for(;;){clrscr();gotoxy(30,8);printf("built a new user (B)");gotoxy(30,10);printf("return book (R)");gotoxy(30,12);printf("borrow books (J)");gotoxy(30,14);printf("delete user (D)");a=getch();if(a=='b') build();if(a=='r') huan();if(a=='j') borrow();if(a=='d') dele();else continue;}}void build(){FILE *f,*p;char id[20],name[20],sex[2],age[3],grad[50];window(1,1,80,25);clrscr();printf("ID number:");scanf("%s",id);printf("name:");scanf("%s",name);printf("sex:");scanf("%s",sex);printf("grad:");scanf("%s",grad);p=fopen(id,"w+");if(p==NULL){printf("can't build that user");getch();adm2();}fprintf(p,"%s ",name);fprintf(p,"%s ",id);fprintf(p,"%s ",sex);fprintf(p,"%s ",grad);printf("bulid success");getch();fclose(p);}void huan(){FILE *fp,*p,*f;char id[20],a[5][50],name[20],c;int i=0,m,k; clrscr();printf("input ID number:");scanf("%s",id);p=fopen(id,"r");if(p==NULL) { printf("error");getch();fclose(p);exit(0);}fscanf(p,"%s",name);fclose(p);fp=fopen(name,"r");do{ fscanf(fp,"%s",a[i++]); }while(!feof(fp));for(k=0;k<i-1;k++) printf("\nbook %d: %s",k+1,a[k]);fclose(fp);f=fopen(name,"w+");for(;;){printf("\n\npress the book number that you want to return. \n\nPress 6 if you want to return all. \n\npress 7 to cancle.\n");scanf("%d",&m);if(m==7) { for(k=0;k<i-1;k++){fprintf(f,"%s\n",a[k]);}fclose(f);adm2();}if(m==6) remove(name);if(m<6)for(k=0;k<i-1;k++){ if(k!=m-1)fprintf(f,"%s\n",a[k]);}printf("book %d has returned.",m);printf("\ncontinue? (Y/N)");c=getch();if(c=='y')continue;if(c=='n') { fclose(f);adm2(); }}}void borrow(){ FILE *f,*m,*p;char id[20],book[5][50],name[20],c;int i=0,n=0,k;window(1,1,80,25);clrscr();printf("please input the user's ID:");scanf("%s",id);m=fopen(id,"r");if(m==NULL) { printf("user no exit");getch();fclose(m);adm2();}fscanf(m,"%s",name);fclose(m);p=fopen(name,"r");if(p==NULL);else{while(!feof(p)){fscanf(p,"%s",book[i]);i++;}i--;for(k=0;k<i;k++)printf("\nbook %d :%s",k+1,book[k]);}fclose(p);f=fopen(name,"w");printf("\nhow many book do you want to borrow?:"); do{printf("\ninput:");scanf("%d",&n);}while(i+n>=6);for(k=i;k<i+n;k++){printf("\nbook %d :",k+1);scanf("%s",book[k]);}for(k=0;k<i+n;k++) fprintf(f,"%s\n",book[k]);fputc('\0',f);printf("success");fclose(f);}void dele(){FILE *fp,*f;char id[20],a[4][20],c,b[5][50];int i=0,j=0,k;window(1,1,80,25);clrscr();printf("Input ID number:");scanf("%s",id);fp=fopen(id,"r");if(fp==NULL){printf("\nuser isn't exit");getch();fclose(fp);adm2();}else while(!feof(fp)){fscanf(fp,"%s",a[i++]);}printf("\nname: %s",a[0]);printf("\nID: %s",a[1]);printf("\nsex: %s",a[2]); printf("\ngrad: %s",a[3]);f=fopen(a[0],"r");if(f==NULL);else{while(!feof(f)){ fscanf(f,"%s",b[j++]);}for(k=0;k<j-1;k++) printf("\nbook %d: %s",k+1,b[k]);}printf("\nDo you want to delete? (Y/N): ");c=getch();fclose(fp);fclose(f);if(c=='y'){remove(id);remove(a[0]);printf("\nsuccess");getch();adm2();}if(c=='n')adm2();}。

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

#include<stdio.h>#include<stdlib.h>#include<string.h>struct book{int num;char bname[50];char wname[20];char press[50];char sort[50];int time;float price;struct book *next;};struct book *creatbook(); //创建链表struct book *addbook(struct book *head); //添加图书int yanzheng(struct book *head,int m); //验证新添加的图书编码是否已存在void deletebook(struct book *head); //删除图书void fprint(struct book *head); //将链表写入文件struct book *load(); //从文件中读取信息并建成链表void print_book(struct book *head); //将链表信息输出void chaxun(struct book *head); //查询图书信息void num_chaxun(struct book *head); //按图书编号查询图书void wname_chaxun(struct book *head); //按作者名查询图书void sort_chaxun(struct book *head); //按类别查询图书void time_chaxun(struct book *head); //按出版时间查询图书void bname_chaxun(struct book *head); //按图书名查询图书void xiugai(struct book *head); //修改图书信息void paixu(struct book *head); //对图书进行排序void num_paixu(struct book *head); //按图书编号排序void time_paixu(struct book *head); //按图书出版时间排序void price_paixu(struct book *head); //按图书价格排序void bname_paixu(struct book *head); //按图书名排序void wname_paixu(struct book *head); //按作者名排序int main(){int choice,n,x,y=1,c,c1=1234;char a,d,b[10],b1[10]="yjk";struct book *head=NULL;while(y){system("cls");printf("\n\n\n\n\n\n\n");printf(" ********** 欢迎光临**********\n\n");printf(" ********************** 图书信息管理系统************************\n\n\n");printf("\n\n");printf(" ============1-用户登录===========\n");printf(" ============0-退出系统===========\n");printf(" 请输入您的选择:");scanf("%d",&n);printf("\n");getchar();switch(n){case 0:y=0;break;case 1:printf(" 请输入您的用户名:");gets(b);printf("\n");printf(" 请输入您的密码:");scanf("%d",&c);printf("\n");if(strcmp(b,b1)!=0||c!=c1){printf(" 验证失败,请重新输入!\n");scanf("%c",&d);getchar();system("cls");}else{printf(" 验证通过!请按Enter键进入!\n");scanf("%c",&d);getchar();x=1;while(x){system("cls");printf(" ------------------\n");printf(" *图书信息管理系统*\n");printf(" ------------------\n\n");printf("**********************************************\n\n");printf("**********************************************\n\n");printf(" || 1-添加图书2-删除图书||\n\n");printf(" || 3-图书列表4-图书排序||\n\n");printf(" || 5-查询图书6-修改图书||\n\n");printf(" || 7-录入数据0-退出系统||\n\n");printf("**********************************************\n\n");printf("**********************************************\n\n");printf("请输入所选择的序号:");scanf("%d",&choice);getchar();system("cls");switch(choice){case 0:x=0;break;case 1:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{head=addbook(head);printf("添加成功!\n");printf("是否将新信息保存到文件?(y/n)\n");scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;}case 2:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{deletebook(head);getchar();break;}break;case 3:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{print_book(head);getchar();break;}case 4:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{paixu(head);getchar();}break;case 5:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{chaxun(head);getchar();}break;case 6:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{xiugai(head);getchar();break;}break;case 7:printf("注意:输入图书编码为0时结束!\n");head=creatbook();printf("是否将输入的信息保存到文件以覆盖文件中已存在的信息?(y/n)\n");getchar();scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;default:printf("您的输入有误,请重新输入!\n");getchar();break;}}}break;default:printf(" 您的输入有误! 请重新输入!\n");getchar();break;}}}//录入数据并形成链表struct book *creatbook(){struct book *head,*tail,*p;int num,time,n;char bname[50],wname[20],press[50],sort[50];float price;int size=sizeof(struct book);head=tail=NULL;printf("请输入图书编号:");scanf("%d",&num);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();while(1){p=(struct book *)malloc(size);p->num=num;strcpy(p->bname,bname);strcpy(p->wname,wname);strcpy(p->press,press);strcpy(p->sort,sort);p->time=time;p->price=price;p->next=NULL;if(head==NULL)head=p;elsetail->next=p;tail=p;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n");}while(1);if(num==0)break;else{printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();}}return head;}//插入结点,并且插入后仍按一定顺序struct book *addbook(struct book *head){struct book *ptr,*p1,*p2,*p;char bname[50],wname[20],press[50],sort[50];int size=sizeof(struct book);int num,time,n=1;float price;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n");}while(1);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();p=(struct book *)malloc(size);p->num=num;strcpy(p->bname,bname);strcpy(p->wname,wname);strcpy(p->press,press);strcpy(p->sort,sort);p->time=time;p->price=price;p2=head;ptr=p;while((ptr->num>p2->num)&&(p2->next!=NULL)){ p1=p2;p2=p2->next;}if(ptr->num<=p2->num){if(head==p2)head=ptr;else{p1->next=ptr;p->next=p2;}}else{p2->next=ptr;p->next=NULL;}return head;}//验证添加的图书编号是否已存在int yanzheng(struct book *head,int m){struct book *p;p=head;while(p!=NULL){if(p->num==m)break;p=p->next;}if(p==NULL)return 0;elsereturn 1;}//将新链表写入文件中void fprint(struct book *head){FILE *fp;char ch='1';struct book *p1;if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fputc(ch,fp);for(p1=head;p1;p1=p1->next){fprintf(fp,"%d %s %s %s %s %d %f\n",p1->num,p1->bname,p1->wname,p1->press,p1->sort ,p1->time,p1->price);}fclose(fp);}//从文件中读取图书信息struct book *load(){FILE *fp;char ch;struct book *head,*tail,*p1;head=tail=NULL;if((fp=fopen("f1.txt","r"))==NULL){printf("File open error!\n");exit(0);}ch=fgetc(fp);if(ch=='1'){while(!feof(fp)){p1=(struct book *)malloc(sizeof(struct book));fscanf(fp,"%d%s%s%s%s%d%f\n",&p1->num,p1->bname,p1->wname,p1->press,p1->sort,&p1-> time,&p1->price);if(head==NULL)head=p1;elsetail->next=p1;tail=p1;}tail->next=NULL;fclose(fp);return head;}elsereturn NULL;}//将整个链表的信息输出void print_book(struct book *head){struct book *ptr;if(head==NULL){printf("\n没有信息!\n");return;}printf(" 图书信息列表如下\n");printf("==========================================================\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");for(ptr=head;ptr;ptr=ptr->next)printf(" %d %s %s %s %s %d %.2f\n",ptr->num,ptr->bname,ptr->wname,ptr->press,ptr->sort,ptr->time,ptr->price);printf("==========================================================\n");}//删除图书信息void deletebook(struct book *head){int a;char b,ch='1';struct book *p1,*p2;FILE *fp;printf("请输入要删除的图书编号:");scanf("%d",&a);p1=head;if(p1->num==a&&p1->next==NULL){ //对于文件中只有一组数据printf("是否清空文件!(y/n)\n");getchar();scanf("%c",&b);getchar();switch(b){case 'n':break;case 'y':if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fclose(fp);printf("文件已清空!\n");}}else{while(p1->num!=a&&p1->next!=NULL){p2=p1;p1=p1->next;}if(p1->next==NULL){if(p1->num==a){p2->next=NULL;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{printf("没有找到要删除的数据!\n");getchar();}}else if(p1==head){head=p1->next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{p2->next=p1->next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}}}//图书查询void chaxun(struct book *head){int a;printf("==========================================================\n");printf(" ** 1-按图书编号查询2-按图书名查询**\n");printf(" ** 3-按图书类别查询4-按作者名查询**\n");printf(" ** 5-按出版时间查询0-退出查询**\n");printf("==========================================================\n");printf("请输入所选择的编号:");scanf("%d",&a);getchar();switch(a){case 0:break;case 1:num_chaxun(head);break;case 2:bname_chaxun(head);break;case 3:sort_chaxun(head);break;case 4:wname_chaxun(head);break;case 5:time_chaxun(head);break;default:printf("您的输入有误!\n");break;}}//按编号查询图书信息void num_chaxun(struct book *head){int a;struct book *p;printf("请选择您要查询的图书编号:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p->num==a)break;p=p->next;}if(p==NULL){printf("没有找到该编号的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);printf("====================================================================== ===\n");}}//按图书名查询图书信息void bname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书名:");gets(a);p=head;while(p!=NULL){if(strcmp(p->bname,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->bname,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);}p=p->next;}printf("====================================================================== ===\n");}}//按作者名查询图书信息void wname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书作者名:");gets(a);p=head;while(p!=NULL){if(strcmp(p->wname,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->wname,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("====================================================================== ===\n");}}//按图书类别查询图书信息void sort_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书类别:");gets(a);p=head;while(p!=NULL){if(strcmp(p->sort,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->sort,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("====================================================================== ===\n");}}//按图书出版时间查询图书信息void time_chaxun(struct book *head){int a,flag=0;struct book *p;printf("请选择您要查询的图书出版时间:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p->time==a){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ===\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(p->time==a){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("====================================================================== ===\n");}}//修改图书信息void xiugai(struct book *head){int a,b;char c;struct book *p;printf("请输入要修改的图书编号:");scanf("%d",&a);p=head;while(p!=NULL){if(p->num==a)break;p=p->next;}if(p==NULL){printf("没有找到该编号的图书!\n");getchar();}else{printf("============================================================\n");printf(" ** 1-编号2-图书名3-作者名**\n");printf(" ** 4-出版社5-类别6-出版时间**\n");printf(" ** 7-价格8-修改全部0-放弃修改**\n");printf("============================================================\n");printf("请选择你要修改的信息编号:");scanf("%d",&b);getchar();switch(b){case 1:printf("请输入新编号:");scanf("%d",&p->num);printf("修改成功!\n");getchar();break;case 2:printf("请输入新图书名:");gets(p->bname);printf("修改成功!\n");break;case 3:printf("请输入新作者名:");gets(p->wname);printf("修改成功!\n");break;case 4:printf("请输入新出版社:");gets(p->press);printf("修改成功!\n");break;case 5:printf("请输入新类别:");gets(p->sort);printf("修改成功!\n");break;case 6:printf("请输入新出版时间:");scanf("%d",&p->time);printf("修改成功!\n");getchar();break;case 7:printf("请输入新价格:");scanf("%f",&p->price);printf("修改成功!\n");getchar();break;case 8:printf("请输入新图书编号:");scanf("%d",&p->num);printf("请输入新图书名:");scanf("%s",p->bname);getchar();printf("请输入新作者名:");scanf("%s",p->wname);getchar();printf("请输入新出版社:");scanf("%s",p->press);getchar();printf("请输入新类别:");scanf("%s",p->sort);getchar();printf("请输入新出版时间:");scanf("%d",&p->time);getchar();printf("请输入新价格:");scanf("%f",&p->price);getchar();printf("修改成功!\n");getchar();break;case 0:break;default :printf("您的输入有误!\n");break;}printf("是否将修改后的信息保存到文件中?(y/n)\n");scanf("%c",&c);getchar();switch(c){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}}}//图书排序void paixu(struct book *head){int a;printf("================================================================\n");printf(" ** 1-按图书编号排序2-按出版时间排序**\n");printf(" ** 3-按图书价格排序4-按图书名排序**\n");printf(" ** 5-按作者名排序0-取消排序操作**\n");printf("================================================================\n");printf("请输入您选择的编号:");scanf("%d",&a);getchar();switch(a){case 0:break;case 1:num_paixu(head);break;time_paixu(head);break;case 3:price_paixu(head);break;case 4:bname_paixu(head);break;case 5:wname_paixu(head);break;default:printf("您的输入有误!\n");break;}}//按图书编号排序void num_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->num<a[index]->num)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);switch(b){case 'n':break;case 'y':printf("================================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("================================================================\n");break;default:printf("您的输入有误!\n");break;}}//按出版时间排序void time_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->time<a[index]->time)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("===============================================================\n");break;default:printf("您的输入有误!\n");break;}}//按图书价格排序void price_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->price<a[index]->price)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("===============================================================\n");break;default:printf("您的输入有误!\n");break;}}//按图书名排序void bname_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(strcmp(a[index]->bname,a[i]->bname)>0)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("===============================================================\n");break;default:printf("您的输入有误!\n");break;}}//按作者名排序void wname_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(strcmp(a[index]->wname,a[i]->wname)>0)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s %d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("===============================================================\n");break;default:printf("您的输入有误!\n");break;}}。

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

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

#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#图书管理系统程序代码

/* Note:Your choice is C IDE */#include<graphics.h>#include "conio.h"#include<stdlib.h>#include<string.h>void main(){ void adm1(),adm2(),build(),huan(),borrow(),dele();adm1();} void adm1(){ FILE *fp,*p ;char adp[20],password[20];int i,n=0;textbackground(2);clrscr();gotoxy(25,12);fp=fopen("pass","r");if(fp==NULL) { prin ("no exit "); getch()();exit(0); }prin ("input password:");for(;;) { window(42,12,53,12);textbackground(0);clrscr();gets(adp);for(i=0;adp[i]!='\0';i++);fgets(password,i+1,fp); gotoxy(55,12);if(strcmp(password,adp)==0) { window(55,12,70,12);clrscr(); cprin ("YES"); getch()();adm2(); getch()();exit(0); }else{ n++;window(55,12,60,12); clrscr(); gotoxy(55,12); cprin ("error");for(i=0;i<30;i++) delay(8000);if(n==2) { window(55,12,70,12); clrscr();gotoxy(55,12); cprin ("once again"); for(i=0;i<=30;i++) delay(8000); }if(n==3) { window(55,12,70,12); clrscr();gotoxy(55,12); cprin ("3 second out"); for(i=0;i<=30;i++) { delay(8000); }exit(0); } }fclose(fp);clrscr(); }}void adm2(){ char a;window(1,1,80,25);clrscr();for(;;){ clrscr();gotoxy(30,8); prin ("built a new user (B)"); gotoxy(30,10); prin ("return book (R)"); gotoxy(30,12); prin ("borrow books (J)");gotoxy(30,14); prin ("delete user (D)");a=getch();if(a=='b') build();if(a=='r') huan();if(a=='j') borrow();if(a=='d') dele();else con nue;}} void build() { FILE *f,*p;char id[20],name[20],sex[2],age[3],grad[50];window(1,1,80,25);clrscr();prin ("ID number:");scanf("%s",id);prin ("name:");scanf("%s",name);prin ("sex:");scanf("%s",sex);prin ("grad:"); scanf("%s",grad);p=fopen(id,"w+"); if(p==NULL) { prin ("can't build that user"); getch();adm2(); }fprin (p,"%s ",name);fprin (p,"%s ",id);fprin (p,"%s ",sex);fprin (p,"%s ",grad);prin ("bulid success");getch();fclose(p); }void huan(){FILE *fp,*p,*f; char id[20],a[5][50],name[20],c; int i=0,m,k; clrscr();prin ("input ID number:");scanf("%s",id);p=fopen(id,"r");if(p==NULL) { prin ("error");getch();fclose(p);exit(0); }fscanf(p,"%s",name);fclose(p);fp=fopen(name,"r");do{ fscanf(fp,"%s",a[i++]); }while(!feof(fp));for(k=0;k<i-1;k++) prin ("\nbook %d: %s",k+1,a[k]); fclose(fp);f=fopen(name,"w+");for(;;){ prin ("\n\npress the book number that you want to return. \n\nPress 6 if you want to return all. \n\npress 7 to cancle.\n");scanf("%d",&m);if(m==7) { for(k=0;k<i-1;k++){fprin (f,"%s\n",a[k]);}fclose(f);adm2();}if(m==6) remove(name);if(m<6)for(k=0;k<i-1;k++){ if(k!=m-1)fprin (f,"%s\n",a[k]);}prin ("book %d has returned.",m);prin ("\ncon nue? (Y/N)");c=getch();if(c=='y') con nue;if(c=='n') { fclose(f);adm2(); }}} void borrow(){ FILE *f,*m,*p;char id[20],book[5][50],name[20],c;int i=0,n=0,k; window(1,1,80,25);clrscr();prin ("please input the user's ID:");scanf("%s",id);m=fopen(id,"r");if(m==NULL) { prin ("user no exit"); getch(); fclose(m); adm2(); }fscanf(m,"%s",name);fclose(m);p=fopen(name,"r");if(p==NULL); else{ while(!feof(p)){fscanf(p,"%s",book[i]);i++;}i--;for(k=0;k<i;k++) prin ("\nbook %d :%s",k+1,book[k]);}fclose(p);f=fopen(name,"w");prin ("\nhow many book do you want to borrow?:");do { prin ("\ninput:");scanf("%d",&n); } while(i+n>=6); for(k=i;k<i+n;k++){ prin ("\nbook %d :",k+1);scanf("%s",book[k]);} for(k=0;k<i+n;k++) fprin (f,"%s\n",book[k]);fputc('\0',f);prin ("success"); fclose(f);} void dele(){ FILE *fp,*f;char id[20],a[4][20],c,b[5][50];int i=0,j=0,k;window(1,1,80,25);clrscr();prin ("Input ID number:");scanf("%s",id);fp=fopen(id,"r");if(fp==NULL) { prin ("\nuser isn't exit"); getch(); fclose(fp); adm2(); }else while(!feof(fp)) { fscanf(fp,"%s",a[i++]); }prin ("\nname: %s",a[0]);prin ("\nID: %s",a[1]);prin ("\nsex: %s",a[2]); prin ("\ngrad: %s",a[3]);f=fopen(a[0],"r");if(f==NULL);else {while(!feof(f)){ fscanf(f,"%s",b[j++]);} for(k=0;k<j-1;k++) prin ("\nbook %d: %s",k+1,b[k]);}prin ("\nDo you want to delete? (Y/N): ");c=getch();fclose(fp);fclose(f); if(c=='y') { remove(id);remove(a[0]); prin ("\nsuccess"); getch(); adm2(); }if(c=='n') adm2();} 。

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

图书管理系统源代码--纯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。

图书管理系统程序代码

图书管理系统程序代码

#include<fstream〉#include<iostream〉#include<stdlib.h〉#include〈ctime〉#include<cmath>#include〈termios.h〉#include <sstream〉#include<string。

h〉#include<assert.h〉//改变字体颜色#define NONE "\033[m"#define RED "\033[0;32;31m”#define GREEN ”\033[0;32;32m”#define BLUE "\033[0;32;34m”#define YELLOW ”\033[1;33m”#define LIGHT_RED ”\033[1;31m”#define LIGHT_GREEN "\033[1;32m"#define LIGHT_BLUE "\033[1;34m”/*程序导读:1。

程序中对书的操作,可通过书名,编号来进行,flag=0按书名来操作,flag=1按书编号来操作2.程序中对用户的操作,也可通过姓名,用户ID号或编号两种方式来进行,flag=0按姓名来操作,flag=1按用户ID号或编号来操作3。

本程序分5个部分,具体已标识如(1)图书管理。

.*/using namespace std;class Book{public:string book_name;string book_num;//编号string book_pre;//出版社string book_aut;//作者int book_con;//这样的书还有几本int book_mux;//这样的书总共有几本public:Book(){book_con=0;book_mux=0;}void show_book();};/****************************************(1)图书管理*******************************************/void Book::show_book(){cout<〈"书名:”<〈book_name<〈endl;cout〈〈”出版社:"〈<book_pre〈〈endl;cout<<”此书的作者:"〈<book_aut〈<endl;cout〈<”ISBN编号:”<〈book_num<〈endl;cout<<"此书共有"〈<book_mux<<”本”〈〈endl;cout<<”还有"<<book_con〈〈”本书未借出!"〈<endl;}class BookNode{public:Book book;BookNode *next;};BookNode *headbook=NULL;class BookManage{public:int totolbook;public:BookManage(){totolbook=0;}void addbook();void delbook(string s,int num,int flag);void findbook(string s,int flag);//查询图书};void BookManage::addbook(){string h;cout〈〈"添加输入0,退出输入—1"<〈endl;cin>>h;if(h==”-1”)return;else if(h=="0”)while(1){if(h==”-1”)break;else if(h==”0”){string na,nu,p1,aut;int con;BookNode *p=new BookNode;cout<<”请输入书名:"〈〈endl;cin〉>na;p—〉book.book_name=na;cout<〈"请输入ISBN编号:”<<endl;cin>〉nu;p->book。

图书管理系统的C#代码完整版

图书管理系统的C#代码完整版

C#代码清单共1个项目,包含5个类。

项目: librarysystem类:主类代码:namespace librarysystem{ PublicationISBN = PublicationISBN;= PublicationName;= PublicationAuthor;= PublicationType;= PublicationStatus;}}}读者类代码:namespace librarysystem{ 询图书");("2.借书服务");("3.还书服务");("4.新出版物入库");("5.录入新读者");("6.查询读者的借阅信息");("7.退出管理系统");("-------------------------------------------------------------------");bool flag;do{flag = false;("请选择:");string key = ();switch (key){case"1":("请输入需要查询图书的书名:");ShowPubInfo();break;case"2":("请输入您的姓名:");();ShowBorrowInfo();("请输入您的姓名:");();ShowReturnInfo();break;case"4":("请按照提示逐步输入需要入库出版物的信息……");ShowAddPublications();break;case"5":("请按照提示逐步输入新注册读者的信息……");ShowAddReaders();break;case"6":("请输入您的姓名: ");();ShowRedPubInfo;break;case"7":flag = false;break;default:("无此业务,是否重新选择(y/n)");string answer = ();if (answer != "y"){flag = false;}else{flag = true;}break;}} while (flag);}/*显示查询到的出版物信息*/public void ShowPubInfo(){if ()){("您要查询的出版物信息:");("-------------------------------------------------------------------"); ("编号: " + ("出版物名字: " + ("出版物作者: " + ("出版物类型: " + if {("出版物状态:在架,可借");else{("出版物状态:未在架,不可借");}("-------------------------------------------------------------------"); ("");("");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();();}else{("结束");}}else{("抱歉,未找到该图书!");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();();();}else{("结束");}}}/*显示借阅操作结果*/public void ShowBorrowInfo(){if{("恭喜,借阅成功!");ShowRedPubInfo;}{("抱歉,借阅失败!");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();}else{("结束");}}}/*显示归还操作结果*/public void ShowReturnInfo(){if{("恭喜,归还成功!");ShowRedPubInfo;}else{("抱歉,归还失败!");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();}else{("结束");}}}public void ShowRedPubInfo(Readers red){("当前你的借阅信息如下:");("--------------------------------------------------------------------"); ("编号: " + ;("姓名: " + ;("性别: " + ;("主修专业: " + ;("已借图书: ");for (int{if [i] != ""){(" "+[i]);}}("");("--------------------------------------------------------------------"); ("");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();}else{("结束");}}/*显示新出版物入库的信息*/public void ShowAddPublications(){pub = new Publications();("请输入出版物的编号: ");=();("请输入出版物的名称: ");= ();("请输入出版物的编者: ");= ();("请输入出版物的类型: ");= ();= true;(pub);("新出版物入库成功!");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();();}else{("结束");}}/*显示新读者注册的信息*/public void ShowAddReaders(){red = new Readers();("请输入新注册读者的编号: "); = ();("请输入新注册读者的姓名: "); = ();("请输入新注册读者的性别: "); = ();("请输入新注册读者的院系: "); = ();("请输入新注册读者的专业: "); = ();for(int i=0;i<10;i++){[i]="";}(red);("新读者注册成功!");("是否办理其他业务(y/n) ");string answer = ();if (answer == "y"){ShowMainMenu();();();}else{("结束");}}}}。

图书管理系统的C#代码(完整版)

图书管理系统的C#代码(完整版)

C#代码清单共1个项目,包含5个类。

项目:librarysystem类:Program.cs Readers。

cs Manage.cs Menu.cs Publications.cs主类代码:namespace librarysystem{///〈summary〉///类名:Program///功能:项目主类///时间:2015—11-19///〈/summary〉class Program{static void Main(string[] args){Menu meu = new Menu();meu.ShowMainMenu();Console。

ReadLine();}}}出版物类代码:namespace librarysystem{ ///<summary〉///类名:Publications///功能:馆藏出版物信息///时间:2015—11-19///〈/summary〉class Publications{/*出版物编号*/private string PublicationISBN;public string PublicationIsbn{get{return PublicationISBN;}{PublicationISBN = value;}}/*出版物名称*/public string PublicationName;/*出版物作者或出版机构*/public string PublicationAuthor;/*出版物在架状态*/public bool PublicationStatus;/*出版物类型*/public string PublicationType;public Publications(){}public Publications(string PublicationISBN,string PublicationName,string PublicationAuthor,string PublicationType,bool PublicationStatus){this。

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

图书管理系统设计图书管理信息包括:图书名称、图书编号、单价、作者、存在状态、借书人姓名、性别、学号等功能描述:1 .新进熟土基本信息的输入2 .图书基本信息的查询3 .对撤销图书信息的删除4 .为借书人办理注册5 .办理借书手续6 .办理换书手续要求:以文件方式存储数据,系统以菜单方式工作。

这是本人大一第二学期初 C 语言课程设计的作品,嘿嘿,本来以为已经找不到原稿了,今天无意中居然在QQ 网络硬盘中找到了当初的teta 版,发布于此,以作记念。

C 源代码如下:#include〈stdio 。

h〉#include<stdlib。

h〉#include〈string 。

h>struct book {char book_name [30];int bianhao;double price;char author[20];char state [20] ;char name[20];char sex [10];int xuehao;struct book *book_next;};struct club {char name [20];char sex[10];int xuehao;char borrow [30];struct club *club_next;};void Print_Book(struct book *head_book);/*浏览所有图书信息*/void Print_Club(struct club *head_club);/*浏览所有会员信息*/struct book *Create_New_Book();/*创建新的图书库, 图书编号输入为0 时结束*/struct book *Search_Book_bianhao(int bianhao,struct book *head_book);struct book *Search_Book_name (char *b_name,struct book *head_book);struct book *Search_Book_price (double price_h,double price_l,struct book *head_book);struct book *Insert_Book (struct book *head_book,struct book *stud_book) ;/*增加图书,逐个添加*/struct book *Delete_Book(struct book *head_book,int bianhao);/*删除图书*/struct club *Create_New_Club() ;struct club *Search_Club_xuehao(int xuehao,struct club *head_club);struct club *Search_Club_name (char *c_name,struct club *head_club);struct club *Insert_Club (struct club *head_club,struct club *stud_club);struct club *Delete_Club (struct club *head_club,int xuehao);struct book *Lent_Book (int bianhao ,int xuehao,struct book *head_book,struct club *head_club);struct book *back (int bianhao,int xuehao,struct book *head_book,struct club *head_club); int main(){struct book *head_book,*p_book;char book_name [30],name [20],author [20],sex [10];int bianhao;double price,price_h,price_l;int size_book=sizeof(struct book);int m=1,n=1,f;char *b_name,*c_name;struct club *head_club,*p_club;int xuehao;int size_club=sizeof (struct club) ;int choice;printf ("\n 欢迎您第一次进入图书管理系统!\n\n");printf("---——>[向导]————-〉[新建图书库] \n\n”) ;printf ("注意:当输入图书编号为0 时,进入下一步.\n\n");head_book=Create_New_Book();system(”cls”) ;printf("\n 欢迎您第一次进入图书管理系统!\n\n") ;printf("----—〉[向导]——---〉[新建会员库]\n\n”);printf(”注意:当输入会员学号为0 时,进入主菜单.\n\n”);head_club=Create_New_Club () ;system (”cls”);do {printf(”\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n”);printf("\n”);printf ("\t\t\t[1] :借书办理\t");printf(" [6]:还书办理\n”);printf (”\n");printf(”\t\t\t[2]:查询图书\t");printf(" [7]:查询会员\n”);printf (” \t\t\t[3]:添加图书\t");printf (" [8]:添加会员\n”);printf ("\t\t\t[4]:删除图书\t");printf (” [9] :删除会员\n") ;printf (” \t\t\t[5]:遍历图书\t");printf (” [10]:遍历会员\n\n”) ;printf ("\t\t\t〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n\n”);printf("\t\t\t0:退出\n\n”) ;printf(”请选择〈0~10〉:”);scanf(”%d",&choice);switch(choice) {case 1:printf ("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");printf (”输入所借图书编号:\n");scanf (”%d",&bianhao);printf ("输入借书人的学号:\n”);scanf ("%d",&xuehao);head_book=Lent_Book(bianhao,xuehao,head_book,head_club);system (”cls");printf (” \n 借阅成功!\n\n");printf (”相关信息如下:\n\n");head_book=Search_Book_bianhao (bianhao,head_book);break;case 2:system ("cls”) ;printf(”\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n”); printf ("1。

c语言图书馆管理系统(codeblocks版)

c语言图书馆管理系统(codeblocks版)
printf("\t--------ID: %40s--------\n", p1->ID);
printf("\t--------PASS: %40s--------\n", p1->pass);
printf("\t--------LEVEL:%40d--------\n", p1->level);
/*
*图书馆管理系统
*@author琴卓
*@time 2015-12-10
*/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#include<windows.h>
#define PASS_LEN 20 //密码长度
int lendsum;
struct user *next;
}user;
//用户结构体简写为bokk
typedef struct book {
char name[20];
char author[20];
char publish[20];
char year[10];
char ISBN[40];
char state[10];
char choice;
//程序入口
void main()
{
system("color 8b");
system("mode con cols=100 lines=50");
printf("\t\t\t图书馆系统细则:\n\t\t1.新用户注册由系统管理员操作\n\t\t2.图书由图书管理员负责\n\t\t3.普通用户最多借3本书为期30天,可续借一次,\n\t\t超期不换将每天扣除0.1元,超过10元账户将冻\n\t\t结,届时无法完成登录,需要找系统管理员解冻\n\t\t4.密码输入支持退格,访问级别1代表普通用户\n\t\t5.单项数据输入不支持空格\n\t\t6.程序每关闭开启一次经过6天\n");

C语言图书管理系统代码(完整资料).doc

C语言图书管理系统代码(完整资料).doc

【最新整理,下载后即可编辑】#include<stdio.h>#include<stdlib.h>#include<string.h>struct book{int num;char bname[50];char wname[20];char press[50];char sort[50];int time;float price;struct book *next;};struct book *creatbook(); //创建链表struct book *addbook(struct book *head); //添加图书int yanzheng(struct book *head,int m); //验证新添加的图书编码是否已存在void deletebook(struct book *head); //删除图书void fprint(struct book *head); //将链表写入文件struct book *load(); //从文件中读取信息并建成链表void print_book(struct book *head); //将链表信息输出void chaxun(struct book *head); //查询图书信息void num_chaxun(struct book *head); //按图书编号查询图书void wname_chaxun(struct book *head); //按作者名查询图书void sort_chaxun(struct book *head); //按类别查询图书void time_chaxun(struct book *head); //按出版时间查询图书void bname_chaxun(struct book *head); //按图书名查询图书void xiugai(struct book *head); //修改图书信息void paixu(struct book *head); //对图书进行排序void num_paixu(struct book *head); //按图书编号排序void time_paixu(struct book *head); //按图书出版时间排序void price_paixu(struct book *head); //按图书价格排序void bname_paixu(struct book *head); //按图书名排序void wname_paixu(struct book *head); //按作者名排序int main(){int choice,n,x,y=1,c,c1=1234;char a,d,b[10],b1[10]="yjk";struct book *head=NULL;while(y){system("cls");printf("\n\n\n\n\n\n\n");printf(" ********** 欢迎光临**********\n\n");printf(" ********************** 图书信息管理系统************************\n\n\n");printf("\n\n");printf(" ============1-用户登录===========\n");printf(" ============0-退出系统===========\n");printf(" 请输入您的选择:");scanf("%d",&n);printf("\n");getchar();switch(n){case 0:y=0;break;case 1:printf(" 请输入您的用户名:");gets(b);printf("\n");printf(" 请输入您的密码:");scanf("%d",&c);printf("\n");if(strcmp(b,b1)!=0||c!=c1){printf(" 验证失败,请重新输入!\n");scanf("%c",&d);getchar();system("cls");}else{printf(" 验证通过!请按Enter键进入!\n");scanf("%c",&d);getchar();x=1;while(x){system("cls");printf("------------------\n");printf(" *图书信息管理系统*\n");printf("------------------\n\n");printf("**********************************************\n\n");printf("**********************************************\n\n");printf(" || 1-添加图书2-删除图书||\n\n");printf(" || 3-图书列表4-图书排序||\n\n");printf(" || 5-查询图书6-修改图书||\n\n");printf(" || 7-录入数据0-退出系统||\n\n");printf("**********************************************\n\n");printf("**********************************************\n\n");printf("请输入所选择的序号:");scanf("%d",&choice);getchar();system("cls");switch(choice){case 0:x=0;break;case 1:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{head=addbook(head);printf("添加成功!\n");printf("是否将新信息保存到文件?(y/n)\n");scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;}case 2:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{deletebook(head);getchar();break;}break;case 3:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{print_book(head);getchar();break;}case 4:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{paixu(head);getchar();}break;case 5:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{chaxun(head);getchar();}break;case 6:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{xiugai(head);getchar();break;}break;case 7:printf("注意:输入图书编码为0时结束!\n");head=creatbook();printf("是否将输入的信息保存到文件以覆盖文件中已存在的信息?(y/n)\n");getchar();scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;default:printf("您的输入有误,请重新输入!\n");getchar();break;}}}break;default:printf(" 您的输入有误! 请重新输入!\n");getchar();break;}}}//录入数据并形成链表struct book *creatbook(){struct book *head,*tail,*p;int num,time,n;char bname[50],wname[20],press[50],sort[50];float price;int size=sizeof(struct book);head=tail=NULL;printf("请输入图书编号:");scanf("%d",&num);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();while(1){p=(struct book *)malloc(size);p->num=num;strcpy(p->bname,bname);strcpy(p->wname,wname);strcpy(p->press,press);strcpy(p->sort,sort);p->time=time;p->price=price;p->next=NULL;if(head==NULL)head=p;elsetail->next=p;tail=p;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n"); }while(1);if(num==0)break;else{printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();}}return head;}//插入结点,并且插入后仍按一定顺序struct book *addbook(struct book *head){struct book *ptr,*p1,*p2,*p;char bname[50],wname[20],press[50],sort[50];int size=sizeof(struct book);int num,time,n=1;float price;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n"); }while(1);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();p=(struct book *)malloc(size);p->num=num;strcpy(p->bname,bname);strcpy(p->wname,wname);strcpy(p->press,press);strcpy(p->sort,sort);p->time=time;p->price=price;p2=head;ptr=p;while((ptr->num>p2->num)&&(p2->next!=NULL)){ p1=p2;p2=p2->next;}if(ptr->num<=p2->num){if(head==p2)head=ptr;else{p1->next=ptr;p->next=p2;}}else{p2->next=ptr;p->next=NULL;}return head;}//验证添加的图书编号是否已存在int yanzheng(struct book *head,int m){struct book *p;p=head;while(p!=NULL){if(p->num==m)break;p=p->next;}if(p==NULL)return 0;elsereturn 1;}//将新链表写入文件中void fprint(struct book *head){FILE *fp;char ch='1';struct book *p1;if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fputc(ch,fp);for(p1=head;p1;p1=p1->next){fprintf(fp,"%d %s %s %s %s %d %f\n",p1->num,p1->bname,p1->wname,p1->press,p1->sort,p1->time,p1->price);}fclose(fp);}//从文件中读取图书信息struct book *load(){FILE *fp;char ch;struct book *head,*tail,*p1;head=tail=NULL;if((fp=fopen("f1.txt","r"))==NULL){printf("File open error!\n");exit(0);}ch=fgetc(fp);if(ch=='1'){while(!feof(fp)){p1=(struct book *)malloc(sizeof(struct book));fscanf(fp,"%d%s%s%s%s%d%f\n",&p1->num,p1->bname,p1->wna me,p1->press,p1->sort,&p1->time,&p1->price);if(head==NULL)head=p1;elsetail->next=p1;tail=p1;}tail->next=NULL;fclose(fp);return head;}elsereturn NULL;}//将整个链表的信息输出void print_book(struct book *head){struct book *ptr;if(head==NULL){printf("\n没有信息!\n");return;}printf(" 图书信息列表如下\n");printf("========================================= =================\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");for(ptr=head;ptr;ptr=ptr->next)printf(" %d %s %s %s %s %d %.2f\n",ptr->num,ptr->bname,ptr->w name,ptr->press,ptr->sort,ptr->time,ptr->price);printf("========================================= =================\n");}//删除图书信息void deletebook(struct book *head){int a;char b,ch='1';struct book *p1,*p2;FILE *fp;printf("请输入要删除的图书编号:");scanf("%d",&a);p1=head;if(p1->num==a&&p1->next==NULL){ //对于文件中只有一组数据printf("是否清空文件!(y/n)\n");getchar();scanf("%c",&b);getchar();switch(b){case 'n':break;case 'y':if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fclose(fp);printf("文件已清空!\n");}}else{while(p1->num!=a&&p1->next!=NULL){p2=p1;p1=p1->next;}if(p1->next==NULL){if(p1->num==a){p2->next=NULL;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{printf("没有找到要删除的数据!\n");getchar();}}else if(p1==head){head=p1->next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{p2->next=p1->next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}}}//图书查询void chaxun(struct book *head){int a;printf("========================================= =================\n");printf(" ** 1-按图书编号查询2-按图书名查询**\n");printf(" ** 3-按图书类别查询4-按作者名查询**\n");printf(" ** 5-按出版时间查询0-退出查询**\n");printf("========================================= =================\n");printf("请输入所选择的编号:");scanf("%d",&a);getchar();switch(a){case 0:break;case 1:num_chaxun(head);break;case 2:bname_chaxun(head);break;case 3:sort_chaxun(head);break;case 4:wname_chaxun(head);break;case 5:time_chaxun(head);break;default:printf("您的输入有误!\n");break;}}//按编号查询图书信息void num_chaxun(struct book *head){int a;struct book *p;printf("请选择您要查询的图书编号:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p->num==a)break;p=p->next;}if(p==NULL){printf("没有找到该编号的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("========================================= ================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->pri ce);printf("========================================= ================================\n");}}//按图书名查询图书信息void bname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书名:");gets(a);p=head;while(p!=NULL){if(strcmp(p->bname,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}printf(" 你所查询的图书信息如下\n");printf("========================================= ================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->bname,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->pri ce);}p=p->next;}printf("========================================= ================================\n");}}//按作者名查询图书信息void wname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书作者名:");p=head;while(p!=NULL){if(strcmp(p->wname,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("========================================= ================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->wname,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->pri ce);flag=1;}p=p->next;}printf("========================================= ================================\n");}}//按图书类别查询图书信息void sort_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书类别:");gets(a);p=head;while(p!=NULL){if(strcmp(p->sort,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("========================================= ================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(strcmp(p->sort,a)==0){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->pri ce);flag=1;}p=p->next;}printf("========================================= ================================\n");}}//按图书出版时间查询图书信息void time_chaxun(struct book *head){int a,flag=0;struct book *p;printf("请选择您要查询的图书出版时间:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p->time==a){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("========================================= ================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");while(p!=NULL){if(p->time==a){printf("** %d %s %s %s %s %d %.2f **\n",p->num,p->bname,p->wname,p->press,p->sort,p->time,p->pri ce);flag=1;}p=p->next;}printf("========================================= ================================\n");}}//修改图书信息void xiugai(struct book *head){int a,b;char c;struct book *p;printf("请输入要修改的图书编号:");scanf("%d",&a);p=head;while(p!=NULL){if(p->num==a)break;p=p->next;}if(p==NULL){printf("没有找到该编号的图书!\n");getchar();}else{printf("========================================= ===================\n");printf(" ** 1-编号2-图书名3-作者名**\n");printf(" ** 4-出版社5-类别6-出版时间**\n");printf(" ** 7-价格8-修改全部0-放弃修改**\n");printf("========================================= ===================\n");printf("请选择你要修改的信息编号:");scanf("%d",&b);getchar();switch(b){case 1:printf("请输入新编号:");scanf("%d",&p->num);printf("修改成功!\n");getchar();break;case 2:printf("请输入新图书名:");gets(p->bname);printf("修改成功!\n");break;case 3:printf("请输入新作者名:");gets(p->wname);printf("修改成功!\n");break;case 4:printf("请输入新出版社:");gets(p->press);printf("修改成功!\n");break;case 5:printf("请输入新类别:");gets(p->sort);printf("修改成功!\n");break;case 6:printf("请输入新出版时间:");scanf("%d",&p->time);printf("修改成功!\n");getchar();break;case 7:printf("请输入新价格:");scanf("%f",&p->price);printf("修改成功!\n");getchar();break;case 8:printf("请输入新图书编号:");scanf("%d",&p->num);printf("请输入新图书名:");scanf("%s",p->bname);getchar();printf("请输入新作者名:");scanf("%s",p->wname);getchar();printf("请输入新出版社:");scanf("%s",p->press);getchar();printf("请输入新类别:");scanf("%s",p->sort);getchar();printf("请输入新出版时间:");scanf("%d",&p->time);getchar();printf("请输入新价格:");scanf("%f",&p->price);getchar();printf("修改成功!\n");getchar();break;case 0:break;default :printf("您的输入有误!\n");break;}printf("是否将修改后的信息保存到文件中?(y/n)\n");scanf("%c",&c);getchar();switch(c){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}}}//图书排序void paixu(struct book *head){int a;printf("========================================= =======================\n");printf(" ** 1-按图书编号排序2-按出版时间排序**\n");printf(" ** 3-按图书价格排序4-按图书名排序**\n");printf(" ** 5-按作者名排序0-取消排序操作**\n");printf("========================================= =======================\n");printf("请输入您选择的编号:");scanf("%d",&a);getchar();switch(a){case 0:break;case 1:num_paixu(head);break;case 2:time_paixu(head);break;case 3:price_paixu(head);break;case 4:bname_paixu(head);break;case 5:wname_paixu(head);break;default:printf("您的输入有误!\n");break;}}//按图书编号排序void num_paixu(struct book *head) {struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->num<a[index]->num)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("========================================= =======================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s % d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->t ime,a[i]->price);}printf("========================================= =======================\n");break;default:printf("您的输入有误!\n");break;}}//按出版时间排序void time_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->time<a[index]->time)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("===============================================================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s % d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->t ime,a[i]->price);}printf("========================================= ======================\n");break;default:printf("您的输入有误!\n");break;}}//按图书价格排序void price_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->price<a[index]->price)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("========================================= ======================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s % d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->t ime,a[i]->price);}printf("========================================= ======================\n");break;default:printf("您的输入有误!\n");break;}}//按图书名排序void bname_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(strcmp(a[index]->bname,a[i]->bname)>0)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("========================================= ======================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s % d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->t ime,a[i]->price);}printf("========================================= ======================\n");break;default:printf("您的输入有误!\n");break;}}//按作者名排序void wname_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(strcmp(a[index]->wname,a[i]->wname)>0)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("========================================= ======================\n");printf(" ** 编号图书名作者名出版社类别出版时间价格**\n");for(i=0;i<n;i++){printf("** %d %s %s %s %s % d %.2f **\n",a[i]->num,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->t ime,a[i]->price);}printf("========================================= ======================\n");break;default:printf("您的输入有误!\n");break;}}【最新整理,下载后即可编辑】。

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

C#代码清单共1个项目,包含5个类。

项目:librarysystem类:主类代码:namespace librarysystem{ PublicationISBN = PublicationISBN;= PublicationName;= PublicationAuthor;= PublicationType;= PublicationStatus;}}}读者类代码:namespace librarysystem{ 询图书");("2.借书服务");("3.还书服务");("4.新出版物入库");("5.录入新读者");("6.查询读者的借阅信息");("7.退出管理系统");("-------------------------------------------------------------------");bool flag;do{flag = false;("请选择:");string key = ();switch (key){case"1":("请输入需要查询图书的书名:");ShowPubInfo();break;case"2":("请输入您的姓名:");();ShowBorrowInfo();break;case"3":("请输入您的姓名:");();ShowReturnInfo();break;case"4":("请按照提示逐步输入需要入库出版物的信息……"); ShowAddPublications();break;case"5":("请按照提示逐步输入新注册读者的信息……");ShowAddReaders();break;case"6":("请输入您的姓名: ");();ShowRedPubInfo;break;case"7":flag = false;break;default:("无此业务,是否重新选择(y/n)?");string answer = ();if (answer != "y"){flag = false;}else{flag = true;}break;}} while (flag);}/*显示查询到的出版物信息*/public void ShowPubInfo(){if ()){("您要查询的出版物信息:");("-------------------------------------------------------------------");("编号: " + ("出版物名字: " + ("出版物作者: " + ("出版物类型: " + if { ("出版物状态:在架,可借");}else{("出版物状态:未在架,不可借");}("-------------------------------------------------------------------");("");("");("是否办理其他业务(y/n)?");string answer = ();if (answer == "y"){ShowMainMenu();();}else{("结束");}}else{("抱歉,未找到该图书!");("是否办理其他业务(y/n)?");string answer = ();if (answer == "y"){ShowMainMenu();();();}else{("结束");}}}/*显示借阅操作结果*/public void ShowBorrowInfo(){if{("恭喜,借阅成功!");ShowRedPubInfo;}else{("抱歉,借阅失败!");("是否办理其他业务(y/n)?");string answer = ();if (answer == "y"){ShowMainMenu();}else{("结束");}}}/*显示归还操作结果*/public void ShowReturnInfo(){if{("恭喜,归还成功!");ShowRedPubInfo;}else{("抱歉,归还失败!");("是否办理其他业务(y/n)?");string answer = ();if (answer == "y"){ShowMainMenu();}else{("结束");}}}public void ShowRedPubInfo(Readers red){("当前你的借阅信息如下:");("--------------------------------------------------------------------"); ("编号: " + ;("姓名: " + ;("性别: " + ;("所在院系: " + ;("主修专业: " + ;("已借图书: ");for (int i = 0; i < i++){if [i] != ""){(" "+[i]);}}("");("--------------------------------------------------------------------"); ("");("是否办理其他业务(y/n)?");string answer = ();if (answer == "y"){ShowMainMenu();}else{("结束");}}/*显示新出版物入库的信息*/public void ShowAddPublications(){pub = new Publications();("请输入出版物的编号: ");=();("请输入出版物的名称: ");= ();("请输入出版物的编者: ");= ();("请输入出版物的类型: ");= ();= true;(pub);("新出版物入库成功!");("是否办理其他业务(y/n)?");string answer = ();if (answer == "y"){ShowMainMenu();();();}else{("结束");}}/*显示新读者注册的信息*/public void ShowAddReaders(){red = new Readers();("请输入新注册读者的编号: "); = ();("请输入新注册读者的姓名: "); = ();("请输入新注册读者的性别: "); = ();("请输入新注册读者的院系: "); = ();("请输入新注册读者的专业: "); = ();for(int i=0;i<10;i++){[i]="";}(red);("新读者注册成功!");("是否办理其他业务(y/n)?");string answer = ();if (answer == "y") {ShowMainMenu(); ();();}else{("结束");}}}}。

相关文档
最新文档