15 Quote and Bulk_quote

本文介绍了一个图书销售系统中使用的三种不同折扣策略:普通折扣、批量折扣和限量折扣。通过继承和多态,实现了灵活的价格计算,包括普通价格、批量折扣价格和限量折扣价格。文章详细解释了每种策略的实现方式,并提供了一个示例,展示了如何使用这些策略来计算购买图书的总价格。

Quote class
Quote.h

#pragma once
#include <iostream>
#include <string>

class Quote {
public:
    Quote() = default;
    Quote(const std::string &bookNo, double book_price);
    std::string isbn() const;
    double print_total(std::ostream &out, Quote &item, size_t n) const;
    virtual double net_price(size_t n) const;
    virtual void debug() const;
    virtual ~Quote();
private:
    std::string bookNo;
protected:
    double price;
};

Quote.cpp

#include "Quote.h"

Quote::Quote(const std::string &bookNo, double book_price)
    : bookNo(bookNo), price(book_price) {}

std::string Quote::isbn() const {
    return bookNo;
}

double Quote::print_total(std::ostream &out, Quote &item, size_t n) const {
    double ret = item.net_price(n);
    out << "The book " << item.isbn() <<  " sold: " << n <<
    " total price " << ret << std::endl;
    return ret;
}

double Quote::net_price(size_t n) const {
    return n * price;
}

void Quote::debug() const {
    std::cout << "===This is a Quote call debug" << std::endl;
    std::cout << "The book number is: " << bookNo << " and the price is: " << price << std::endl;
}

Quote::~Quote() {}

Bulk_quote class
Bulk_quote.h

#pragma once
#include "Quote.h"

class Bulk_quote : public Quote {
public:
    Bulk_quote() = default;
    Bulk_quote(const std::string &bookNo, double book_price, size_t min_qty, double discount);
    virtual double net_price(size_t n) const;
    virtual void debug() const;
    virtual ~Bulk_quote();
private:
    size_t min_qty;
    double discount;
};

Bulk_quote.cpp

#include "Bulk_quote.h"

Bulk_quote::Bulk_quote(const std::string &bookNo, double book_price, size_t min_qty, double discount)
    : Quote(bookNo, book_price), min_qty(min_qty), discount(discount) {}

double Bulk_quote::net_price(size_t n) const {
    if (n >= min_qty) {
        return n * (1 - discount) * price;
    } else {
        return n * price;
    }
}

void Bulk_quote::debug() const {
    std::cout << "===This is a Bulk_quote object call" << std::endl;
    Quote::debug();
    std::cout << "The min number of books is: " 
              << min_qty << " and the discount is: " 
              << discount << std::endl;
}

Bulk_quote::~Bulk_quote() {}

Limit_quote class
Limit_quote.h

#pragma once
#include "Bulk_quote.h"

class Limited_quote : public Bulk_quote {
public:
    Limited_quote() = default;
    Limited_quote(const std::string &bookNo, double book_price, size_t min_qty, double discount, size_t max_qty);
    virtual double net_price(size_t n) const;
    virtual void debug() const;
    ~Limited_quote();
private:
    size_t max_qty;
};

Limit_quote.cpp

#include "Limited_quote.h"

Limited_quote::Limited_quote(const std::string &bookNo, double book_price, size_t min_qty, double discount, size_t max_qty)
    : Bulk_quote(bookNo, book_price, min_qty, discount), max_qty(max_qty) {}

double Limited_quote::net_price(size_t n) const {
    if (min_qty < n && n < max_qty) {
        return n * (1 - discount) * price;
    } else {
        return n * price;
    }
}

void Limited_quote::debug() const {
    std::cout << "===This is a Limited_quote object call" << std::endl;
    Bulk_quote::debug();
    std::cout << "The max number of books is: " << max_qty << std::endl;
}

Limited_quote::~Limited_quote() {}

main.cpp

#include <iostream>
#include <string>
#include "Quote.h"
#include "Bulk_quote.h"

using namespace std;

int main() {
    Quote *b = new Limited_quote("tree", 25, 3, 0.3, 10);
    b->print_total(cout, *b, 8);
    b->debug();
    delete b;
}
gene_count <- ncol(ref_final) if(gene_count < 1000) { warning(paste("仅保留", gene_count, "个基因,建议检查数据质量")) } else { message(paste("保留", gene_count, "个基因进行反卷积")) } ​ # 设置恶性细胞类型(根据实际名称) cell_types <- rownames(ref_final) key_cell <- if("Tumor-cells" %in% cell_types) "Tumor-cells" else NULL Last executed at 2025-06-26 19:44:59 in 18ms 保留 13851 个基因进行反卷积 # 创建Prism对象 bp <- new.prism( reference = ref_final, # 细胞类型×基因矩阵 mixture = t(bulk_final), # 样本×基因 input.type = "GEP", cell.type.labels = cell_types, cell.state.labels = cell_types, key = "Tumor-cells", pseudo.min = 1E-8 ) # 创建Prism对象 bp <- new.prism( reference = ref_final, # 细胞类型×基因矩阵 mixture = t(bulk_final), # 样本×基因 input.type = "GEP", cell.type.labels = cell_types, cell.state.labels = cell_types, key = "Tumor-cells", pseudo.min = 1E-8 ) Last executed at 2025-06-26 19:45:20 in 160ms number of cells in each cell state cell.state.labels Astrocyte Chemokine-myeloid Complement-myeloid M2-myeloid 1 1 1 1 Microglia Naive-T Neutrophil NK-T 1 1 1 1 Olig Prolifera Regulated-Tcells Tumor-cells 1 1 1 1 recommend to have sufficient number of cells in each cell state Error in validate.input(reference): Error: input contains NaN or NA values. Traceback: 1. validate.input(reference) 2. stop(" Error: input contains NaN or NA values.\n") 3. .handleSimpleError(function (cnd) . { . watcher$capture_plot_and_output() . cnd <- sanitize_call(cnd) . watcher$push(cnd) . switch(on_error, continue = invokeRestart("eval_continue"), . stop = invokeRestart("eval_stop"), error = invokeRestart("eval_error", . cnd)) . }, " Error: input contains NaN or NA values.\n", base::quote(validate.input(reference)))
06-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值