首页 技术 正文
技术 2022年11月15日
0 收藏 863 点赞 2,264 浏览 1431 个字
// 15_15.cpp : 定义控制台应用程序的入口点。
//#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;class Quote
{
public:
Quote() = default;
Quote(const string &book,double p):bookNo(book),price(p){}
const string& isbn()const { return bookNo; }
virtual double net_price(size_t n)const
{
return n*price;
}
private:
string bookNo;
protected:
double price = 0.0;
};class Dis_Quote :public Quote
{
public:
Dis_Quote() = default;
Dis_Quote(const string &book,double p,size_t n,double d):Quote(book,p),quantity(n),discount(d){}
virtual double net_price(size_t n)const = ;
protected:
size_t quantity = ;
double discount = 0.0;
};class Bulk_Quote :public Dis_Quote
{
public:
Bulk_Quote() = default;
Bulk_Quote(const string &book,double p,size_t n,double d):Dis_Quote(book,p,n,d){}
virtual double net_price(size_t n)const override
{
if (n > quantity)
return n*( - discount)*price;
else
return n*price;
}
};class Exercise_Quote :public Dis_Quote
{
public:
Exercise_Quote() = default;
Exercise_Quote(const string &book,double p,size_t n,double d):Dis_Quote(book,p,n,d){}
virtual double net_price(size_t n)const override
{
if (n <= quantity)
return n*( - discount)*price;
else
return quantity*( - discount)*price + (n - quantity)*price;
}
};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;
}int main()
{
Quote q1("lidandan", );
Bulk_Quote q2("lidandan", , , 0.1);
Exercise_Quote q3("lidandan", , , 0.1);
//Dis_Quote q4;
print_total(cout, q1, );
print_total(cout, q2, );
print_total(cout, q3, );
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,110
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,584
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,202
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,837
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,920