C++图书管理基本业务模拟,数据结构课程设计(含源码、报告)

数据结构课程设计

题目:图书管理基本业务模拟

目 录

一、实验概述
1.1 实验题目
1.2 基本要求
1.3 问题描述

二、详细设计
2.1 数据结构的设计
2.1.1 图书信息的存入
2.1.2 学生信息存入
2.2 算法的设计思想及流程图
2.2.1 主要函数的功能说明
2.3.1 程序总流程图
2.3.2 管理员的图书管理模块流程
2.3.3 图书查询模块

三、主要程序分析

四、程序运行结果
4.1 读者界面与管理员界面
4.2 显示所有图书信息界面
4.3 图书借阅界面

一、实验概述

1.1 实验题目
图书管理基本业务模拟
1.2 基本要求
(1)书的登记内容包括书号、书名、著作者、现存量和库存量等;学生信息包括借书证号、借阅信息等;
(2)以书号建立索引表(线性表)以提高查找效率;
(3)主要功能如下:
采编入库:新购一种书,确定书号后,登记到图书帐目表中,如果表中已有,则只将库存量增加;
借阅:如果一种书的现存量大于0,则借出一本,登记借阅者的书号和归还期限,改变现存量;
归还:注销对借阅者的登记,改变该书的现存量。
(4)输出形式:
能按书号、书名、著作者查找库存的书籍信息
能按学生的借书证号显示学生信息和借阅信息
书籍入库
借书功能实现
还书功能实现
1.3 问题描述
图书管理一般包括图书采编、图书编目、图书查询及图书流通(借、还书)等基本业务。要求设计一个图书管理信息系统,用计算机模拟实现上述系统功能。

二、详细设计

2.1 数据结构的设计
2.1.1 图书信息的存入

ofstream fout("book.txt");
	if (fout)
	{
		fout << data.size() << endl;
		//book p;
		for (int i = 0; i <(int)data.size(); i++)
		{
			fout << data[i].idnum << " " << data[i].name << " " << data[i].author << " " << data[i].price << " " << data[i].kind << " " << data[i].room << " " << data[i].sum << " " << data[i].nowsum << " " << data[i].BorrowCount << " " << data[i].ok << " " << data[i].appointment << " " << data[i].borrowdate << " " << data[i].returndate << " " << endl;
		}
		fout.close();
	}

2.1.2 学生信息存入

ofstream fout("student.txt");
	if (fout)
{
		fout << data1.size() << endl;
		//student p;
		for (int i = 0; i <(int)data1.size(); i++)
{
			fout << data1[i].id << " " << data1[i].name << " " << data1[i].borrowsum << " " << data1[i].number << " " << data1[i].borrowday;
			for (int j = 0; j<10; j++)
			{
fout << " " << data1[i].b[j];
}
			fout << endl;
}
		fout.close();
}

2.2 算法的设计思想及流程图
2.2.1 主要函数的功能说明
1、void AddBook(book NewBook); //增加图书
2、void DeleteBook(string bookname, string author);//删除图书
3、void BorrowBook(string name, string author);//借阅图书
4、void BackBook(string name, string author, int k);//归还图书
5、void ShowAllBook(); //输出系统所有图书
6、void SearchBookPosWithname(string thebook); //按书名查询
7、void SearchBookPosWithAuthor(string theauthor);//按作者查询
8、void SearchBookPosWithKind(string kind);//按种类查询
9、int SearchBookPosWithNum(int theNum);//按编号查询
10、void SortBook(int ca); //排序
11、void Save(); //存入图书馆文件
12、void Save1();//存入学生文件
13、void printbook(book a);//输出某本书的所有信息
14、void revisebook(string name, string author);//修改某本书的信息
15、int SerchStudent(int id);//查询某个读者
16、void AddStudent(student a);//增加一个读者
17、void PrintStudent(int kid);//输出读者信息
18、int GetStudent();//返回读者总数

2.3 模块结构及流程图
2.3.1 程序总流程图

如图1所示:
在这里插入图片描述
图1 系统总流程图

2.3.2 管理员的图书管理模块流程
管理员的图书管理模块流程。如图2所示。
在这里插入图片描述
图2 图书管理模块

2.3.3 图书查询模块
图书查询模块如图3所示。
在这里插入图片描述
图3 图书查询模块

三、主要程序分析

Library::AddBook(book NewBook){data.push_back(NewBook);}
添加图书函数并将新增图书放到链表最后一位

Library::AddStudent(student newstudent){data1.push_back(newstudent);}
添加读者函数并将新增读者放到链表最后一位

Library::DeleteBook(string bookname, string author){
int pos = SearchBookPosWithAB(author, bookname);
if (pos != -1){data.erase(data.begin() + pos);return;}
删除函数:删除图书信息

Library::SearchBookPosWithname(string thebook){
int flag = 0;for (int i = 0; i <(int)data.size(); i++){
if (data[i].name == thebook){printbook(data[i]);flag = 1;}}
查询函数:所有查询方式匀与此类似,均为按值查找

Library::revisebook(string name, string author) if (data[i].author == author&&data[i].name == name){k = i;break;}
修改函数:对已存图书信息进行修改

四、程序运行结果

4.1 读者界面与管理员界面
在这里插入图片描述
在这里插入图片描述

4.2 显示所有图书信息界面
在这里插入图片描述

4.3 图书借阅界面
在这里插入图片描述

附录(源程序):

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>  
#include <vector>                               //vector 顺序容器 比数组优越 .at()访问
#include <algorithm>                            //模板库  
#include <fstream>
#include <cctype>                               //字符处理库   字符测试、映射
#include <iomanip>                              //流操作符头文件
using namespace std;
struct student
{
	static int s1;
	int id;//读者编号
	string name;//读者姓名
	int borrowsum;//你已借阅多少本书,默认为0
	int number;//现在还有多少本书未还,默认为0
	string borrowday;//上次借阅时间,默认为0000.00.00
	int b[10];//你所借书的的编号,最多10本
};
struct book
{
	int idnum;//图书编号号
	int BorrowCount;//图书借阅量,初始化为0
	string name;//书名
	string kind;//图书种类
	double price;//图书价格
	int sum;//图书总库存存量
	int nowsum;//图书现库存量
	string author;//图书作者
	bool ok;//是否可借,初始为可以
	string borrowdate;//图书最近一次借出时间,默认为0000-00-00;
	string returndate;//图书最近一次归还时间,默认为0000-00-00;
};
bool cmpByidnum(book a, book b)
{
	return a.idnum < b.idnum;
}
bool cmpByCount(book a, book b)
{
	return a.BorrowCount > b.BorrowCount;
}
bool cmpByBorrowsum(student a, student b)
{
	return a.borrowsum > b.borrowsum;
}
bool cmpByid(student a, student b)
{
	return a.id < b.id;
}
class Library
{
private:
	vector<book> data;
	vector<student> data1;
	vector<int> betoli;//预约书到馆,储存其编号
public:
	Library();
	void AddBook(book NewBook);  //增加图书
	void DeleteBook(string bookname, string author);//删除图书
	void BorrowBook(string name, string author);//借阅图书
	void BackBook(string name, string author, int k);//归还图书
	void ShowAllBook(); //输出系统所有图书
	void SearchBookPosWithNum(int theauthor);//按编号查询
	void  SearchBookPosWithname(string thebook); //按书名查询
	void  SearchBookPosWithAuthor(string theauthor);//按作者查询
	void  SearchBookPosWithKind(string kind);//按种类查询
	int  SearchBookPosWithAB(string theauthor, string thebook);//按作者和书名查询
	void Save();  //存入图书馆文件
	void Save1();//存入学生文件
	void printbook(book a);//输出某本书的所有信息
	void revisebook(string name, string author);//修改某本书的信息
	int SerchStudent(int id);//查询某个读者
	void AddStudent(student a);//增加一个读者
	void PrintStudent(int kid);//输出读者信息
	int GetStudent();//返回读者总数
};
Library::Library()
{
	int AllBook, AllStudent;
	ifstream fin("book.txt");
	if (fin)
	{
		fin >> AllBook;
		for (int i = 0; i < AllBook; i++)
		{
			book tem;
			fin >> tem.idnum >> tem.name >> tem.author >> tem.price >> tem.kind  >> tem.sum >> tem.nowsum >> tem.BorrowCount >> tem.ok  >> tem.borrowdate >> tem.returndate;
			data.push_back(tem);              //添加在数组最后
		}
		fin.close();
	}
	ifstream tfin("student.txt");
	if (tfin)
	{
		tfin >> AllStudent;
		for (int i = 0; i < AllStudent; i++)
		{
			student tem;
			tfin >> tem.id >> tem.name >> tem.borrowsum >> tem.number >> tem.borrowday;
			for (int j = 0; j < 10; j++)
			{
				tfin >> tem.b[j];
			}
			data1.push_back(tem);
		}
		tfin.close();
	}
}
int Library::GetStudent()
{
	int k = (int)data1.size();
	return k + 1;
}
void Library::AddBook(book NewBook)
{
	data.push_back(NewBook);
}
void Library::AddStudent(student newstudent)
{
	data1.push_back(newstudent);
}
void Library::DeleteBook(string bookname, string author)
{
	int pos = SearchBookPosWithAB(author, bookname);
	if (pos != -1)
	{
		data.erase(data.begin() + pos);
		Save();
		return;
	}
	else
		cout << "查无此书!\n";
}
void Library::BorrowBook(string name, string author)
{
	string BorrowDate;
	string BackDate;
	char c;
	int flag = 0;
	int sid = -1;
	for (int i = 0; i < (int)data.size(); i++)
	{
		if (data[i].name == name && data[i].author == author)
		{
			if (data[i].nowsum)
			{
				cout << "借书读者的读者号是:";
				cin >> sid;
				if (data1[sid - 1].number > 10)
				{
					cout << "现你同时借了10本书!不可再借!" << endl;
					break;
				}
				flag = 1;
				data[i].nowsum = data[i].nowsum - 1;
				data[i].BorrowCount = data[i].BorrowCount + 1;
				cout << "请输入借阅日期" << endl;
				cin >> BorrowDate;
				data[i].borrowdate = BorrowDate;
				cout << "请输入预计归还日期" << endl;
				cin >> BackDate;
				data[i].returndate = BackDate;
				data[i].ok = bool(data[i].nowsum);
				data1[sid - 1].number++;
				for (int j = 0; j < 10; j++)
				{
					if (data1[sid - 1].b[j] == 0)
						data1[sid - 1].b[j] = data[i].idnum;
					Save();
					Save1();
				}
				cout << "借阅成功" << endl;
			}
			else
			{
				cout << "抱歉这本书库存为零,无法借阅" << endl;
			}
		}
	}
	if (!flag)
		cout << "抱歉,未找到您要找的书。" << endl;
}
void Library::BackBook(string name, string author, int k)//k表示还书途径
{
	int c = -1;
	{
		cout << "请输入你的读者号:";
		cin >> c;
		c = c - 1;
	}
	for (int i = 0; i < (int)data.size(); i++)
	{
		if (data[i].name == name && data[i].author == author)
		{
			data[i].nowsum = data[i].nowsum + 1;
			data[i].ok = bool(data[i].nowsum);
			for (int j = 0; j < 10; j++)
			{
				if (data1[c].b[j] == data[i].idnum)
					data1[c].b[j] = 0;
			}
			data1[c].number--;
			break;
		}
	}
	Save();
	Save1();
	cout << "还书成功" << endl;
}
void Library::printbook(book a)
{

	cout << " 编号:" << setw(12) << a.idnum;
	cout << " 书名:" << setw(14) << a.name;
	cout << " 作者:" << setw(14) << a.author << endl;
	cout << " 价格:" << setw(14) << fixed << setprecision(2) << a.price;
	cout << " 种类:" << setw(14) << a.kind;
	cout << " 总库存量:" << setw(10) << a.sum;
	cout << " 现库存量:" << setw(10) << a.nowsum;
	cout << " 图书借阅量:" << setw(14) << a.BorrowCount << endl;
	cout << " 状态:" << setw(14) << (a.ok == 0 ? "不可借" : "可借");
	cout << " 近期借出日期:" << setw(14) << a.borrowdate;
	cout << " 近期归还日期:" << setw(14) << a.returndate << endl;
	cout << endl << endl;
}
void Library::PrintStudent(int kid)
{
	int id = kid - 1;
	cout << setw(8) << data1[id].id;
	cout << setw(8) << data1[id].name;
	cout << setw(18) << data1[id].number;
	if (data1[id].number)
	{
		cout << "                 " << endl;
		cout << "你当前借了这些书:\n";
		cout << setw(16) << "编号" << setw(16) << "书名" << setw(16) << "作者" << endl;
		for (int i = 0; i < 1; i++)
		{
			if (data1[id].b[i] != 0)
				cout << setw(16) << data[data1[id].b[i] - 1].idnum << setw(16) << data[data1[id].b[i] - 1].name << setw(16) << data[data1[id].b[i] - 1].author << endl;
		}
	}
	else
		cout << "你当前并未借任何书,快去借本书看看吧!\n";
}
void Library::ShowAllBook()
{
	system("cls");
	cout << "所有图书为:" << endl;
	for (int i = 0; i < (int)data.size(); i++)
	{
		printbook(data[i]);
	}
}
int Library::SerchStudent(int id)
{
	int m = -1;
	for (int i = 0; i < (int)data1.size(); i++)
	{
		if (data1[i].id == id)
		{
			return i;
		}
	}
	return m;
}
void Library::SearchBookPosWithNum(int thenum)//按编号查询
{
	bool flag = false;
	for (int i = 0; i < (int)data.size(); i++)
	{
		if (data[i].idnum == thenum)
		{
			flag = true;
			printbook(data[i]);
		}
	}
	if (!flag) cout << "查无此编号!";
}
void Library::SearchBookPosWithname(string thebook)//按书名查询
{
	int flag = 0;
	for (int i = 0; i < (int)data.size(); i++)
	{
		if (data[i].name == thebook)
		{
			printbook(data[i]);
			flag = 1;
		}
	}
	if (!flag) cout << "查无此书!\n";
}
void Library::SearchBookPosWithAuthor(string theauthor)//按作者查询
{
	bool flag = false;
	for (int i = 0; i < (int)data.size(); i++)
	{
		if (data[i].author == theauthor)
		{
			flag = true;
			printbook(data[i]);
		}
	}
	if (!flag) cout << "查无此作者的书!";
}
void Library::SearchBookPosWithKind(string kind)//按种类查询
{
	bool flag = false;
	for (int i = 0; i < (int)data.size(); ++i)
	{
		if (data[i].kind == kind)
		{
			flag = true;
			printbook(data[i]);
		}
	}
	if (!flag) cout << "查无此类书!";
}
int Library::SearchBookPosWithAB(string theauthor, string thebook)//按作者和书名查询
{
	for (int i = 0; i < (int)data.size(); ++i)
	{
		if (data[i].author == theauthor && data[i].name == thebook)
		{
			printbook(data[i]);
			return i;
		}
	}
	cout << "查无此书!";
	return -1;
}
void Library::Save() //存入书籍文件
{
	ofstream fout("book.txt");
	if (fout)
	{
		fout << data.size() << endl;
		for (int i = 0; i < (int)data.size(); i++)
		{
			fout << data[i].idnum << " " << data[i].name << " " << data[i].author << " " << data[i].price << " " << data[i].kind /*<< " " << data[i].room */ << " " << data[i].sum << " " << data[i].nowsum << " " << data[i].BorrowCount << " " << data[i].ok/* << " " << data[i].appointment */ << " " << data[i].borrowdate << " " << data[i].returndate << " " << endl;
		}
		fout.close();
	}
}
void Library::Save1() //存入学生文件
{
	ofstream fout("student.txt");
	if (fout)
	{
		fout << data1.size() << endl;
		for (int i = 0; i < (int)data1.size(); i++)
		{
			fout << data1[i].id << " " << data1[i].name << " " << data1[i].borrowsum << " " << data1[i].number << " " << data1[i].borrowday;
			for (int j = 0; j < 10; j++)
			{
				fout << " " << data1[i].b[j];
			}
			fout << endl;
		}
		fout.close();
	}
}
void Library::revisebook(string name, string author)//修改图书
{
	Library mybook;
	string  Kind;
	int num1, num2, k = 0;
	printf("你要修改的内容是:\n");
	printf("                 1.图书现库存量修改\n");
	printf("                 2.图书总库存量修改\n");
	printf("                 3.图书所属种类修改\n");
	printf("                 4.退出\n");
	for (int i = 0; i < (int)data.size(); i++)
	{
		if (data[i].author == author && data[i].name == name)
		{
			k = i;
			break;
		}
	}
	int cho;
	do
	{
		cin >> cho;
		switch (cho)
		{
		case 1:
		{
			cout << "请输入新的现库存量:\n";
			cin >> num1;
			data[k].nowsum = num1;
			Save();
			cout << "修改成功" << endl;
			break;
		}
		case 2:
		{
			cout << "请输入新的总库存量:\n";
			cin >> num2;
			data[k].sum = num2;
			Save();
			cout << "修改成功" << endl;
			break;
		}
		case 3:
		{
			cout << "请输入图书所属新种类:\n";
			cin >> Kind;
			data[k].kind = Kind;
			Save();
			cout << "修改成功" << endl;
			break;
		}
		}
	} while (cho < 3);
}

int main()
{
	cout.setf(ios::left);//左对齐
	Library mybook;
	cout << "************************** 欢迎使用北京石油化工学院图书管理系统 **************************" << endl << endl;
	cout << "请输入读者编号登录" << endl;
	int mm = 310;
	int bh, k = 0, z = 0, cho;

	cin >> bh;
	if (bh == mm)
	{
		cout << "欢迎使用" << endl;
		k = 2;
	}
	else    z = 3;

	if (k == 2) {
		do
		{
			cout << "欢迎进入管理员系统" << endl;
			cin.clear();
			cin.sync();
			cout << " ***1.图书目录 ***" << endl;
			cout << " ***2.查询图书 ***" << endl;
			cout << " ***3.添加图书 ***" << endl;
			cout << " ***4.删除图书 ***" << endl;
			cout << " ***5.修改图书信息***" << endl;
			cout << "-------------------------------------------------------------------------------------------------------------------" << endl;
			cout << "请选择功能,输入指令 " << endl;
			cin >> cho;
			switch (cho)
			{
			case 1:
			{
				int cho2;
				mybook.ShowAllBook();
				cout << "--------------------------------------------------------------------------------------------------------------------" << endl;
				cin >> cho2;
				/*while (cho2 < 2);
				{
					switch (cho2)
					{
					case 0:
						mybook.SortBook(0);
						break;
					case 1:
						mybook.SortBook(1);
						break;
					}
				}*/
				break;
			}
			case 2:
			{   cout << " *** 0.返回 *** " << endl;
			cout << " *** 1.按书名查询 *** " << endl;
			cout << " *** 2.按作者查询 *** " << endl;
			cout << " *** 3.按种类查询 *** " << endl;
			cout << " *** 4.按编号查询 *** " << endl;
			cout << " *** 请选择功能,输入指令 *** " << endl;
			int p1;
			string Name, Author, Kind;
			int thenum;
			cin >> p1;
			if (p1 >= 0 && p1 <= 4)
			{
				do
				{
					switch (p1)
					{
					case 1:do
					{
						cout << "请输入书名!" << endl;
						cin >> Name;
						mybook.SearchBookPosWithname(Name); //按书名查询
						break;
					} while (p1 != 0); break;
					case 2:
					{
						cout << "请输入作者!" << endl;
						cin >> Author;
						mybook.SearchBookPosWithAuthor(Author);//按作者查询
						break;
					}
					case 3:
					{
						cout << "请输入种类!" << endl;
						cin >> Kind;
						mybook.SearchBookPosWithKind(Kind);//按种类查询
						break;
					}
					case 4:
					{
						cout << "请输入编号!" << endl;
						cin >> thenum;
						mybook.SearchBookPosWithNum(thenum);//按编号查询
						break;
					}
					}
				}

				while (p1 >= 1 && p1 <= 4); break;
			}
			else
			{
				cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
				cout << "!!!!!!!!!!请输入正确指令!!!!!!!!!!" << endl;
				cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
				break;
			}
			}
			case 3:         //增加图书
			{
				book temp;
				cin.clear();
				cin.sync();
				cout << "编号:";
				cin >> temp.idnum;
				cout << "书名:";
				cin >> temp.name;
				cout << "作者:";
				cin >> temp.author;
				cout << "价格:";
				cin >> temp.price;
				cout << "种类:";
				cin >> temp.kind;
				cout << "数量:";
				cin >> temp.sum;
				temp.nowsum = temp.sum;
				temp.BorrowCount = 0;
				temp.ok = true;
				temp.borrowdate = "0000.00.00";
				temp.returndate = "0000.00.00";
				mybook.AddBook(temp);
				mybook.Save();
				cout << "信息保存成功" << endl;
				break;
			}
			case 4:         //删除图书
			{
				string bookname, bookauthor;
				cout << "请输入书名和作者:" << endl;
				cin >> bookname >> bookauthor;
				mybook.DeleteBook(bookname, bookauthor);
				break;
			}
			case 5://修改图书信息
			{
				string name, author;
				cout << "请输入要修改的书名和作者:" << endl;
				cin >> name >> author;
				mybook.revisebook(name, author);
				break;
			}
			}
		} while (cho >= 1 && cho <= 5);
		{
			cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
			cout << "!!!!!!!!!!请输入正确指令!!!!!!!!!!" << endl;
			cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
			system("pause");
		}
	}

	if (z == 3)
	{


		if (mybook.SerchStudent(bh) == -1)
		{
			int n;
			cout << "你不是此系统读者,是否注册?\n";
			cout << "                    1.注册\n";
			cout << "                    2.不需要\n";
			cin >> n;
			student temp;
			if (n == 1)
			{
				cout << "请输入你的姓名:";
				cin >> temp.name;
				cin.clear();
				cin.sync();
				temp.id = mybook.GetStudent();
				temp.borrowsum = 0;
				temp.number = 0;
				temp.borrowday = "0000.00.00";
				for (int i = 0; i < 10; i++)
				{
					temp.b[i] = 0;
				}
				mybook.AddStudent(temp);
				mybook.Save1();
				cout << "                注册成功!请记住你的读者号,若忘记请联系管理员!\n";
				cout << "                姓名:" << temp.name << endl;
				cout << "                读者号:" << temp.id << endl;
				k = temp.id;
				do
				{

					cin.clear();
					cin.sync();
					cout << "***1.查询图书***" << endl;
					cout << "***2.借阅图书***" << endl;
					cout << "***3.归还图书***" << endl;
					cout << "***4.查询读者信息***" << endl;
					cout << "***请选择功能,输入指令***" << endl;
					cin >> cho;
					int thenum;
					switch (cho)
					{
					case 1:
					{   cout << " *** 0.返回 *** " << endl;
					cout << " *** 1.按书名查询 *** " << endl;
					cout << " *** 2.按作者查询 *** " << endl;
					cout << " *** 3.按种类查询 *** " << endl;
					cout << " *** 4.按编号查询 *** " << endl;
					cout << " *** 请选择功能,输入指令 *** " << endl;
					int p1;
					string Name, Author, Kind;
					cin >> p1;
					if (p1 >= 0 && p1 <= 4)
					{
						do
						{
							switch (p1)
							{
							case 1:do
							{
								cout << "请输入书名!" << endl;
								cin >> Name;
								mybook.SearchBookPosWithname(Name); //按书名查询
								break;
							} while (p1 != 0); break;
							case 2:
							{
								cout << "请输入作者!" << endl;
								cin >> Author;
								mybook.SearchBookPosWithAuthor(Author);//按作者查询
								break;
							}
							case 3:
							{
								cout << "请输入种类!" << endl;
								cin >> Kind;
								mybook.SearchBookPosWithKind(Kind);//按种类查询
								break;
							}
							case 4:
							{
								cout << "请输入编号!" << endl;
								cin >> thenum;
								mybook.SearchBookPosWithNum(thenum);//按编号查询
								break;
							}
							}
						}

						while (p1 >= 1 && p1 <= 4); break;
					}
					else
					{
						cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
						cout << "!!!!!!!!!!请输入正确指令!!!!!!!!!!" << endl;
						cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
						break;
					}
					}
					case 2:
					{
						string bookname, bookauthor;
						cout << "请输入要借的书名和作者:" << endl;
						cin >> bookname >> bookauthor;
						mybook.BorrowBook(bookname, bookauthor);
						mybook.Save();
						system("pause");
						break;
					}
					case 3:
					{
						string bookname, bookauthor;
						cout << "请输入要还的书名和作者:" << endl;
						cin >> bookname >> bookauthor;
						mybook.BackBook(bookname, bookauthor, -1);
						mybook.Save();
						system("pause");
						break;
					}
					case 4:
					{
						cout << setw(8) << "读者号" << setw(8) << "姓名"/* << setw(8) << "历史借阅次数" */ << setw(8) << "现在借阅书个数" /*<< setw(8) << "上次还书时间" */ << endl;
						mybook.PrintStudent(k);
						system("pause");
						break;
					}
					}
				} while (cho >= 1 && cho <= 4);
				{cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
				cout << "!!!!!!!!!!请输入正确指令!!!!!!!!!!" << endl;
				cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
				system("pause");
				}

			}
			else

				return(0);
		}


		else
		{
			k = bh;
		}

		do
		{

			cin.clear();
			cin.sync();
			cout << "***1.查询图书***" << endl;
			cout << "***2.借阅图书***" << endl;
			cout << "***3.归还图书***" << endl;
			cout << "***4.查询读者信息***" << endl;
			cout << "***请选择功能,输入指令***" << endl;
			cin >> cho;
			switch (cho)
			{
			case 1:
			{   cout << " *** 0.返回 *** " << endl;
			cout << " *** 1.按书名查询 *** " << endl;
			cout << " *** 2.按作者查询 *** " << endl;
			cout << " *** 3.按种类查询 *** " << endl;
			cout << " *** 4.按编号查询 *** " << endl;
			cout << " *** 请选择功能,输入指令 *** " << endl;
			int p1;
			string Name, Author, Kind;
			int thenum;
			cin >> p1;
			if (p1 >= 0 && p1 <= 4)
			{
				do
				{
					switch (p1)
					{
					case 1:do
					{
						cout << "请输入书名!" << endl;
						cin >> Name;
						mybook.SearchBookPosWithname(Name); //按书名查询
						break;
					} while (p1 != 0); break;
					case 2:
					{
						cout << "请输入作者!" << endl;
						cin >> Author;
						mybook.SearchBookPosWithAuthor(Author);//按作者查询
						break;
					}
					case 3:
					{
						cout << "请输入种类!" << endl;
						cin >> Kind;
						mybook.SearchBookPosWithKind(Kind);//按种类查询
						break;
					}
					case 4:
					{
						cout << "请输入编号!" << endl;
						cin >> thenum;
						mybook.SearchBookPosWithNum(thenum);//按编号查询
						break;
					}
					}
				}

				while (p1 >= 1 && p1 <= 4); break;
			}
			else
			{
				cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
				cout << "!!!!!!!!!!请输入正确指令!!!!!!!!!!" << endl;
				cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
				break;
			}
			}
			case 2:
			{
				string bookname, bookauthor;
				cout << "请输入要借的书名和作者:" << endl;
				cin >> bookname >> bookauthor;
				mybook.BorrowBook(bookname, bookauthor);
				mybook.Save();
				system("pause");
				break;
			}
			case 3:
			{
				string bookname, bookauthor;
				cout << "请输入要还的书名和作者:" << endl;
				cin >> bookname >> bookauthor;
				mybook.BackBook(bookname, bookauthor, -1);
				mybook.Save();
				system("pause");
				break;
			}
			case 4:
			{
				cout << setw(8) << "读者号" << setw(8) << "姓名" /*<< setw(8) << "历史借阅次数" */ << setw(8) << "现在借阅书个数" /*<< setw(8) << "上次还书时间"*/ << endl;
				mybook.PrintStudent(k);
				system("pause");
				break;
			}
			}
		} while (cho >= 1 && cho <= 4);
		{cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
		cout << "!!!!!!!!!!请输入正确指令!!!!!!!!!!" << endl;
		cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
		system("pause");
		}

	}
}
发布了2 篇原创文章 · 获赞 2 · 访问量 51

猜你喜欢

转载自blog.csdn.net/weixin_44487231/article/details/104369724
今日推荐