15.30
double print_total(ostream& os, const Quote & item, size_t n){
double ret = item.net_price(n);
os << "ISBN: " << item.isbn() << "#sold:" << n << "total due"<<ret << endl;
return ret;
}
class Basket {
public:
void addItems(const Quote& qt){
items.insert(shared_ptr<Quote>(qt.clone()));
}
void addItems(Quote&& qt) {
items.insert(shared_ptr<Quote>(std::move(qt).clone()));
}
void total_receipt(ostream& os){
double sum = 0.0;
for(auto it = items.cbegin();it != items.cend();it = items.upper_bound(*it)){
sum += print_total(os,**it,items.count(*it));
}
cout << "sum:" << sum << endl;
}
static bool compare(const std::shared_ptr<Quote> & lhs, const std::shared_ptr<Quote> & rhs){
return lhs->isbn() < rhs->isbn();
}
private:
std::multiset<shared_ptr<Quote>, bool(*)(const std::shared_ptr<Quote> &, const std::shared_ptr<Quote> &)> items{compare};
};
15.31
a. 查询s1和s2其中一个关键字同时不包含s3
AndQuery
b.满足同时拥有s2和没有s3关键字或者满足s1
OrQuery
c.同时满足s1和s2关键字,或者,同时满足s3和s4关键字
OrQuery