头文件与声明
#include<iostream>
#include<string>
#include<list>
#include<sstream>
#include<fstream>
#include<iomanip>
#define MAX_BOOK 100
using namespace std;
template<class T>
T stringToNum(const string&str);
定义一个书类并创建一个图书链表存放书目信息
class Book
{
public:
string bookISBN;//编号
string bookname;//书名
int price;//价格
int count;//数量
Book()
{
bookISBN = "0";
bookname = "0";
price = 0;
count = 0;
}
Book(string ISBN, string name, int money, int num) :
bookISBN(ISBN), bookname(name), price(money), count(num){}
bool operator<(Book b) { return this->bookISBN<b.bookISBN; }//为了排序
bool operator>(Book b) { return this->bookISBN>b.bookISBN; }
void print()
{//显示图书信息
cout << bookISBN << setw(15) << bookname << setw(5) << price << setw(5) << count << endl;
}
};
list<Book>lst;//图书链表,用于存放图书信息
各个操作函数
void print(list<Book>lst, string name)
{//输入链表中所有书籍
list<Book>::iterator it;
cout << name << ":" << endl;
cout << "编号" << setw(15) << "书名" << setw(11) << "价格" << setw(5) << "数量" << endl;
for (it = lst.begin(); it != lst.end(); it++)
it->print();
cout << endl;
}
void screenA()//显示屏幕操作A
{
cout << "****************************************" << endl;
cout << " 1--------------查询" << endl;
cout << " 2--------------排序" << endl;
cout << " 3--------------插入" << endl;
cout << " 4--------------删除" << endl;
cout << " 5--------------显示" << endl;
cout << "