当前位置:网站首页>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;
}
}
边栏推荐
- P1347 sorting (TOPO)
- What is the digital "true" twin? At last someone made it clear!
- AI video cloud vs narrowband HD, who is the favorite in the video Era
- [greed] leetcode991 Broken Calculator
- leetcode 91. Decode Ways 解码方法(中等)
- mysql优化,sql执行非常卡顿,不改变sql结构达到10秒内结束
- Prince language on insect date class
- 基于HAProxy实现网页动静分离
- How to solve the problem that the web page fails to log in after the easycvr service is started?
- 【二叉樹進階】AVLTree - 平衡二叉搜索樹
猜你喜欢

There is a problem with redis startup

How to make the page number start from the specified page in word

背景彩带动画插件ribbon.js

Idea import module

Svg+js smart home monitoring grid layout

A summary of PostgreSQL data types. All the people are here

Pytorch---Pytorch进行自定义Dataset

京东云分布式数据库StarDB荣获中国信通院 “稳定性实践先锋”

【深度学习】深度学习推理框架 TensorRT MNN OpenVINO ONNXRuntime

会话和守护进程
随机推荐
静态查找表和静态查找表
如何保证应用程序的安全性
PTA: Simulation Implementation of 7-87 set (class template)
How e-commerce makes use of small programs
JD cloud distributed database stardb won the "stability practice pioneer" of China Academy of information technology
Form development mode
怎么用好MySQL索引
Idea import module
PTA: Simulation Implementation of 7-86 set (function template)
Xiaojinwei, chairman of Chenglian Technology: implement the national strategy of data economy and lead the development of new consumption in the digital era!
【二叉树进阶】AVLTree - 平衡二叉搜索树
Review the SQL row column conversion, and the performance has been improved
【深度学习】深度学习推理框架 TensorRT MNN OpenVINO ONNXRuntime
深度学习 简介
Full analysis of embedded software testing tool tpt18 update
在 KubeSphere 上部署 Apache Pulsar
Bug STM32 advanced timer (haha, to tell you the truth, the hardware timer can't reflect its strength. In fact, I want to send the kernel timer. Just think about it. Take your time)
背景彩带动画插件ribbon.js
Preface
photoshop PS 查看像素坐标、像素颜色、像素HSB颜色