音像制品(类与对象)

音像制品(类与对象) 

时间限制1s

内存限制128MB

题目描述

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

其中类型用单个数字表示,对应关系为: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 "cstring"
using namespace std;

class info{
    char type1[4][30]={"BF","CD","VCD","DVD"};
    char *name1;
    int rate1;
    int state1;

public:
    void set(char *name,int rate,int state){
        name1=new char();
        strcpy(name1,name);
        rate1=rate;
        state1=state;

    }
    void display(int type,int ope,int state1);

};
void info::display(int type, int ope, int state1) {
    if(ope==0){
        if(state1==0) cout<<type1[type-1]<<"["<<name1<<"]not rented"<<endl;
        if(state1!=0) cout<<type1[type-1]<<"["<<name1<<"]rented"<<endl;
    }
    else{
        if(state1==0) cout<<type1[type-1]<<"["<<name1<<"]not rented\nNo rental"<<endl;
        if(state1!=0) {cout<<type1[type-1]<<"["<<name1<<"]rented"<<endl;
            cout<<"Rental:"<<' '<<ope*rate1<<endl;}

    }
}

int main() {
    int type, rate, state, ope;
    char name[30];
    info c;
    int t;
    cin >> t;
    while (t--) {
        cin >> type >> name >> rate >> state >> ope;
        c.set(name, rate, state);
        c.display(type, ope, state);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Canan猫

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

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

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

打赏作者

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

抵扣说明:

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

余额充值