课程设计-图书信息管理系统
来源:互联网 发布:遗传算法基本思想 编辑:程序博客网 时间:2024/05/21 21:38
介绍:
课程设计-银行储蓄系统——》在这里
图书信息管理系统包括:登录号、书名、作者名、分类号、出版单位、出版时间、价格等。试设计一图书信息管理系统,使之能提供以下功能:
(1)系统以菜单方式工作(2)图书信息录入功能(学生信息用文件保存)---输入
(3)图书信息浏览功能---输出
(4)查询、排序功能
按登录号查询
按书名查询
(5)图书信息的删除与修改
源代码:
下面是源代码:
book.h:
#ifndef BOOK_H_INCLUDED#define BOOK_H_INCLUDED#include<fstream>#include<iostream>#include<cstdlib>#include<string>using namespace std;class Book//图书的类{private: string number;//登陆号 string name;//书名 string author;//作者 string snumber;//分类号 string office;//出版单位 string time;//出版时间 string money;//价格public: string get_number(){return number;} string get_name(){return name;} string get_author(){return author;} string get_snumber(){return snumber;} string get_office(){return office;} string get_time(){return time;} string get_money(){return money;} void set_number(string num){number=num;} void set_name(string n){name=n;} void set_author(string a){author=a;} void set_snumber(string sn){snumber=sn;} void set_office(string o){office=o;} void set_time(string t){time=t;} void set_money(string m){money=m;} void setbook(string num,string n,string a,string sn,string o,string t,string m);};#endif // BOOK_H_INCLUDED
menu.h:
#ifndef MENU_H_INCLUDED#define MENU_H_INCLUDED#include<fstream>#include<iostream>#include<cstdlib>#include<string>using namespace std;class Menu{public: Book *book=new Book[5000]; Menu(); ~Menu(); int num; void showmenu(); int name_search(string);//桉树名查找 int num_search(string);//按登录号查找 void searchbook(int);//查找图书 void showinfo(int);//显示图书信息 void showchange();//显示信息更改菜单 void showall();//显示所有的信息 int openfile(void);//打开文件 void savefile();//保存文件 void addinfo();//增加图书信息 void changeinfo();//修改图书信息};#endif // MENU_H_INCLUDED
book.cpp:
#include <fstream>#include <iostream>#include <cstdlib>#include <string>#include "book.h"using namespace std;void Book::setbook(string num,string n,string a,string sn,string o,string t,string m){ number=num; name=n; author=a; snumber=sn; office=o; time=t; money=m;}
menu.cpp:
#include <fstream>#include <iostream>#include <cstdlib>#include <string>#include "book.h"#include "menu.h"using namespace std;Menu::Menu(){ num=0; string number,n,a,sn,o,t,m; ifstream infile("bookinfo.dat",ios::in); if (!infile) { cout<<"打开文件失败!"; exit(1); } while (infile>>number>>n>>a>>sn>>o>>t>>m) { book[num].setbook(number,n,a,sn,o,t,m); num++; } infile.close(); //cout<<num<<endl; //文件读取结束}Menu::~Menu(){ delete []book;}void Menu::savefile(){ int i; ofstream outfile("bookinfo.dat",ios::out); if (!outfile) { cout<<"打开文件失败!"; exit(1); } for (i=0; i<num; i++) { outfile<<book[i].get_number()<<" "<<book[i].get_name()<<" "<<book[i].get_author()<<" "<<book[i].get_snumber()<<" "<<book[i].get_office()<<" "<<book[i].get_time()<<" "<<book[i].get_money()<<endl; } outfile.close();}void Menu::showmenu(){ /*for (int i=0; i<num; i++) { cout<<book[i].get_number()<<book[i].get_name()<<endl; }*/ cout<<"+-------------------+"<<endl; cout<<"图书信息管理系统"<<endl; cout<<"+-------------------+"<<endl; cout<<"1、按登录号查找"<<endl; cout<<"2、按书名查找"<<endl; cout<<"3、图书信息浏览"<<endl; cout<<"4、图书信息录入"<<endl; cout<<"5、修改图书信息"<<endl; cout<<"请选择功能(输入0退出):";}void Menu::showchange(void){ cout<<"+-------------------+"<<endl; cout<<"1、登陆号"<<endl; cout<<"2、书名"<<endl; cout<<"3、作者名"<<endl; cout<<"4、分类号"<<endl; cout<<"5、出版单位"<<endl; cout<<"6、出版时间"<<endl; cout<<"7、价格"<<endl; cout<<"+-------------------+"<<endl; cout<<"请输入要修改的选项(1-7):";}int Menu::name_search(string key)//按书名查找{ int i; for (i=0; i<num; i++) { if (key==book[i].get_name()) return i; } return i;}int Menu::num_search(string key)//按登录号查找{ int i=-1; for (i=0; i<num; i++) { if (key==book[i].get_number()) return i; } return i;}void Menu::searchbook(int way)//查找图书信息{ string numkey,namekey; int i; while(1) { if (way==1) { cout<<"请输入图书登录号:"; cin>>numkey; i=num_search(numkey); if (i==-1) { cout<<"无此图书信息!"<<endl; continue; } else { showinfo(i); system("PAUSE"); break; } } else if (way==2) { cout<<"请输入书名:"; cin>>namekey; i=name_search(namekey); if (i==-1) { cout<<"无此图书信息!"<<endl; continue; } else { showinfo(i); system("PAUSE"); break; } } }}void Menu::showinfo(int i){ cout<<book[i].get_number()<<" "<<book[i].get_name()<<" "<<book[i].get_author()<<" "<<book[i].get_snumber()<<" "<<book[i].get_office()<<" "<<book[i].get_time()<<" "<<book[i].get_money()<<endl;}void Menu::showall(){ int i; cout<<"图书信息:"<<endl<<cout<<"依次为图书的登陆号、书名、作者名、分类号、出版单位、出版时间、价格:"<<endl; for (i=0; i<num; i++) { showinfo(i); } system("PAUSE");}void Menu::addinfo(){ int add,addsum,tem; tem=num; string numb,n,a,sn,o,t,m; cout<<"请输入录入的个数:"; cin>>addsum; cout<<"请依次输入图书的登陆号、书名、作者名、分类号、出版单位、出版时间、价格"<<endl; cout<<"例如:201501 《在这复杂的世界里》 韩寒 201 浙江出版社 2014-06-01 49"<<endl; //打开文件 ofstream outfile("bookinfo.dat",ios::app); if (!outfile) { cout<<"打开文件失败!"; exit(1); } tem+=addsum; for (add=tem; add<(addsum+tem); add++) { cin>>numb>>n>>a>>sn>>o>>t>>m; outfile<<numb<<" "<<n<<" "<<" "<<a<<" "<<sn<<" "<<a<<" "<<t<<" "<<m<<endl; } num=addsum+tem; outfile.close(); cout<<"写入结束!共写入"<<addsum<<"条记录,现共有"<<num-1<<"条记录。"<<endl; system("PAUSE"); //文件写入结束}void Menu::changeinfo(){ int i; string numkey,numb,n,a,sn,o,t,m; int cut; cout<<"请输入要修改图书的登陆号:"; cin>>numkey; i=num_search(numkey); cout<<"您正在修改“"; showinfo(i); cout<<"”的信息"<<endl; showchange(); cin>>cut; cout<<"请输入修改的内容:"; while (1) { if (cut==1) { cin>>numb; book[i].set_number(numb); } else if (cut==2) { cin>>n; book[i].set_name(n); } else if (cut==3) { cin>>a; book[i].set_author(a); } else if (cut==4) { cin>>sn; book[i].set_snumber(sn); } else if (cut==5) { cin>>o; book[i].set_office(o); } else if (cut==6) { cin>>t; book[i].set_time(t); } else if (cut==7) { cin>>m; book[i].set_money(m); } else { cout<<"输入错误,请重新输入。"<<endl; continue; } savefile(); cout<<"修改成功!"<<endl; system("PAUSE"); break; }}
main.cpp:
#include <fstream>#include <iostream>#include <cstdlib>#include <string>#include "book.h"#include "menu.h"using namespace std;int main(){ int choice; Menu m; while (1) { system("cls"); m.showmenu();//显示开始菜单 cin>>choice; switch(choice) { case 0:cout<<"感谢使用图书管理系统!";exit(1); case 1:m.searchbook(1);break; case 2:m.searchbook(2);break; case 3:m.showall();break; case 4:m.addinfo();break; case 5:m.changeinfo();break; default: cout<<"输入错误,请重新输入。"; } } return 0;}
截图:
软件运行截图:图书数据库信息:
@ Mayuko
2 0
- 课程设计.图书信息管理系统
- 课程设计-图书信息管理系统
- 课程设计(图书信息管理系统)
- 课程设计论文-图书信息管理系统
- 课程设计—图书信息管理系统
- 课程设计---图书信息管理系统设计
- 数据结构课程设计—图书信息管理系统
- 课程设计--图书信息管理系统(C语言)
- 数据结构课程设计——图书信息管理系统设计
- 课程设计:大学生信息管理系统
- 课程设计--学生信息管理系统
- 学生信息管理系统(课程设计)
- 课程设计---学生信息管理系统
- 课程设计--学生信息管理系统
- 课程设计: 学生信息管理系统
- 课程设计--学生信息管理系统
- 课程设计-学生信息管理系统
- 课程设计--学生信息管理系统
- Jquery 获得输入框文件名和后缀名
- linux配置java环境变量
- Android问题集锦转载之一:解决Android requires .class compatibility set to 5.0. Please fix project properties
- c++对象模型function布局
- Cache和Buffer的区别
- 课程设计-图书信息管理系统
- 使用ant进行web打包
- EventBus使用详解(一)初步
- hdu 4099 Revenge of Fibonacci(字典树)
- UEFI规范实现EDKII项目学习笔记绪论[0]
- JavaScript对象和数组
- VB-机房收费系统之Excel导出
- javaScript中Math对象的基本介绍
- Flocker浅析与Docker插件(1)