当前位置:网站首页>PTA:7-58 图书音像出租管理
PTA:7-58 图书音像出租管理
2022-06-23 03:47:00 【Sy_Faker】
一个图书音像店出租图书和磁带。
给出下面一个基类的框架:
class Publication
{
protected:
string title;//名称
float price;//原价
int day;//租期
public:
virtual void display()=0;//打印价格清单
}
以Publication为基类,构建Book和Tape类。
生成上述类并编写主函数,要求主函数中有一个基类Publication指针数组,数组元素不超过10个。
Publication pp[10];
主函数根据输入的信息,相应建立Book, Tape类对象。
它们的原始租金为:租期1.2。
另外,实际收取的租金不超过2倍的租品估价。
Book的估价为:新旧程度*原价。
Tape的估价为:原价/(1+已出租次数/3)。
输入格式:每个测试用例占一行,第一项为租品类型,1为Book,2为Tape.接下来为名称、原价、租期。最后一项Book是新旧程度(0.1至1),Tape是已出租次数。以0表示输入的结束。
要求输出名称,原始租金(小数点后保留1位小数),如果原始租金大于2倍租品估价,则同时给出实际应收取的租金(小数点后保留1位小数),并在最后标明R。
输入样例
1 AAA 19.5 3 0.5
1 BBB 9.5 2 0.1
2 AA 10 2 0
2 DDDD 12.5 2 38
1 FFF 42 3 0.1
0
输出样例
AAA 3.6
BBB 2.4 1.9 R
AA 2.4
DDDD 2.4 1.8 R
FFF 3.6
#include<iostream>
using namespace std;
class Publication
{
protected:
string title;//名称
float price;//原价
int day;//租期
public:
Publication()
{
;
}
Publication(string n,float p,int d)
{
title=n;
price=p;
day=d;
}
virtual void display()=0;//打印价格清单
};
class Book:public Publication
{
double k;
public:
Book(string n,float p,int d,double q):Publication(n,p,d)
{
k=q;
}
virtual void display()
{
cout<<title<<" ";
printf("%.1f",day*1.2);
if(day*1.2>price*k*2)
printf(" %.1f R",price*k*2);
cout<<endl;
}
};
class Tape:public Publication
{
int k;
public:
Tape(string n,float p,int d,int q):Publication(n,p,d)
{
k=q;
}
virtual void display()
{
cout<<title<<" ";
printf("%.1f",day*1.2);
if(day*1.2>(price/(k/3+1))*2)
printf(" %.1f R",(price/(k/3+1))*2);
cout<<endl;
}
};
int main()
{
int type;
cin>>type;
string n;
float p;
int d;
double q1;
int q2;
for(int i=0;type!=0;i++)
{
Publication *pp;
cin>>n>>p>>d;
if(type==1)
{
cin>>q1;
pp=new Book(n,p,d,q1);
}
else
{
cin>>q2;
pp=new Tape(n,p,d,q2);
}
pp->display();
delete pp;
cin>>type;
}
}
边栏推荐
- Idea import module
- Getting started with tensorflow
- [Shangshui Shuo series] day three - preview4
- 虫子 日期类 上 太子语言
- 浅析2022年物联网现状
- AI video cloud: a good wife in the era of we media
- Why APP But Not WebPage
- PTA: Simulation Implementation of 7-87 set (class template)
- Adobe international certification 𞓜 how IIT Madras brings efficiency and accessibility to scholars through Adobe e Acrobat
- PTA:7-69 数据的间距问题
猜你喜欢

会话和守护进程

在线文本过滤小于指定长度工具

Pytorch---Pytorch进行自定义Dataset

【一起上水硕系列】Day Three - preview4

浅析2022年物联网现状

Introduction to deep learning

QMainWindow

Software development in 2022: five realities CIOs should know

怎么使用Shell脚本实现监测文件变化

Halcon glue line detection - template matching, pose transformation, glue width, glue continuity detection
随机推荐
Two ways to improve the writing efficiency of hard disk storage data
Common events for elements
背景彩带动画插件ribbon.js
电商如何借助小程序发力
[tcapulusdb knowledge base] [list table] sample code of asynchronous scanning data
P1347 sorting (TOPO)
[deep learning] deep learning reasoning framework tensorrt MNN openvino onnxruntime
node+express如何操作cookie
Compilation, installation and global configuration section description of haproxy
What is metadata
PTA: Simulation Implementation of 7-86 set (function template)
[tcapulusdb knowledge base] [list table] example code for replacing the data at the specified location in the list
bubble sort
[advanced binary tree] AVLTree - balanced binary search tree
【一起上水硕系列】Day Three - preview4
Pytorch---Pytorch进行自定义Dataset
Pta:7-85 data spacing (overload + function template)
Full analysis of embedded software testing tool tpt18 update
mysql优化,sql执行非常卡顿,不改变sql结构达到10秒内结束
怎么使用Shell脚本实现监测文件变化