当前位置:网站首页>Pta:7-58 Book audio-visual rental management
Pta:7-58 Book audio-visual rental management
2022-06-23 04:38:00 【Sy_ Faker】
A book and video store rents books and tapes .
Give the following framework for a base class :
class Publication
{
protected:
string title;// name
float price;// The original price
int day;// Lease term
public:
virtual void display()=0;// Print price list
}
With Publication Base class , structure Book and Tape class .
Generate the above class and write the main function , The main function is required to have a base class Publication Pointer array , Array elements do not exceed 10 individual .
Publication pp[10];
The main function is based on the input information , Corresponding establishment Book, Tape Class object .
Their original rent is : Lease term 1.2.
in addition , The actual rent charged does not exceed 2 Times the rental valuation .
Book Our valuation is : Old and new * The original price .
Tape Our valuation is : The original price /(1+ Number of rentals /3).
Input format : One line per test case , The first item is the type of rent ,1 by Book,2 by Tape. Next is the name 、 The original price 、 Lease term . Last item Book Is the degree of newness (0.1 to 1),Tape Is the number of times it has been rented . With 0 Indicates the end of the input .
Output name required , Original rent ( After the decimal point 1 Decimal place ), If the original rent is greater than 2 Double rent valuation , At the same time, the actual rent that should be charged ( After the decimal point 1 Decimal place ), And marked at the end R.
sample input
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
sample output
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;// name
float price;// The original price
int day;// Lease term
public:
Publication()
{
;
}
Publication(string n,float p,int d)
{
title=n;
price=p;
day=d;
}
virtual void display()=0;// Print price list
};
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;
}
}
边栏推荐
猜你喜欢

城链科技董事长肖金伟:践行数据经济系国家战略,引领数字时代新消费发展!

Basic skills of x64dbg
![[pytoch] calculate the derivative of sin (x) by automatic differentiation](/img/a7/16dd9ecc13a986a9141ecc3fba00a1.png)
[pytoch] calculate the derivative of sin (x) by automatic differentiation

Deploying Apache pulsar on kubesphere

大一学生课设c——服装管理系统

Online text filter less than specified length tool

Code refactoring Guide

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

Mobile terminal city list sorting JS plug-in vertitylist js

Inscription of lougu brush
随机推荐
Pta:6-73 function call
众昂矿业:新能源新材料产业链对萤石需求大增
PTA:7-37 学号解析
【深度学习】深度学习推理框架 TensorRT MNN OpenVINO ONNXRuntime
How to use MySQL index well
Fundamentals of 3D mathematics [16] formulas for uniformly accelerated linear motion
Background ribbon animation plug-in ribbon js
Does the network disk also roll inside?
国家药品不良反应监测中心 ADR 电子传输EDI解决方案
Halcon知识:binocular_disparity 知识
Zhongang Mining: the demand for fluorite in the new energy and new material industry chain has increased greatly
Sequence table lookup
leetcode 91. Decode Ways 解码方法(中等)
[multimode] unimo
How node+express operates cookies
Online text filter less than specified length tool
Sessions and Daemons
Avltree - arbre de recherche binaire équilibré
距离度量 —— 余弦距离(Cosine Distance)
Inscription of lougu brush