[2018年5月24号]C++ primer 课后练习 第十五章 面向对象程序设计

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值