输入分多行。
第一行是整数M>0,表示有M个测试用例。
每个测试占一行,分为三部分:第一部分是出版物类型(B表示Book,T表示Tape)、单价和数量(页数或分钟数)。
标签:string tput 图书 else inpu ica on() 计算书 book
某出版社可出版图书和磁带。其中图书按照每页的价格乘以页数进行定价,磁带根据每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中给出。
输入分多行。
第一行是整数M>0,表示有M个测试用例。
每个测试占一行,分为三部分:第一部分是出版物类型(B表示Book,T表示Tape)、单价和数量(页数或分钟数)。
见样例。
#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;}
};
标签:string tput 图书 else inpu ica on() 计算书 book
原文地址:http://www.cnblogs.com/masterchd/p/6770449.html