C++图书管理系统程序源代码
本文实例为大家分享了C++图书管理系统程序的具体代码,供大家参考,具体内容如下
大一期末c++综合实验,功能基本都实现了,但是代码写的有些繁琐,还有很大的优化空间,仅供参考。
实验要求
实验目的:
1、能够综合运用面向对象程序设计方法,设计实现一个相对完整信息管理应用程序。
2、能够适当进行题目分析、实验设计、核心代码描述、实验结果分析等。
实验:设计并编写一个C++风格应用程序,模拟一个图书管理系统应用程序,支持系统用户的图书借阅、图书管理、用户管理等功能。图书借阅管理主要包括图书借阅、图书归还、借阅信息查看等功能。图书管理主要包括图书的增加、删除、修改、查看、统计等功能。用户管理主要包括用户注册、登录、修改密码、修改个人信息、设置用户类型等功能。
具体要求:
1、定义图书管理系统中的Book书目类(还可以定义User用户类、Log图书借还日志类等)。
2、合理应用类的继承性进行馆藏资源的继承性定义,可分为书、碟片、电子资源等(或将系统用户分为读者、图书管理员、系统管理员)。
3、根据不同类型用户,登录系统显示不同的用户功能菜单,实现不同的操作处理,如学生与教师所借阅书的数量和天数均不相同(或考虑图书馆中多种馆藏资源支持的用户操作有所区别)。
4、增加异常处理,在借阅图书时,已到所能借阅图书数量的最大数量给予提示;归还图书时,图书已超期需要缴纳罚款。
5、通过重载运算符“<<”和“>>”方便图书信息、读者信息录入等操作,并实现将馆藏图书信息、借阅记录等保存到磁盘,形成图书借还日志文件。
6、扩展实验:可尝试使用MFC可视化界面提高用户操作方便性和友好性。
程序源代码
#include#include #include #include //文件输入输出#include //控制输入输出格式#pragma warning(disable:4996)//消除strcpy不安全的错误提示#define kouling2 "654321"using namespace std; class tt{//系统当前时间public:int year; int month; int day; int hours; int minutes; int seconds; tt() {}}; tt system_time()//获取当前时间{tt pp; time_t nowtime; struct tm* p; time(&nowtime); p = localtime(&nowtime); pp.year = p->tm_year + 1900; pp.month = p->tm_mon + 1; pp.day = p->tm_mday; pp.hours = p->tm_hour; pp.minutes = p->tm_min; pp.seconds = p->tm_sec; return pp; }class Log; class Book {//书目类protected:char leixing[50]; //书的类型,分为纸质图书,碟片,电子书int no; //编号char name[50]; //书名char author[50]; //作者char press[50]; //出版社char price[50]; //价格int state; //图书是否在架,1为在架,0为借出public:Book(){}friend Log; void set_name(char a[])//设置书名{strcpy(name, a); }void set_author(char a[])//设置作者{strcpy(author, a); }void set_press(char a[])//设置出版社{strcpy(press, a); }void set_price(char a[])//设置价格{strcpy(price, a); }void set_no(int a)//设置编号{no = a; }void set_state(int a)//设置图书状态{state = a; }char *get_name()//获取书名{return name; }char *get_author()//获取作者{return author; }char* get_press()//获取出版社{return press; }char* get_price()//获取价格{return price; }int get_no()//获取编号{return no; }int get_state()//获取图书状态{return state; }int chongfu_no(int no1)//判断编号是否重复,返回1为重复,0为不重复{char leixing[100][50]; //图书类型int x[100]; //图书编号char c[100][50]; //图书书名char d[100][50]; //图书作者char e[100][50]; //图书出版社char f[100][20]; //价格int yy[100]; //状态int i; fstream in; in.open("Book.text", ios::in); for (i = 0; ; i++){if (in.eof())//判断是否到文件末尾{break; }in >> leixing[i] >> x[i] >> c[i] >> d[i] >> e[i] >> f[i] >> yy[i]; //读入图书信息if (no1 == x[i])//编号已存在{cout << "增加图书失败,该编号已存在!" << endl; return 1; }}in.close(); return 0; }}; class User {//用户类protected:char name[20]; //用户名char password[20]; //密码public:User(){}friend Log; void set_name(char a[])//设置用户名{strcpy(name, a); }void set_password(char a[])//设置密码{strcpy(password, a); }int chongfu_name(char a[])//检查用户名是否已存在,返回1为已存在{int i; int num = 0; //已注册的用户量char d[100][50]; //已注册的用户类型char e[100][50]; //已注册的用户名char f[100][50]; //已注册的密码fstream in; in.open("User.text", ios::in); for (i = 0; ; i++){if (in.eof())//判断是否到文件末尾{num--; break; }in >> d[i]; in >> e[i]; in >> f[i]; num++; }in.close(); for (i = 0; i > d[i]; in >> e[i]; in >> f[i]; if (strcmp(e[i], name) == 0)//找到要修改的用户{if (n == 1){memset(name, '\0', sizeof(name)); //清空数组strcpy(name, a); memset(e[i], '\0', sizeof(e[i])); //清空数组strcpy(e[i], a); }if (n == 2){memset(password, '\0', sizeof(password)); //清空数组strcpy(password, a); memset(f[i], '\0', sizeof(f[i])); //清空数组strcpy(f[i], a); }}num++; }in.close(); fstream out; out.open("User.text", ios::out|ios::trunc); for (i = 0; i > d[i]; in >> e[i]; in >> f[i]; num++; }in.close(); int flag = 0; //0为登录失败,1为登录成功char a[20]; //登录用户名char b[20]; //登录密码cout << "请输入用户名:" << endl; cin >> a; cout << "请输入密码:" << endl; cin >> b; for (i = 0; i < num; i++){if (strcmp(p,d[i])==0&&strcmp(a, e[i]) == 0 && strcmp(b, f[i]) == 0)//登录成功{flag = 1; break; }}if (flag == 1)//登录成功{cout << "您好!尊敬的"<> d[i]; in >> e[i]; in >> f[i]; num++; }in.close(); char a[20]; //所要注册的用户名cout << "请输入用户名:" << endl; int flag = 1; //0为用户名已注册,1为未注册for (; ; )//输入用户名{char aa[20]; //暂时存储所要注册的用户名cin >> aa; for (i = 0; i < num; i++)//判断用户名是否已注册{if (strcmp(e[i], aa) == 0)//用户名已被注册{cout << "该用户名已存在,请重新输入:" << endl; flag = 0; break; }else{flag = 1; }}if (flag == 1)//用户名未被注册{strcpy(a, aa); break; }}for (; ; ){char b[20]; //密码char c[20]; //第二次输入的密码cout << "请设置密码:" << endl; cin >> b; cout << "请再次输入密码:" << endl; cin >> c; if (strcmp(b, c) == 0)//两次密码输入一致{cout << "注册成功!" << endl; set_name(a); set_password(b); fstream out; out.open("User.text", ios::app); out <> d[i]; in >> e[i]; in >> f[i]; num++; }in.close(); char a[20]; //所要注册的用户名cout << "请输入用户名:" << endl; int flag = 1; //0为用户名已注册,1为未注册for (; ; )//输入用户名{char aa[20]; //暂时存储所要注册的用户名cin >> aa; for (i = 0; i < num; i++)//判断用户名是否已注册{if (strcmp(e[i], aa) == 0){cout << "该用户名已存在,请重新输入:" << endl; flag = 0; break; }else{flag = 1; }}if (flag == 1){strcpy(a, aa); break; }}for (; ; ){char b[20]; //密码char c[20]; //第二次输入的密码cout << "请设置密码:" << endl; cin >> b; cout << "请再次输入密码:" << endl; cin >> c; if (strcmp(b, c) == 0){cout << "注册成功!" << endl; set_name(a); set_password(b); fstream out; out.open("User.text", ios::app); out << setiosflags(ios::left) << setw(14) << "图书管理员" << setw(20) << a << setw(20) << b << endl; out.close(); break; }else{cout << "两次密码不一致,请重新输入" << endl; }}}void add_book(int no1, char name1[], char author1[], char press1[], char price1[],int y)//增加图书{fstream out; out.open("Book.text", ios::app); if (y == 1)//纸质图书out << "纸质图书"; if (y == 2)//碟片out << "碟片"; if (y == 3)//电子书out << "电子书"; out << setiosflags(ios::left) << setw(15) << no1 << setw(20) << name1 << setw(20) << author1 << setw(20) << press1 << setw(20) << price1 <> leixing[i] >> x[i] >> c[i] >> d[i] >> e[i] >> f[i] >> y[i]; num++; //}in.close(); fstream out; out.open("Book.text", ios::out); for (i = 0; i < num; i++)//将删除图书后的的图书信息写入文件{if (x[i] != n)out << setiosflags(ios::left) << setw(20) << leixing[i] << setw(15) << x[i] << setw(20) << c[i] << setw(20) << d[i] << setw(20) << e[i] << setw(20) << f[i] << setw(5) << y[i] << endl; //最后一个左对齐能否去掉elseflag = 1; }out.close(); if(flag==1)cout << "删除成功!" << endl; if (flag == 0)cout << "删除失败,未查找到该书!" << endl; }void change_book(int n)//修改图书信息{int i; int num = 0; char leixing[100][50]; //图书类型int x[100]; //图书编号char c[100][50]; //图书书名char d[100][50]; //图书作者char e[100][50]; //图书出版社char f[100][20]; //价格int y[100]; //状态fstream in; in.open("Book.text", ios::in); for (i = 0; ; i++){if (in.eof()){num--; //break; }in >> leixing[i] >> x[i] >> c[i] >> d[i] >> e[i] >> f[i] >> y[i]; num++; //}in.close(); for (i = 0; i < num; i++){if (n == x[i])//找到要修改的图书{memset(leixing[i], '\0', sizeof(leixing[i])); x[i] = 0; memset(c[i], '\0', sizeof(c[i])); memset(d[i], '\0', sizeof(d[i])); memset(e[i], '\0', sizeof(e[i])); memset(f[i], '\0', sizeof(f[i])); y[i] = 0; cout << "请输入修改后的图书类型:" << endl; cin >> leixing[i]; cout << "请输入修改后的图书编号:" << endl; cin >> x[i]; cout << "请输入修改后的图书书名:" << endl; cin >> c[i]; cout << "请输入修改后的图书作者:" << endl; cin >> d[i]; cout << "请输入修改后的图书出版社:" << endl; cin >> e[i]; cout << "请输入修改后的图书价格:" << endl; cin >> f[i]; cout << "请输入修改后的图书状态:(1为在架,0为已借出)" << endl; cin >> y[i]; cout << "修改成功!" << endl; break; }}if (i == num)//未查找到图书cout << "抱歉,未查到此书!" << endl; fstream out; out.open("Book.text", ios::out); for (i = 0; i < num; i++)//将修改后的图书信息写入文件{out << setiosflags(ios::left) << setw(20) << leixing[i] << setw(15) << x[i] << setw(20) << c[i] << setw(20) << d[i]; out<< setw(20) << e[i]<< setw(20) << f[i] << setw(5) << y[i] << endl; }out.close(); }void see_all()//查看所有用户的借阅信息{int i; int num = 0; char a[100][20]; //图书类型char b[100][20]; //编号char c[100][20]; //书名char d[100][20]; //作者char e[100][20]; //出版社char f[100][20]; //价格char people[100][20]; //借书人tt p; //借书时间fstream out2; out2.open("Log.text", ios::in); for (i = 0; ; i++){if (out2.eof())//判断是否到文件末尾{num--; break; }out2 >> a[i] >> b[i] >> c[i] >> d[i] >> e[i] >> f[i]; out2 >> people[i]; out2 >> p.year >> p.month >> p.day >> p.hours >> p.minutes >> p.seconds; num++; }out2.close(); cout << "以下为所有用户借阅信息:" << endl; for (i = 0; i < num; i++){cout << a[i] << "" << b[i] << "" << c[i] << "" << d[i] << "" << e[i] << "" << f[i] << "" <<"借阅人:"<> d[i]; in >> e[i]; in >> f[i]; num++; }in.close(); char a[20]; //所要注册的用户名cout << "请输入用户名:" << endl; int flag = 1; //0为用户名已注册,1为未注册for (; ; )//输入用户名{char aa[20]; //暂时存储所要注册的用户名cin >> aa; for (i = 0; i < num; i++)//判断用户名是否已注册{if (strcmp(e[i], aa) == 0){cout << "该用户名已存在,请重新输入:" << endl; flag = 0; break; }else{flag = 1; }}if (flag == 1){strcpy(a, aa); break; }}for (; ; ){char b[20]; //密码char c[20]; //第二次输入的密码cout << "请设置密码:" << endl; cin >> b; cout << "请再次输入密码:" << endl; cin >> c; if (strcmp(b, c) == 0){cout << "注册成功!" << endl; set_name(a); set_password(b); fstream out; out.open("User.text", ios::app); out << setiosflags(ios::left) << setw(14) << "系统管理员" << setw(20) << a << setw(20) << b << endl; out.close(); break; }else{cout << "两次密码不一致,请重新输入" << endl; }}}void add_User(char name[],char password[],int y)//增加用户{if (chongfu_name(name) == 1)//用户名已注册cout << "增加用户失败,该用户名已存在!" << endl; if (chongfu_name(name) == 0)//用户名未注册{fstream out; out.open("User.text", ios::app); if (y == 1)out << setiosflags(ios::left) << setw(18) << "读者" << setw(20) << name << setw(20) << password << endl; if (y == 2)out << setiosflags(ios::left) << setw(14) << "图书管理员" << setw(20) << name << setw(20) << password << endl; out.close(); cout << "增加成功!" << endl; }}void delete_user(char name[])//删除用户{int i; int num = 0; //已注册的用户量char d[100][50]; //已注册的用户类型char e[100][50]; //已注册的用户名char f[100][50]; //已注册的密码int del; //要删除的用户的序号fstream in; in.open("User.text", ios::in); for (i = 0; ; i++){if (in.eof())//判断是否到文件末尾{num--; break; }in >> d[i]; in >> e[i]; in >> f[i]; num++; }in.close(); for (i = 0; i > d[i]; in >> e[i]; in >> f[i]; num++; }in.close(); if (y == 1)//修改用户类型{for (i = 0; i > name1; if (chongfu_name(name1) == 1)//用户名已存在cout << "该用户名已存在,请重新输入" << endl; else{strcpy(name2, name1); break; }}for (i = 0; ; i++){if (strcmp(name, e[i]) == 0)//找到要修改的用户{memset(e[i], '\0', sizeof(e[i])); //清空用户名strcpy(e[i], name2); break; }}}if (y == 3)//修改密码{char password2[50]; cout << "请输入修改后的密码:" << endl; cin >> password2; for (i = 0; ; i++){if (strcmp(name, e[i]) == 0){memset(f[i], '\0', sizeof(f[i])); strcpy(f[i], password2); break; }}}fstream out; out.open("User.text", ios::out); for (i = 0; i > d[i]; in >> e[i]; in >> f[i]; num++; }in.close(); cout << "——————————用户信息——————————" << endl; for (i = 0; i < num; i++){cout <<"用户类型:"< > a[i] >> b[i] >> c[i] >> d[i] >> e[i] >> f[i]; in >> people[i]; in >> p.year >> p.month >> p.day >> p.hours >> p.minutes >> p.seconds; num++; }in.close(); int flag=0; //0为没有借书,1为有借书cout << "以下为您的借阅信息:" << endl; for (i = 0; i < num; i++){if (strcmp(people[i],yonghu.name) == 0)//检索到借阅人{cout << a[i] << "" << b[i] << "" << c[i] << "" << d[i] << "" << e[i] << "" << f[i] << "" << p.year << "年" << p.month << "月" << p.day << "日" << p.hours << ":" << p.minutes << endl; flag = 1; }}if (flag==0)cout << "无" << endl; }void lend_book(User yonghu)//借阅图书{int i; char a[50]; //书名char b[50]; //作者int num = 0; //书的数目int x[100]; //在架的图书编号char leixing[100][50]; //图书类型char c[100][50]; //在架的图书书名char d[100][50]; //在架的图书作者char e[100][50]; //在架的图书出版社char f[100][20]; //价格int y[100]; //状态cout << "请输入您要借阅的图书书名:" << endl; cin >> a; cout << "请输入您要借阅的图书作者:" << endl; cin >> b; fstream in; in.open("Book.text", ios::in); for (i = 0; ; i++)//找要借阅的书{if (in.eof()){num--; break; }in >> leixing[i] >> x[i] >> c[i] >> d[i] >> e[i] >> f[i] >> y[i]; num++; }in.close(); cout << "查询到以下图书:" << endl; int flag = 0; //0为未查到书,1为查到书for (i = 0; i < num; i++){if (strcmp(a, c[i]) == 0 && strcmp(b, d[i]) == 0){cout << "" << leixing[i] << "编号:" << x[i] << "" << c[i] << "" << d[i] << "" << e[i] << "" << f[i] << ""; if (y[i] == 1)cout << "在架可借" << endl; if (y[i] == 0)cout << "已借出" << endl; flag = 1; }}if (flag == 0)//未检索到书{cout << "无" << endl; cout << "未查询到此书!" << endl; }if (flag == 1)//检索到书{int flag2=1; //0借阅失败,1为借阅成功int bianhao; cout << "请输入您要借阅的图书编号:" << endl; cin >> bianhao; for (i = 0; i < num; i++){if (bianhao == x[i]&&y[i]==1)//找到书且书可借{y[i]=0; break; }if (bianhao == x[i] && y[i] == 0)//找到书且书已借出{cout << "无法借阅,该书已被借出!" << endl; flag2 = 0; break; }}if (i == num)//未检索到图书{flag2 = 0; cout << "未查询到该图书!" << endl; }if(flag2==1)//借阅成功{fstream out; out.open("Book.text", ios::out); for (i = 0; i < num; i++)out << setiosflags(ios::left) << setw(15) << leixing[i] << setw(15) << x[i] << setw(20) << c[i] << setw(20) << d[i] << setw(20) << e[i] << setw(20) << f[i] << setw(5) << y[i] << endl; out.close(); tt p; p = system_time(); //p存储了当前系统时间fstream out2; out2.open("Log.text", ios::app); for (i = 0; i < num; i++){if (bianhao == x[i]){out2 << setiosflags(ios::left) << setw(15) << leixing[i] << setw(15) << x[i] << setw(20) << c[i] << setw(20) << d[i] << setw(20) << e[i] << setw(20) << f[i]; out2 << yonghu.name << ""; out2 << p.year << " " << p.month << " " << p.day << " " << p.hours << " " << p.minutes << " " << p.seconds << endl; break; }}out2.close(); cout << "借阅成功!" << endl; }}}void return_book(int n,User yonghu)//n:1为读者,2为图书管理员,3为系统管理员{int i; int num = 0; //图书数量int x[100]; //图书编号char leixing[100][50]; //图书类型char c[100][50]; //图书书名char d[100][50]; //图书作者char e[100][50]; //图书出版社char f[100][20]; //价格int y[100]; //状态fstream in; in.open("Book.text", ios::in); for (i = 0; ; i++)//找要还的书{if (in.eof()){num--; //break; }in >> leixing[i] >> x[i] >> c[i] >> d[i] >> e[i] >> f[i] >> y[i]; num++; //}in.close(); see(yonghu); //输出该用户借阅图书信息int bianhao; cout << "请输入您要返还图书的编号:" << endl; cin >> bianhao; for (i = 0; i < num; i++)//改变图书状态{if (bianhao == x[i])//找到图书{y[i] = 1; //改变图书状态为在架可借break; }}if (i == num)//未查询到图书{cout << "未查询到该图书!" << endl; }else//查询到图书{fstream out; out.open("Book.text", ios::out); for (i = 0; i < num; i++)//更新book文件{out << setiosflags(ios::left) << setw(15) << leixing[i] << setw(15) << x[i] << setw(20) << c[i]; out << setw(20) << d[i] << setw(20) << e[i] << setw(20) << f[i] << setw(5) << y[i] << endl; }out.close(); //更改Log.textint x2[100]; //已借阅的的图书编号char leixing2[100][50]; //已借阅图书的图书类型char c2[100][50]; //已借阅图书的图书书名char d2[100][50]; //已借阅图书的图书作者char e2[100][50]; //已借阅图书的图书出版社char f2[100][50]; //已借阅图书的价格char person[50]; //借书者用户名tt time1[100]; //借书时间tt time2 = system_time(); //还书时间int log_num = 0; fstream in2; in2.open("Log.text", ios::in); for (i = 0; ; i++){if (in2.eof()){log_num--; break; }in2 >> leixing2[i] >> x2[i] >> c2[i] >> d2[i] >> e2[i] >> f2[i] >> person; in2>> time1[i].year >> time1[i].month >> time1[i].day >> time1[i].hours >> time1[i].minutes >> time1[i].seconds; log_num++; //}in2.close(); int del; //还的书的序号for (i = 0; i < log_num; i++){if (bianhao == x2[i]){del = i; break; }}fstream out2; out2.open("Log.text", ios::out); for (i = 0; i < log_num; i++)//向文件输出新的Log{if (i == del)continue; out2 << setiosflags(ios::left) << setw(15) << leixing2[i] << setw(15) << x2[i]; out2<< setw(20) << c2[i] << setw(20) << d2[i] << setw(20) << e2[i] << setw(20) << f2[i]; out2 << yonghu.name << ""; out2 << time1[i].year << " " << time1[i].month << " " << time1[i].day << " "; out2<< time1[i].hours << " " << time1[i].minutes << " " << time1[i].seconds << endl; }out2.close(); //判断是否超出还书时间int deadline; if (n == 1)//读者deadline = 14; //读者借书期限为14天if (n == 2 || n == 3)//图书管理员或系统管理员deadline = 21; //管理员借书期限为21天if (time2.year - time1[del].year > 0 || time2.month - time1[del].month > 0 || time2.day - time1[del].day > deadline){cout << "您已超出图书归还日期,请到办公室缴纳罚款" << endl; }elsecout << "还书成功!" << endl; }}}; int main(){char kouling1[50] = "123456"; cout << "——————图书管理系统——————" << endl; int i,j; Book shu[100]; //图书Reader duzhe[100]; //读者Librarian tushu[100]; //图书管理员System_Admin xitong[100]; //系统管理员Log rizhi[100]; //借还书日志int flag; //0为没有用户登录,1为已有用户登录for (i = 0; ; i++){if(i!=0)cout << "————主界面————" << endl; cout << "1.注册" << endl; cout << "2.登录" << endl; cout << "3.退出" << endl; int n; //1为注册,2为登录,3为退出系统cin >> n; if (n == 1)//注册{cout << "请选择您要注册的用户类型" << endl; cout << "1.读者" << endl; cout << "2.图书管理员" << endl; cout << "3.系统管理员" << endl; cout << "4.返回上一层菜单" << endl; int m; //1为注册读者,2为注册图书管理员,3为注册系统管理员cin >> m; if (m == 1){duzhe[i].zhuce(); //注册读者}if (m == 2){for (; ; ){char kl[20]; //图书管理员口令cout << "请输入图书管理员口令:" << endl; cin >> kl; //接收口令if (strcmp(kl,kouling1) == 0){tushu[i].zhuce(); //注册图书管理员break; }else{cout << "口令错误,请输入正确口令!" << endl; }}}if (m == 3){for (; ; ){char k2[20]; //系统管理员口令cout << "请输入系统管理员口令:" << endl; cin >> k2; //接收口令if (strcmp(k2, kouling2) == 0){xitong[i].zhuce(); //注册系统管理员break; }else{cout << "口令错误,请输入正确口令!" << endl; }}}if (m == 4){continue; }}if (n == 2)//登录界面{cout << "请选择您要登录的用户类型" << endl; cout << "1.读者" << endl; cout << "2.图书管理员" << endl; cout << "3.系统管理员" << endl; cout << "4.返回上一层菜单" << endl; int m; cin >> m; if (m == 1){flag=duzhe[i].denglu("读者"); }if (m == 2){flag=tushu[i].denglu("图书管理员"); }if (m == 3){flag=xitong[i].denglu("系统管理员"); }if (m == 4)continue; if (flag == 1)//登录成功{if (m == 1)//读者登录{for (; ; ){int x; cout << "————读者界面————" << endl; cout << "1.修改用户名" << endl; cout << "2.修改密码" << endl; cout << "3.借阅图书" << endl; cout << "4.还书" << endl; cout << "5.本人借阅信息查看" << endl; cout << "6.退出账号" << endl; cin >> x; if (x == 1){char after_name[20]; //改后的用户名cout << "请输入新的用户名:" << endl; cin >> after_name; duzhe[i].change_information(after_name,1); }if (x == 2){char after_password[20]; //改后的密码cout << "请输入新的密码" << endl; cin >> after_password; duzhe[i].change_information(after_password,2); }if (x == 3){rizhi[i].lend_book(duzhe[i]); }if (x == 4){rizhi[i].return_book(1,duzhe[i]); }if (x == 5)rizhi[i].see(duzhe[i]); if (x == 6)break; }}if (m == 2)//登录的为图书管理员{for (; ; ){int x; cout << "————图书管理员界面————" << endl; cout << "1.修改用户名" << endl; cout << "2.修改密码" << endl; cout << "3.借阅图书" << endl; cout << "4.还书" << endl; cout << "5.本人借阅信息查看" << endl; cout << "6.增加图书" << endl; cout << "7.修改图书信息" << endl; cout << "8.删除图书" << endl; cout << "9.查看用户借阅信息" << endl; cout << "10.退出账号" << endl; cin >> x; if (x == 1){char after_name[20]; //改后的用户名cout << "请输入新的用户名:" << endl; cin >> after_name; tushu[i].change_information(after_name, 1); }if (x == 2){char after_password[20]; //改后的密码cout << "请输入新的密码" << endl; cin >> after_password; tushu[i].change_information(after_password, 2); }if (x == 3){rizhi[i].lend_book(tushu[i]); }if (x == 4){rizhi[i].return_book(2, tushu[i]); }if (x == 5)rizhi[i].see(tushu[i]); if (x == 6){int y; //1为纸质图书,2为碟片,3为电子资源int no1; //编号char name1[20]; //书名char author1[20]; //作者char press1[20]; //出版社char price1[10]; //价格cout << "请输入您要增加的图书类型:" << endl; cout << "1.纸质图书" << endl; cout << "2.碟片" << endl; cout << "3.电子资源" << endl; cin >> y; cout << "请输入图书编号:" << endl; cin >> no1; if (shu[i].chongfu_no(no1) == 1)continue; cout << "请输入书名:" << endl; cin >> name1; cout << "请输入作者:" << endl; cin >> author1; cout << "请输入出版社:" << endl; cin >> press1; cout << "请输入图书价格" << endl; cin >> price1; if (y == 1)tushu[i].add_book(no1, name1, author1, press1, price1, 1); if (y == 2)tushu[i].add_book(no1, name1, author1, press1, price1, 2); if (y == 3)tushu[i].add_book(no1, name1, author1, press1, price1, 3); }if (x == 7){int y; cout << "请输入您要修改图书的编号:" << endl; cin >> y; tushu[i].change_book(y); }if (x == 8){int y; cout << "请输入您要删除图书的编号:" << endl; cin >> y; tushu[i].delete_book(y); }if (x == 9){tushu[i].see_all(); }if (x == 10)break; }}if (m == 3)//登录的为系统管理员{for (; ; ){int x; cout << "————系统管理员界面————" << endl; cout << "1.修改用户名" << endl; cout << "2.修改密码" << endl; cout << "3.借阅图书" << endl; cout << "4.还书" << endl; cout << "5.本人借阅信息查看" << endl; cout << "6.修改图书管理员口令" << endl; cout << "7.增加用户" << endl; cout << "8.删除用户" << endl; cout << "9.修改用户信息" << endl; cout << "10.查看用户信息" << endl; cout << "11.退出账号" << endl; cin >> x; if (x == 1){char after_name[20]; //改后的用户名cout << "请输入新的用户名:" << endl; cin >> after_name; xitong[i].change_information(after_name, 1); }if (x == 2){char after_password[20]; //改后的密码cout << "请输入新的密码" << endl; cin >> after_password; xitong[i].change_information(after_password, 2); }if (x == 3){rizhi[i].lend_book(xitong[i]); }if (x == 4){rizhi[i].return_book(3,xitong[i]); }if (x == 5){rizhi[i].see(xitong[i]); }if (x == 6){char kouling3[50]; cout << "请输入修改后的图书管理员口令:" << endl; cin >> kouling3; memset(kouling1, '\0', sizeof(kouling1)); strcmp(kouling1, kouling3); }if (x == 7){int y; //1为读者,2为图书管理员char name[50]; char password[50]; cout << "请输入您要增加的用户类型:" << endl; cout << "1.读者" << endl; cout << "2.图书管理员" << endl; cin >> y; cout << "请输入用户名:" << endl; cin >> name; cout << "请输入密码:" << endl; cin >> password; xitong[i].add_User(name,password,y); }if (x == 8){char name[50]; cout << "请输入您要删除用户的用户名:" << endl; cin >> name; xitong[i].delete_user(name); }if (x == 9){char name[50]; cout << "请输入您要修改用户的用户名:" << endl; cin >> name; int y; cout << "请输入您要修改用户的哪个信息:" << endl; cout << "1.用户类型" << endl; cout << "2.用户名" << endl; cout << "3.用户密码" << endl; cin >> y; xitong[i].change_user(name,y); }if (x == 10){xitong[i].see_user(); }if (x == 11){break; }}}}}if (n == 3)return 0; }return 0; }
实验结果展示
文章图片
文章图片
注册成功后用户信息会写入文件中,这样关闭程序后用户信息不会丢失
用户信息
文章图片
文章图片
【C++图书管理系统程序源代码】三个text文件分别保存书籍信息(Book)、借阅信息(Log)、用户信息(User)
书籍信息
文章图片
借阅信息
文章图片
文章图片
文章图片
文章图片
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
推荐阅读
- C++版图书管理系统
- C++项目开发实现图书管理系统
- C++基础知识|C++(char型总结一些细节知识点)
- C++|c++中string的模拟实现
- C/C++|C++中简单的string类的实现
- c++|c++的string类的模拟实现 以及basic_string::_M_construct null not valid错误的原因
- C++|[C/C++]详解STL容器1--string的功能和模拟实现(深浅拷贝问题)
- 蓝桥杯真题(C/C++)|题目 1575: 递归倒置字符数组
- c++|模拟实现string类
- C++实现图书馆管理系统