bool UserServiceImpl::Compare1(Book b1,Book b2)//按照借阅次数比较
{
if(b1.GetCnt() > b2.GetCnt())
{
return true;
}
else
{
return false;
}
}
bool UserServiceImpl::Compare2(Book b1,Book b2)//按照评分比较
{
if(b1.GetScore() > b2.GetScore())
{
return true;
}
else
{
return false;
}
}
//按照借阅次数来向读者推荐
void UserServiceImpl::Cnt()
{
books.clear();//清空书籍容器
b_dao->load(books);//读取书籍库文件存入到容器中
sort(books.begin(),books.end(),UserServiceImpl::Compare1);//比较函数
map<string,int>m;
cout << "\e[32m借阅次数前三图书\e[0m" << endl;
unsigned int i = 0;
int count = 0;
//信息显示
for(i = 0;i < books.size();i++)
{
if(3 <= count)
{
break;
}
if(0 != m[books[i].m_name])
{
continue;
}
++m[books[i].m_name];
cout << "\e[35m书名:\e[0m" << books[i].m_name << "\e[35m 编号:\e[0m" << books[i].m_id << "\e[35m 借阅次数:\e[0m" << books[i].GetCnt() << endl;
++count;
}
anykey_continue();//缓冲,清理缓存区
}
//按评分来向读者推荐
void UserServiceImpl::Soc()
{
books.clear();
b_dao->load(books);
sort(books.begin(),books.end(),UserServiceImpl::Compare2);
map<string,int>m;
cout << "\e[32m评分前三图书\e[0m" << endl;
unsigned int i = 0;
int count = 0;
for(i = 0;i < books.size();i++)
{
if(3 <= count)
{
break;
}
if(0 != m[books[i].m_name])
{
continue;
}
++m[books[i].m_name];
cout << "\e[35m书名:\e[0m" << books[i].m_name << "\e[35m 编号:\e[0m" << books[i].m_id << "\e[35m 评分:\e[0m" << books[i].GetScore() << endl;
++count;
}
anykey_continue();
}