当前位置:网站首页>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;
}
}
边栏推荐
- 深度学习 简介
- Weekly Postgres world news 2022w02
- Review the SQL row column conversion, and the performance has been improved
- Xiaojinwei, chairman of Chenglian Technology: implement the national strategy of data economy and lead the development of new consumption in the digital era!
- 虫子 STM32 高级定时器 (哈哈我说实话硬件定时器不能体现实力,实际上想把内核定时器发上来的,一想算了,慢慢来吧)
- Implementation of VGA protocol based on FPGA
- 两招提升硬盘存储数据的写入效率
- Two ways to improve the writing efficiency of hard disk storage data
- flutter系列之:flutter中的Wrap
- linux下的开源数据库是什么
猜你喜欢

什么是元数据

Ideal car × Oceanbase: when new forces of car building meet new forces of database

How to ensure application security

在线JSON转CSharp(C#)Class工具

摆烂LuoGu刷题记

Efficient remote office experience | community essay solicitation

Halcon glue line detection - template matching, pose transformation, glue width, glue continuity detection

Cool mouse following animation JS plug-ins 5

QMainWindow

怎么用好MySQL索引
随机推荐
在word里,如何让页码从指定页开始编号
node+express如何操作cookie
mysql优化,sql执行非常卡顿,不改变sql结构达到10秒内结束
Bug STM32 interrupt (everyone knows)
在线文本过滤小于指定长度工具
Mysql, field problem
Section 2: spingboot unit test
怎么使用Shell脚本实现监测文件变化
无线网络安全的12个优秀实践
QMainWindow
PTA: Simulation Implementation of 7-87 set (class template)
The tax software exits when it detects that it is a virtual machine. How to solve this problem?
Two ways to improve the writing efficiency of hard disk storage data
Pyspark, paid for data cleaning and uploading to the database
mysql存储引擎之Myisam和Innodb的区别
photoshop PS 查看像素坐标、像素颜色、像素HSB颜色
bubble sort
leetcode 91. Decode ways (medium)
Software project management 8.4 Software project quality plan
Prince language on insect date class