H大学图书馆
H大学图书馆邀请你建立一个图书馆信息管理系统。请使用面向对象思想完成该问题,具体要求如下:
一、设计一款文字式交互的图书管理系统;
二、图书馆必须支持至少10000册书存储,如果课实现书籍可动态增长,加分
三、图书信息包含:
题名
ISBN/ISSN
作者
分类号(分类规则自定,要求有三级分类,可参考中图分类法)
四、图书馆系统提供两种用户模式,请为他们设计不同的用户类:
1)管理员模式:
系统最初提供一个默认的管理员账户以及默认密码;
管理员具备以下功能:
可以使用管理员账号登录
支持对学校用户的账号进行基本管理,添加、删除学校用户默认账号和密码,默认账号为学号/教师编号,密码为123456;恢复学校用户默认密码;
管理员可以对图书信息进行修改
管理员可以增加、删除、搜索图书
2)学校用户模式(学校用户超过5千人):
学校用户可以通过账号和密码登录,账号为学号/教师编号,密码为123456;
学校用户可以修改自己的密码
学校用户可以搜索图书
学校用户可以借、还图书
学校用户可以查看自己的借阅记录
五、设计图书馆类,包含馆藏图书列表、用户列表等成员、在馆记录、用户借阅记录等。
六、图书馆系统提供根据任一信息的搜索图书功能:
题名,精确查找到书
ISBN/ISSN,精确查找到书
作者,模糊查找到该作者所有书,字典序排序
分类号,三级分类,每一级分类均可模糊查找到书,字典序排序,按页显示;如,N 自然科学总论——TP 自动化技术、计算机技术——TP3 计算机技术。
在以上每一级时,均会出现该级所有数目,字典排序,按页显示;
代码中没有实现的功能的思路:
上下翻页可以借助链表加goto
字典序可以直接利用string的特性来比较汉字可以实现
(该代码中相关功能存在一定瑕疵和问题,仅供参考,此外该代码在vs2019中运行无报错,dev和cb并不能保证可以正常运行)
globalfile.h文件,宏定义文件
#pragma once
#define ADMIN_FILE "admin.txt"
#define READER_FILE "reader.txt"
#define BOOK_FILE "books.txt"
#define LENDMESSAGE_FILE "lendmessage.txt"
user.h文件,用户类(当时图方便,实现文件和头文件放在了一起)
#pragma once
#include <vector>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string.h>
#include "book.h"
#include "globalfile.h"
using namespace std;
struct useru {
string name;
};
//父类,用户类
class user {
public:
virtual void opermenu() = 0;
string code;
string key;
};
//子类,读者类
class reader :public user {
public:
~reader() {
}
static int book_num;
reader();
reader(string code0, string key0);
virtual void opermenu();
void changekey();
void book_lend();
void book_show();
void book_find();
void book_return();
reader* pnext;
};
reader::reader() {
}//无参构造
reader::reader(string code0, string key0) {
this->code = code0;
this->key = key0;
}
int reader::book_num = 0;
class LIST {
private:
reader* phead;
public:
LIST();
reader* gethead1()
{
return phead;}
int getlen1();
int modify1();
int modify2();
int dele1();
void read1();
void save1();
void displayu();
};
LIST::LIST() {
phead = new reader();//创建头节点
phead->pnext = NULL;
}
int LIST::getlen1() {
int n = 0;
reader* r;
r = phead;
while (r) {
n++;
r = r->pnext;
}
return n;
}
void LIST::read1() {
reader* p, * q;
ifstream ifs;
p = this->phead;
ifs.open(READER_FILE, ios::in);
if (!ifs.is_open())
{
cout << "文件不存在!" << endl;
ifs.close();
return;
}
string code1, key1;
while (ifs >> code1 && ifs >> key1) {
q = new reader();
q->code = code1; q->key = key1;
p->pnext = q;
p = q;
}
ifs.close();
}
int LIST::dele1() {
string n;
reader* temp, * pr;
temp = phead;
pr = phead;
cout << "输入要删除的用户的学号或者教职工编号:" << endl;
cin >> n;
while (temp) {
if (temp->code == n) {
//找到该用户后
if (temp == phead) {
//如果该用在头节点
phead = phead->pnext;//直接将头节点下一个节点变成头节点
return 1;
}
pr->pnext = temp->pnext;//若果不是,将pr指向下一个节点的指针直接连到temp的下一个节点,即跳过了temp,temp的数据消失
cout << "删除成功!" << endl;
return 1;
}
pr = temp;//pr为上一个节点
temp = temp->pnext;//temp遍历链表
}
cout << "没有查到要删除的书本!" << endl;
system("pause");
system("cls");
return -1;
}
int LIST::modify1() {
string a, b;
reader* temp;
temp = this->phead;
cout << "请输入你要修改的用户的帐号:" << endl;
cin >> a;
while (temp) {
if (temp->code == a)
{
temp->key = "123456";
}
temp = temp->pnext;
}
system("pause");
system("cls");
return -1;
}
int LIST::modify2() {
string a, b;
reader* temp;
temp = this->phead;
cout << "请输入您的用户的帐号:" << endl;
cin >> a;
cout << "请输入您的原密码:" << endl;
cin >> b;
while (temp) {
if (temp->code == a)
{
if (temp->key == b) {
cout << "请输入您的新密码:" << endl;
string p;
cin >> p;
temp->key = p;
cout << "修改成功!" << endl;
}
else {
cout << "原密码不一致,请重新输入!" << endl;
}
}
temp = temp->pnext;
}
system("pause");
system("cls");
return -1;
}
void LIST::displayu() {
int j = 0;
int k = 0;
reader * temp = phead;
int len = getlen1();
cout << "图书馆注册用户有" << len << "人" << endl;
int page = 0;//总书页
int curpage = 0;//当前页数
if (len % 10 == 0) page = len / 10;
else page = len / 10 + 1;
useru * t1 = new useru[len];
for (int i = 0; i < len; i++) {
t1[i].name = temp->code;
temp = temp->pnext;
}
for (j; j <= len; j++) {
cout << t1[j].name << endl;
if (j % 10 == 0)
{
cout << "总页数:" << page << endl;
cout << "当前页数:" << curpage << endl;
curpage++;
cout << "请在按下任意键后,按1后按回车选择下一页,按2后按回车退出查看图书一览" << endl;
system("pause");
int n = 0;
cin >> n;
if (n == 1)
{
system("cls");
continue;
}
else if (n == 2)
{
system("cls");
break;
}
}
}
system("cls");
}
void LIST::save1() {
reader* r;
ofstream ofs;
r = this->gethead1();
ofs.open(READER_FILE, ios::out);
if (!ofs.is_open())
{
cout << "文件不存在!" << endl;
ofs.close();
return;
}
while (r) {
ofs << r->code << " " << r->key << endl;
r = r->pnext;
}
ofs.close();
}
void reader::opermenu() {
cout << "欢迎读者:" << this->code << "登录!" << endl;
cout << "--------------------------------" << endl;
cout << "-------- 1.修改密码 -----------" << endl;
cout << "-------- 2.借阅书本 ----------" << endl;
cout << "-------- 3.归还书本 ----------" << endl;
cout << "-------- 4.借阅情况 ----------" << endl;
cout << "-------- 5.查找图书 ----------" << endl;
cout << "-------- 6.退出登录 ----------" << endl;
cout << "--------------------------------" << endl;
cout << "请选择您的操作" << endl;
}
void reader::changekey() {
LIST i;
i.read1();
i.modify2();
i.save1();
}
void reader::book_lend() {
cout << "请选择搜索类型" << endl;
cout << "1.搜索书名" << endl;
cout << "2.搜索ISBN号" << endl;
cout << "请输入您的选择:" << endl;
int a = 0;
cin >> a;
List ii;
ii.readp();
list oo;
oo.read();
if (a == 1) {
cout << "请输入书库中存在的书本的书名:" << endl;
string bn;
cin >> bn;
if (ii.find1(bn) != 1 && book_num <= 20) {
ofstream ofs;
ofs.open(LENDMESSAGE_FILE, ios::out | ios::app);
ofs << this->code << " " << bn << " " << oo.getcode(bn) << " " << oo.getauthor(bn) << endl;
cout << "借阅成功!" << endl;
book_num++;
ofs.close();
}
else cout << "该书本已被借阅!" << endl;
}
else if (a == 2) {
cout << "请输入书库中存在的书本的ISBN号:" << endl;
string bc;
cin >> bc;
if (ii.find2(bc) != 1 && book_num <= 20) {
ofstream ofs;
ofs.open(LENDMESSAGE_FILE, ios::out | ios::app);
ofs << this->code << " " << oo.getname(bc) << " " << bc << " " << oo.getauthor(bc) << endl;
cout << "借阅成功!" << endl;
book_num++;
ofs.close</

最低0.47元/天 解锁文章
1007





