PTA:7-58 图书音像出租管理

一个图书音像店出租图书和磁带。
给出下面一个基类的框架:
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;
	}
}
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值