某出版社可出版图书和磁带。其中图书按照每页的价格乘以页数进行定价,磁带根据每10分钟的价格乘以磁带录音的分钟数进行定价。请定义Publicatioin、Book、Tape以及BookStore四个类。其中:

1. Publication类:

1)数据成员double price表示单价(对于书,是每页的价格;对于磁带,是每10分钟录音的价格)。

2)数据成员int length表示出版物的长度,对于书,是页数;对于磁带, 是分钟数。

3)成员函数getTotalPrice()用于返回一个出版物的定价。

4)构造函数Publication(double, int)用于构造一个出版物。

5)成员函数double getPrice() const和int getLength()用于返回出版物的单价及长度。

6)析构函数。

2. Book类是Publication的子类。

1)构造函数Book(double,int)。

2)重写父类的getTotalPrice返回定价,定价为单价乘以长度(即页数)。

3)析构函数。

3. Tape是Publication的子类:

1)构造函数Tape(double,int)。

2)重写父类的getTotalPrice返回定价。注意:price属性是每10分钟录音的单价,而磁带的长度不一定是10的整数倍。计算定价时,不足10分钟部分,按照10分钟计算。

3)析构函数。

4.BookStore是书店,具有数据成员Publications **pubs,是书店拥有的出版物列表;int num表示书店拥有的出版物数量。成员函数int getNumOfBook()和int getNumOfTape()分别计算书店中拥有的Book和Tape的数量。该类已经在appcode code中给出。

Input

输入分多行。

第一行是整数M>0,表示有M个测试用例。

每个测试占一行,分为三部分:第一部分是出版物类型(B表示Book,T表示Tape)、单价和数量(页数或分钟数)。

Output

见样例。

Sample Input

3 B 0.10 201 T 0.50 100 T 0.40 105

Sample Output

Call Publication's constructor! Call Book's constructor! Call Publication's constructor! Call Tape's constructor! Call Publication's constructor! Call Tape's constructor! Call Publication's constructor! Call Book's constructor! Call Publication's constructor! Call Tape's constructor! Call Publication's constructor! Call Tape's constructor! There are 1 books and 2 tapes. Their total price is 29.50. Call Book's de-constructor! Call Publication's de-constructor! Call Tape's de-constructor! Call Publication's de-constructor! Call Tape's de-constructor! Call Publication's de-constructor! Call Book's de-constructor! Call Publication's de-constructor! Call Tape's de-constructor! Call Publication's de-constructor! Call Tape's de-constructor! Call Publication's de-constructor! Call BookStore's de-constructor!
#include <iostream>
#include <cstdio>
#include <typeinfo>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
class Publication
{
public:
    double price;
    int length;
    virtual double getTotalPrice(){}
    Publication(double mon,int l):price(mon),length(l){cout<<"Call Publication's constructor!"<<endl;}
    double getPrice() const {return price;}
    int getLength(){return length;}
    virtual~Publication(){cout<<"Call Publication's de-constructor!"<<endl;}
};
class Book:public Publication
{
public:
    Book(double a,int b):Publication(a,b){cout<<"Call Book's constructor!"<<endl;}
    virtual~Book(){cout<<"Call Book's de-constructor!"<<endl;}
    virtual double getTotalPrice(){return price*length*1.0;}
};
class Tape:public Publication
{
public:
    Tape(double a,int b):Publication(a,b){cout<<"Call Tape's constructor!"<<endl;}
    virtual double getTotalPrice()
    {
        if(length%10==0)
            return price*1.0*(length/10);
        else
            return price*1.0*(length/10+1);
    }
    virtual~Tape(){cout<<"Call Tape's de-constructor!"<<endl;}
};

  

Problem D: 来开个书店吧的更多相关文章

  1. Problem A&B: 开宝箱 1/2 (最沙雕的做法)(未用指针做) 改:附上一种指针做法

    Description 急先锋是一个商人,有一天找到了一个宝箱,宝箱需要正确的密码才能打开.同时他发现宝箱上有一个数字,和一份密码表.密码表上有n个密码,只有一个密码是正确的. 急先锋所在的岛上有m个 ...

  2. Eclipse打开,出现Initializing Java Tooling “has encountered a problem错误,而且鼠标悬停在没有导包的类上面不会出现import信息。

    问题1:打开eclipse,出现了Initializing Java Tooling “has encountered a problem,点开详细信息,报的是空指针异常. 问题2:鼠标悬停在没有导包 ...

  3. 一个普通底层.NET程序员关于职场瓶颈期的思考,辗转自我提升/跳槽/转行之间

    徒有工龄,没技术没学历没平台没家底,工作几年,无车无房无存款还前景不明. 时常有身边的亲友问怎么学开发怎么转互联网,说起IT行业都说工资高,动辄月薪上万动辄年薪几十万. 再看看自己,我可能是假的程序员 ...

  4. 2017 SCNUCPC 解题报告

    校内赛题目.解题思路.参考代码一览 A. Blackstorm's Blackstore Problem Description Blackstorm is going to open a black ...

  5. 【NOI2013】小Q的修炼

    题目链接:http://uoj.ac/problem/123 又开提答坑啦,要不是一定要讲题谁他妈要这样伤害自己 CASE 1,2 首先可以打一个通用暴力,用于模拟操作过程,对于每一个操作随机一个选择 ...

  6. Problem B: 开个餐馆算算账

    Description 小明创业了!他开了一家餐馆,每天客人还挺多的.每天下班后,他都要算算今天总共收入多少钱,但是手工算太麻烦了,所以他来向你求助了. Input 第1行N>0,表示餐馆提供N ...

  7. 2019.03.09 bzoj4999: This Problem Is Too Simple!(树链剖分+线段树动态开点)

    传送门 题意:给一颗树,每个节点有个初始值,要求支持将i节点的值改为x或询问i节点到j节点的路径上有多少个值为x的节点. 思路: 考虑对每种颜色动态开点,然后用树剖+线段树维护就完了. 代码: #in ...

  8. BZOJ4999: This Problem Is Too Simple!树链剖分+动态开点线段树

    题目大意:将某个节点的颜色变为x,查询i,j路径上多少个颜色为x的点... 其实最开始一看就是主席树+树状数组+DFS序...但是过不去...MLE+TLE BY FCWWW 其实树剖裸的一批...只 ...

  9. BZOJ4999:This Problem Is Too Simple!(DFS序&树上差分&线段树动态开点:区间修改单点查询)

    Description 给您一颗树,每个节点有个初始值. 现在支持以下两种操作: 1. C i x(0<=x<2^31) 表示将i节点的值改为x. 2. Q i j x(0<=x&l ...

随机推荐

  1. 【JVM命令系列】jmap

    命令基本概述 Jmap是一个可以输出所有内存中对象的工具,甚至可以将VM 中的heap,以二进制输出成文本.打印出某个java进程(使用pid)内存内的,所有'对象'的情况(如:产生那些对象,及其数量 ...

  2. hdu3018欧拉回路题

    Ant Trip Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  3. NOIP2017SummerTraining0720

    这套题,看到第一题就想到了以前做过的运动鞋那道题,然后就往DP这个方向去思考,想来想去每什么思路,然后就去看第二题,第二题一看就是一道最短路的问题,但是它的建图十分困难, 怎么打都不知到该怎么建图,然 ...

  4. JS或jQuery实现一组复选框的全选和取消全选?

    //1.JS方式实现:checkbox 全选/取消全选  var isCheckAll = false;  function swapCheck() {    if (isCheckAll) {    ...

  5. HDU4278 Faulty Odometerd

    开始以为是容斥原理,想着做一下,应该是可以用容斥解决的,有空再过来写一下.题解是进制转换,开始没想到,不过很好理解. 如在10进制里: 1254=  (1*10^3 + 2*10^2 + 5* 10^ ...

  6. zoj3211dream city dp 斜率

    Dream City Time Limit: 1 Second      Memory Limit:32768 KB JAVAMAN is visiting Dream City and he see ...

  7. JS判断浏览器类型与版本

    在JS中判断浏览器的类型,估计是每个编辑过页面的开发人员都遇到过的问题.在众多的浏览器产品中,IE.Firefox.Opera.Safari........众多品牌却标准不一,因此时常需要根据不同的浏 ...

  8. Visual studio 创建项目失败vstemplate

    Visual studio 创建项目失败 提示 the vstemplate file references the wizard class 'Microsoft.VisualStudio.WinR ...

  9. 使用LINQ TO XML 创建xml文档,以及读取xml文档把内容显示到GridView例子

    首先,准备了一个Model类 using System; using System.Collections.Generic; using System.Linq; using System.Text; ...

  10. [hihoCoder]无间道之并查集

    题目大意: #1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之, ...