Library0版的图书管理系统的功能
(1)显示图书馆的所有图书的基本信息
(2)显示本馆的所有读者的基本信息
(3)增加新的图书
(4)增加新的读者,
(5)显示图书馆本月借书量与还书量
代码实现如下:
1.头文件:
#pragma once
#ifndef _LIBRARAY_H_
#define _LIBRARAY_H_
#include<iostream>;
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
struct Reader{
int id;
string name;
};
struct Book {
string BookName;
string BookAuthor;
};
class Library{
private:
int Borrownum;//每月外借量
int Backnum;//每月还书量
vector<Reader> readers;
vector<Book> books;
public:
Library();
int GetBorrownum();//每个月的外借量
int GetBacknum();//每个月的还书量
void Addbook(string name, string author);
void AddReader(int id, string name);
void ShowReader();
void ShowAllBook();
};
#endif
2.头文件相关方法的定义文件:
#include"Libraray0.h";
Library::Library() {
Borrownum = 0;
Backnum = 0;
Reader r = { -1,"nane" };
readers.push_back(r);
Book b = { "none","none" };
books.push_back(b);
}
int Library::GetBorrownum() {//每个月的外借量
return Borrownum;
}
int Library::GetBacknum() {//每个月的还书量
return Backnum;
}
void Library::Addbook(string name, string author) {
Book temp = { name,author };
books.push_back(temp);
}
void Library::AddReader(int id, string name) {
Reader temp = { id,name };
readers.push_back(temp);
}
void Library::ShowReader() {
cout.setf(ios::left);//左端对齐
cout << setw(10)<<"读者编号" << setw(10) << "名字" << endl;
for (int i = 1; i < (int)readers.size(); i++) {//读者的下标均从1开始,0的位置为“哨兵”,只做初始化用
cout <<setw(10)<< readers[i].id << setw(10) << readers[i].name <<endl;
}
}
void Library::ShowAllBook() {
cout.setf(ios::left);//左端对齐
cout <<setw(10)<< "书名" << setw(10) << "作者" << endl;
for (int i = 1; i < (int)books.size(); i++) {//书的下标均从1开始,0的位置为“哨兵”,只做初始化用
cout <<setw(10)<< books[i].BookName << setw(10) << books[i].BookAuthor << endl;
}
}
3.主程序文件:
/*********************************************************************************************************
//该版本为Library0版本
//读者的信息只有读者编号、读者姓名;书本的信息只有书名、作者名
//该图书系统的功能只有显示所有图书与学生信息的功能,增加图书与读者的功能,显示图书馆本月借还统计功能
**********************************************************************************************************/
#include"Libraray0.h"
int main() {
cout.setf(ios::left);
Library DegeLibrary;
int cho;
do {
system("cls");
cout << "--------------------------------------------------------------------" << endl;
cout << " 欢迎来到德哥图书管理系统^-^" << endl;
cout << "德哥图书管理系统的功能菜单如下:" << endl;
cout << "1:打印所有书籍目录" << endl;
cout << "2:查看所有读者信息" << endl;
cout << "3:增加图书" << endl;
cout << "4:增加读者" << endl;
cout << "5.图书馆借还统计" << endl;
cout << "6:退出" << endl;
cout << "--------------------------------------------------------------------" << endl;
cout << "请输入你的功能选项:";
cin >> cho;
switch (cho) {
case 1: {//打印所有书籍目录
system("cls");
cout << " 欢迎来到德哥图书管理系统^-^" << endl;
cout << "--------------------------------------------------------------------" << endl;
DegeLibrary.ShowAllBook();
cout << "--------------------------------------------------------------------" << endl;
system("pause");
break;
}
case 2: {//查看所有读者信息
system("cls");
cout << " 欢迎来到德哥图书管理系统^-^" << endl;
cout << "--------------------------------------------------------------------" << endl;
DegeLibrary.ShowReader();
cout << "--------------------------------------------------------------------" << endl;
system("pause");
break;
}
case 3: {//增加图书
//Book temp;
system("cls");
cout << " 欢迎来到德哥图书管理系统^-^" << endl;
cout << "--------------------------------------------------------------------" << endl;
string name, author;
cout << "请输入书名:";
cin >> name;
//getline(cin,name,'#');//输入#号作为结束输入的终止符
//cin.clear();
//cin.ignore();
//system("pause");
cout << "请输入作者名字:";
cin >> author;
//cin.clear();
//cin.ignore();
//getline(cin, author,'#');
DegeLibrary.Addbook(name, author);
cout << "增加图书成功!" << endl;
cout << "--------------------------------------------------------------------" << endl;
system("pause");
break;
}
case 4: {//增加读者
system("cls");
int readerid;
string name;
cout << " 欢迎来到德哥图书管理系统^-^" << endl;
cout << "--------------------------------------------------------------------" << endl;
cout << "请输入读者编号:";
cin >> readerid;
cout << "请输入读者名字:";
cin >> name;
cin.clear();
//getline(cin, name);
DegeLibrary.AddReader(readerid, name);
cout << "成功增加读者!^-^!" << endl;
cout << "--------------------------------------------------------------------" << endl;
system("pause");
break;
}
case 5: {
system("cls");
cout << " 欢迎来到德哥图书管理系统^-^" << endl;
cout << "--------------------------------------------------------------------" << endl;
cout << "德哥图书馆本月的借阅量为:";
cout << DegeLibrary.GetBorrownum() << endl;
cout << "德哥图书馆本月的还书量为:";
cout << DegeLibrary.GetBacknum() << endl;
cout << "--------------------------------------------------------------------" << endl;
system("pause");
break;
}
}
} while (cho<6&&cho>=1);
return 0;
}