64,639
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using std::string;
using std::vector;
class book
{
private:
string isbn; //书号
string name; //书名
string writer; //作者
string publisher; //出版社
string time; //出版时间
string price; //图书价格
int inventory; //图书库存量
public:
book() {}
book(string a,string b,string c,string d,string e,string f,int g=0)
{
isbn=a;
name= b;
writer=c;
publisher=d;
time=e;
price=f;
inventory=g;
}
string get_name() const
{
return name;
}
string get_price() const
{
return price;
}
string get_isbn() const
{
return isbn;
}
string get_writer() const
{
return writer;
}
string get_time() const
{
return time;
}
string get_publisher() const
{
return publisher;
}
int get_inventory() const
{
return inventory;
}
void BuyBook ();
void creat();
void edit(string a, string b,string c,string d,string e,string f,int g,bool flag);
void display() ; //图书内容的显示
};
bool compare(book b1, book b2)
{
return(b1.get_name() > b2.get_name());
}
int main()
{
vector<book> books;
books.push_back(book("a1","b1","c1","d1","e1","f1", 10));
books.push_back(book("a2","b2","c2","d2","e2","f2", 10));
std::cout<<"init:"<<std::endl;
for(int i = 0; i < books.size(); i++)
{
std::cout<< books[i].get_name()<<std::endl;
}
std::cout<<"sort:"<<std::endl;
std::sort(books.begin(), books.end(), compare);
for(int i = 0; i < books.size(); i++)
{
std::cout<< books[i].get_name()<<std::endl;
}
return (0);
}