【id:101】音像制品(类与对象)

题目描述

某商店出租音像制品,制品信息包括:类型、名称、租金单价、状态。

其中类型用单个数字表示,对应关系为:1-黑胶片(BF),2-CD,3-VCD,4-DVD

名称是字符串,存储制品的名称信息

租金单价表示每天租金价格

状态用单个数字表示,0是未出租(not rented),1是已出租(rented)

商店提供业务操作包括

1. 初始化(可使用构造函数或set方法),从键盘输入音像制品的信息,并设置到对象中

2. 查询Print,输出音像制品的信息

3. 计算租金Fee,参数是租借的天数,输出租金总价,如果未出租则提示,具体输出信息看示范

请定义音像制品类,并创建相应的对象来完成操作

题目涉及的数值均用整数处理

输入

第一行输入n表示有n个音像制品

每个音像制品对应两行输入

一行输入一个音像制品的多个参数,具体为:类型、名称、租金单价、状态

一行输入操作命令,如果输入为0表示查询操作,非0则表示查询并且计算租金费用,租用天数就是这个非0值

依次输入2n行

输出

根据每个音像制品的操作命令,调用相应的操作,然后输出相关结果

输出样式看示范。

输入样例:

4
1 AAA 43 1
0
2 BBB 19 0
3
3 CCC 27 1
5
4 DDD 32 1
7

输出样例:

BF[AAA]rented
CD[BBB]not rented
No rental
VCD[CCC]rented
Rental: 135
DVD[DDD]rented
Rental: 224

#include <iostream>
#include <string.h>
using namespace std; 
class Muc{
	char type;
	char name[100];
	int rent;
	int state;
	public:
		Muc(){}
		Muc(char type1, char name1[], int rent1, int state1){
				type=type1, strcpy(name, name1), rent=rent1, state=state1;
		}
		void print(){
			if(type=='1'){
				cout<<"BF["<<name<<"]";
			}
			else if(type=='2'){
				cout<<"CD["<<name<<"]";
			}
			else if(type=='3'){
				cout<<"VCD["<<name<<"]";	
			}
			else if(type=='4'){
				cout<<"DVD["<<name<<"]";
			}
		
			if(state==1)cout<<"rented"<<endl;
			else if(state==0)cout<<"not rented"<<endl;
			
		}
		void cele(int day){
			if(state==0)cout<<"No rental"<<endl;
			else if(state!=0)
			cout<<"Rental: "<<day*rent<<endl;
		}

		
};
int main()
{	
	int n;
	cin>>n;
	while(n--){
		char type, name[100];
		int rent, state;
		cin>>type>>name>>rent>>state;
		Muc p(type, name, rent, state);
		 int t;
		 cin>>t;
		 if(t==0){
		 	p.print();
		 } 
		else if(t!=0){
			p.print();
			p.cele(t);
		}
	}

	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

看未来捏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值