- 请设计一个程序实现图书库存的管理(vector类)
【问题描述】
请设计一个程序实现图书库存的管理。请根据给定的main函数及程序输出,完成设计。具体要求如下。
一、请设计一个Book类(与动态数组类的要求一致):
1、包括私有成员:
unsigned int m_ID;//编号
string m_Name;//书名
string m_Introductio//简介
string m_Author;//作者
string m_Date;//日期
unsigned int m_Page;//页数
2、设计所有成员变量的getter和setter函数,关于getter和setter,我们在多文件视频课程中已经进行了介绍,同学们也可以百度了解。
3、设计构造与析构函数,不要求输出信息,但各位同学可以自己输出并分析各个对象的创建与删除的情况:
Book();//将m_ID初始化为0,表示这个一个未赋值对象
virtual ~Book();//无具体的工作
Book(const Book& other);//实现所有成员变量的拷贝
二、请设计一个Store类,这是一个基于vector实现的类,用于实现图书的管理:
1、包括私有成员:
m_Books;//利用vector动态创建的Book数组
2、设计 unsigned int GetCount()函数,返回m_Books中存储的Book对象的个数。
3、设计构造与析构函数,因为vector能够实现存储空间的动态管理,因此此处的设计明显比动态数组类简单。
1) Store();
输出"Store default constructor called!"
2)Store(int n);
将m_Books的大小置为n;并输出"Store constructor with (int n) called!";
3)virtual ~Store();
输出"Store destructor called!";
4)Store(const Store& other);
实现对象数组的拷贝,并输出"Store copy constructor called!";vector已经解决了深拷贝的问题,这里无需做深拷贝设计。
4、设计入库操作
入库操作的主要功能是在数组中添加一本新书。
函数声明为:void in(Book &b)
提示:利用vector的成员函数可以直接实现添加元素功能
5、设计出库操作
出库操作的主要功能是根据指定的书名,在数组中删除这本书。
函数声明为:void out(string name)
提示:利用vector的成员函数可以直接实现删除元素功能
6、根据ID查找图书
要求根据给定的ID查找图书,如果找到,则返回一个Book对象,Book对象中存储了对应书本的信息;如果找不到,则返回一个Book对象,Book对象的m_ID为0,表示未被初始化。
函数声明为:Book findbyID(int ID)
提示:vector中的元素遍历可以使用迭代器
7、根据name查找图书
要求根据给定的书名查找图书,如果找到,则返回一个Book对象,Book对象中存储了对应书本的信息;如果找不到,则返回一个Book对象,Book对象的m_ID为0,表示未被初始化。
函数声明为:Book findbyName(string name)
提示:vector中的元素遍历可以使用迭代器
8、设计一个函数打印所有的图书的信息
函数声明为:void printList()
#include <iostream>
#include <vector>
using namespace std;
class Book
{
public:
void SetID(int n);
void SetName(string n);
void SetAuthor(string n);
void SetIntroduction(string n); //请在此处补充Book类的定义
void SetDate(string n);
void SetPage(int n);
Book(const Book& b);
int GetID();
string GetAuthor();
string GetName();
string GetDate();
Book();
~Book();
private:
unsigned int m_ID;//编号
string m_Name;//书名
string m_Introductio;//简介
string m_Author;//作者
string m_Date;//日期
int m_Page;//页数
};
void Book::SetPage(int n)
{
m_Page = n;
}
void Book::SetID(int n)
{
m_ID = n;
}
void Book::SetName(string n)
{
m_Name = n;
} //请在此处补充Book类的成员函数实现
void Book::SetAuthor(string n)
{
m_Author = n;
}
void Book