Problem-G-来开个书店吧.docx_第1页
Problem-G-来开个书店吧.docx_第2页
Problem-G-来开个书店吧.docx_第3页
Problem-G-来开个书店吧.docx_第4页
Problem-G-来开个书店吧.docx_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Problem G 来开个书店吧Time Limit:1 SecMemory Limit:128 MBSubmit:815Solved:424SubmitStatusWeb BoardDescription某出版社可出版图书和磁带。其中图书按照每页的价格乘以页数进行定价,磁带根据每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输入分多行。第一行是整数M0,表示有M个测试用例。每个测试占一行,分为三部分:第一部分是出版物类型(B表示Book,T表示Tape)、单价和数量(页数或分钟数)。Output见样例。Sample Input3B 0.10 201T 0.50 100T 0.40 105Sample OutputCall Publications constructor!Call Books constructor!Call Publications constructor!Call Tapes constructor!Call Publications constructor!Call Tapes constructor!Call Publications constructor!Call Books constructor!Call Publications constructor!Call Tapes constructor!Call Publications constructor!Call Tapes constructor!There are 1 books and 2 tapes. Their total price is 29.50.Call Books de-constructor!Call Publications de-constructor!Call Tapes de-constructor!Call Publications de-constructor!Call Tapes de-constructor!Call Publications de-constructor!Call Books de-constructor!Call Publications de-constructor!Call Tapes de-constructor!Call Publications de-constructor!Call Tapes de-constructor!Call Publications de-constructor!Call BookStores de-constructor!HINT使用typeid判断对象指针指向的实际对象的类型。Append Code#include#include#includeusing namespace std;class Publicationprotected:double price;int length;public:Publication(double p,int l):price(p),length(l)coutCall Publications constructor!endl;virtual Publication()coutCall Publications de-constructor!endl;virtual double getTotalPrice()return price*length;double getPrice() constreturn price;int getLength()return length;class Book:public Publicationpublic:Book(double p,int l):Publication(p,l)coutCall Books constructor!endl;Book()coutCall Books de-constructor!endl;double getTotalPrice()return price*length;class Tape:public Publicationpublic:Tape(double p,int l):Publication(p,l)coutCall Tapes constructor!endl;Tape()coutCall Tapes de-constructor!0)tmp+;return tmp*price;class BookStoreprivate:Publication *pubs;int num;public:BookStore(Publication *p, int n)pubs = new Publication*n;num = n;for (int i = 0; i getPrice(), pi-getLength();elsepubsi = new Tape(pi-getPrice(), pi-getLength();int getNumOfBook()int c = 0;for (int i = 0; i num; i+)if (typeid(*(pubsi) = typeid(Book)c+;return c;int getNumOfTape()int c = 0;for (int i = 0; i num; i+)if (typeid(*(pubsi) = typeid(Tape)c+;return c;BookStore()for (int i = 0; i num; i+)delete pubsi;delete pubs;coutcases;pub = new Publication*cases;for (int i = 0; i typepricedate;switch(type)case B:pubi = new Book(price,date);break;case T:pubi = new Tape(price,date);break;BookStore bookStore(pub, cases);coutThere are bookStore.getNumOfBook() books and bookStore.getNumOfTape

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论