C++实现图书管理系统
闲来无事,用C++做了一个图书管理系统,主要有借书、还书、图书管理、用户管理等功能,主要用到的技术有容器和文件,以及类的封装
成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站制作、成都网站建设、外贸营销网站建设、海晏网络推广、小程序定制开发、海晏网络营销、海晏企业策划、海晏品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联为所有大学生创业者提供海晏建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.com
#include#include #include
#include #include #include using namespace std; class Mybook; class Book; class Book{ public: int id; //书号 char book_name[20]; //书名 int state; //图书状态 char place[20]; //图书所在位置 char stu_number[20]; //学号 char stu_name[20]; //学生姓名 public: Book(); friend class Mybook; }; class User{ public: char stu_number[20]; //学号 char stu_name[20]; //学生姓名 public: User() { strcpy(stu_number,"000"); strcpy(stu_name,"0"); } friend class Mybook; }; class Mybook{ private: list link_book; //保存书本信息 list link_user; //保存用户信息 public: int main_menu(); //主菜单 void getmenu(); //获取菜单 int menu(); //图书管理菜单 void getchoice(); //输入选择 void add_book(); //添加图书 void display_book(); //显示图书信息 void del_book(); //删除图书信息 void search_book(); //搜索图书信息 void update_book(); //修改图书信息 void borrow_book(); //借书 void return_book(); //还书 int menu_user(); //管理用户菜单 void add_user(); //添加用户 void del_user(); //删除用户 void display_user(); //查看用户 void update_user(); //修改用户 void look_borrow(); //查看借阅图书情况 void get_user(); //用户管理 void recv_file(); //将数据保存到文件中 void read_file(); //将数据从文件中读取 void recv_user(); //将用户信息保存到文件 void read_user(); //将用户信息从文件读取 }; Book::Book() { state = 0; strcpy(stu_number,"000"); strcpy(stu_name,"0"); } //保存图书信息到文件 void Mybook::recv_file() { ofstream outfile("library.txt",ios::out); if(!outfile) { cout<<"文件打开失败"< ::iterator p = link_book.begin(); while(p != link_book.end()) { outfile< id< book_name< state< place< stu_number< stu_name< ::iterator p = link_user.begin(); while(p != link_user.end()) { outfile< stu_number< stu_name< >choice; while(!(choice >= 0 && choice <= 4)) { cout<<"输入错误,请重新输入:"; cin>>choice; } return choice; } //执行主菜单 void Mybook::getmenu() { int choice = 0; read_user(); read_file(); while(1) { system("clear"); choice = main_menu(); switch(choice) { case 1: { borrow_book(); break; } case 2: { return_book(); break; } case 3: { getchoice(); break; } case 4: { get_user(); break; } case 0: { cout<<"正在保存,请稍后....."< >id; list ::iterator it = link_user.begin(); while(it != link_user.end()) { if(strcmp(it->stu_number,id) == 0) { strcpy(name,it->stu_name); flag2 = 1; break; } it++; } if(flag2 == 0) { cout<<"你没有借书权限!借书失败"< >book_name; list ::iterator p = link_book.begin(); while(p != link_book.end()) { if(strcmp(p->book_name,book_name) == 0) { cout<<"======================================="< id< book_name< state == 0) { cout<<"图书状态:未借阅!"< place< >book_id; while(p != link_book.end()) { if(strcmp(p->book_name,book_name) == 0 && p->id == book_id && p->state == 0) { strcpy(p->stu_number,id); strcpy(p->stu_name,name); p->state = 1; cout<<"借书成功!"< >stu_id; int flag = 0; int flag1 = 0; list ::iterator p = link_book.begin(); while(p != link_book.end()) { if(strcmp(p->stu_number,stu_id) == 0) { cout<<"==========================================="< id< book_name< >id; p = link_book.begin(); while(p != link_book.end()) { if(strcmp(p->stu_number,stu_id) == 0&&p->id == id) { strcpy(p->stu_name ,"000"); strcpy(p->stu_number , "0"); p->state = 0; cout<<"还书成功!"< >choice; while(!(choice >= 1 && choice <= 6)) { cout<<"输入错误,请重新输入:"; cin>>choice; } return choice; } //执行用户管理 void Mybook::get_user() { int choice = 0; while(1) { system("clear"); choice = menu_user(); system("clear"); switch(choice) { case 1: { add_user(); break; } case 2: { display_user(); break; } case 3: { del_user(); break; } case 4: { update_user(); break; } case 5: { look_borrow(); break; } case 6: { recv_user(); return ; } } cout< >new_user.stu_number; cout<<"请输入姓名:"; cin>>new_user.stu_name; link_user.push_back(new_user); cout<<"添加成功!"; cout<<"是否继续添加(y/n)"; char ch; cin>>ch; while(!(ch == 'Y'||ch == 'y'||ch == 'N'||ch == 'n')) { cout<<"输入有误,请重新输入:"; cin>>ch; } if(ch == 'Y'||ch == 'y') { system("clear"); add_user(); } } //显示用户 void Mybook::display_user() { list ::iterator it = link_user.begin(); while(it != link_user.end()) { cout<<"====================================="< stu_number< stu_name< >id; int flag = 0; list ::iterator it = link_user.begin(); while(it != link_user.end()) { if(strcmp(it->stu_number,id) == 0) { link_user.erase(it); flag = 1; break; } it++; } if(flag == 1) { cout<<"删除成功!"< >number; int flag = 0; list ::iterator it = link_user.begin(); while(it != link_user.end()) { if(strcmp(it->stu_number,number) == 0) { cout<<"请更新学号:"; cin>>it->stu_number; cout<<"请更新姓名:"; cin>>it->stu_name; flag = 1; break; } it++; } if(flag == 1) { cout<<"修改成功!"< ::iterator p = link_book.begin(); while(p != link_book.end()) { if(p->state == 1) { cout<<"==================================================="< stu_name< stu_number< book_name< place< >choice; while(!(choice >= 1 && choice <= 6)) { cout<<"输入错误,请重新输入:"; cin>>choice; } return choice; } //实行图书管理 void Mybook::getchoice() { int choice = 0; while(1) { system("clear"); choice = menu(); system("clear"); switch(choice) { case 1: { add_book(); break; } case 2: { display_book(); break; } case 3: { del_book(); break; } case 4: { search_book(); break; } case 5: { update_book(); break; } case 6: { return ; } } cout< >new_book.id; cout<<"请输入书名:"; cin>>new_book.book_name; cout<<"请输入图书书架:"; cin>>new_book.place; link_book.push_back(new_book); cout<<"添加成功!"; cout<<"是否继续添加(y/n)"; char ch; cin>>ch; while(!(ch == 'Y'||ch == 'y'||ch == 'N'||ch == 'n')) { cout<<"输入有误,请重新输入:"; cin>>ch; } if(ch == 'Y'||ch == 'y') { system("clear"); add_book(); } } //显示书本信息 void Mybook::display_book() { list ::iterator p = link_book.begin(); while(p != link_book.end()) { cout<<"======================================="< id< book_name< state == 0) { cout<<"图书状态:未借阅!"< place< ::iterator p = link_book.begin(); int num = 0; int flag = 0; cout<<"请输入你要删除的书号:"; cin>>num; while(p != link_book.end()) { if(p->id == num) { link_book.erase(p); flag = 1; break; } p++; } if(flag == 1) { cout<<"\n\n删除完成!"; } else { cout<<"\n\n该书不存在,删除失败!"< ::iterator p = link_book.begin(); char book_name[20]; int flag = 0; cout<<"请输入你要查找的书名:"; cin>>book_name; while(p != link_book.end()) { if(strcmp(p->book_name,book_name) == 0) { cout<<"======================================="< id< book_name< state == 0) { cout<<"图书状态:未借阅!"< place< ::iterator p = link_book.begin(); int num = 0; int flag = 0; cout<<"请输入你要更新的书号:"; cin>>num; while(p != link_book.end()) { if(p->id == num) { cout<<"请输入书名"; cin>>p->book_name; cout<<"请输入图书书架号:"; cin>>p->place; flag = 1; } p++; } if(flag == 1) { cout<<"\n\n更新完成!"; } else { cout<<"\n\n该书不存在,更新失败!"<
更多学习资料请关注专题《管理系统开发》。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。
文章标题:C++实现图书管理系统
地址分享:http://hbruida.cn/article/jgphco.html