标签:重写 str qq群 private code 根据 out stream gre
Quote.h
#ifndef __QUOTE_H__
#define __QUOTE_H__
#include <iostream>
#include <memory>
class Quote{
public:
Quote() = default;
Quote(const std::string& book, double pri)
:bookNo(book), price(pri){}
std::string isbn() const{return bookNo;}
virtual void debug()const{
std::cout << bookNo << " " << price << std::endl;
}
virtual ~Quote() = default;
private:
std::string bookNo;
protected:
double price = 0.0;
};
class Bulk_quote : public Quote{
public:
Bulk_quote() = default;
Bulk_quote(const std::string&, double, std::size_t,
double);
void debug()const override;
private:
std::size_t min_qty = 0;//适用于折扣的最低购买数量
double discount = 0.0;//折扣额
};
class Min_quote : public Quote{
public:
Min_quote() = default;
Min_quote(const std::string&, double, std::size_t,
double);
void debug()const override;
private:
std::size_t max_qty = 10;//适用于折扣的最高购买数量
double discount = 0.1;//折扣额
};
#endif
Quote.cpp
#include "Quote.h"
Bulk_quote::Bulk_quote(const std::string& book, double p,
std::size_t qty, double disc):
Quote(book, p), min_qty(qty), discount(disc){}
void Bulk_quote::debug()const{
std::cout << min_qty << " " << discount << " " << price << std::endl;
}
Min_quote::Min_quote(const std::string& book, double p,
std::size_t qty, double disc):
Quote(book, p), max_qty(qty), discount(disc){}
void Min_quote::debug()const{
std::cout << max_qty << " " << discount << " " << price << std::endl;
}
mainQuote.cpp
#include "Quote.h"
int main(){
/*-----------test1-----------*/
Quote& q1 = q;
q1.debug();
q1 = bq;
q1.debug();
q1 = mq;
q1.debug();
/*-----------test1-----------*/
/*-----------test2-----------*/
Quote& q1 = mq;
q1.debug();
q1 = bq;
q1.debug();
q1 = q;
q1.debug();
/*-----------test2-----------*/
/*-----------test3-----------*/
Quote* q2 = &q;
q2->debug();
q2 = &bq;
q2->debug();
q2 = &mq;
q2->debug();
/*-----------test3-----------*/
/*-----------test4-----------*/
Quote* q2 = &mq;
q2->debug();
q2 = &bq;
q2->debug();
q2 = &q;
q2->debug();
/*-----------test4-----------*/
}
01 100
01 100
01 100
15 0.1 100
15 0.1 100
15 0.1 100
01 100
5 0.1 100
15 0.1 100
15 0.1 100
5 0.1 100
01 100
标签:重写 str qq群 private code 根据 out stream gre
原文地址:https://www.cnblogs.com/xiaoshiwang/p/10198391.html