关于此题的相关知识点以及更多题目,请查看👇
【C++学习】【持续更新 】史上最全C++学习总结(知识点+OJ练习讲解)
题目描述
某商店出租音像制品,制品信息包括:类型、名称、租金单价、状态。
其中类型用单个数字表示,对应关系为:1-黑胶片,2-CD,3-VCD,4-DVD
名称是字符串,存储制品的名称信息
租金单价表示每天租金价格
状态用单个数字表示,0是未出租,1是已出租
商店提供业务操作包括
-
初始化(可使用构造函数或set方法),从键盘输入音像制品的信息,并设置到对象中
-
查询Print,输出音像制品的信息
-
计算租金Fee,参数是租借的天数,输出租金总价,如果未出租则提示,具体输出信息看示范
请定义音像制品类,并创建相应的对象来完成操作
题目涉及的数值均用整数处理
输入
第一行输入n表示有n个音像制品
每个音像制品对应两行输入
一行输入一个音像制品的多个参数,具体为:类型、名称、租金单价、状态
一行输入操作命令,如果输入为0表示查询操作,非0则表示查询并且计算租金费用,租用天数就是这个非0值
依次输入2n行
输出
根据每个音像制品的操作命令,调用相应的操作,然后输出相关结果
输出样式看示范。
输入样例1
4
1 AAA 43 1
0
2 BBB 19 0
3
3 CCC 27 1
5
4 DDD 32 1
7
输出样例1
黑胶片[AAA]已出租
CD[BBB]未出租
未产生租金
VCD[CCC]已出租
当前租金为135
DVD[DDD]已出租
当前租金为224
#include <iostream>
#include <cstring>
#include<iomanip>
#include<cmath>
using namespace std;
class Video
{
private:
int type;
char name[20];
int price;
int state;
public:
void set(int t,char* n,int p,int s)
{
type = t;
strcpy(name,n);
price = p;
state = s;
}
void Print()
{
if(state == 0)
{
if(type == 1)
cout << "黑胶片[" << name <<"]未出租"<<endl;
else if(type == 2)
cout << "CD[" << name <<"]未出租"<<endl;
else if(type == 3)
cout << "VCD[" << name <<"]未出租"<<endl;
else if(type == 4)
cout << "DVD[" << name <<"]未出租"<<endl;
}
else if(state == 1){
if(type == 1)
cout << "黑胶片[" << name <<"]已出租"<<endl;
else if(type == 2)
cout << "CD[" << name <<"]已出租"<<endl;
else if(type == 3)
cout << "VCD[" << name <<"]已出租"<<endl;
else if(type == 4)
cout << "DVD[" << name <<"]已出租"<<endl;
}
else{
cout << "error!"<<endl;
}
}
int Fee(int day)
{
return price*day;
}
};
int main()
{
Video v;
int type;
char name[20];
int price;
int state;
int cmd;
int n;
cin >> n;
while(n--)
{
cin >> type >> name >> price >> state;
v.set(type,name,price,state);
cin >> cmd;
if(cmd == 0){
v.Print();
}
else{
v.Print();
if(state == 0)
cout << "未产生租金"<<endl;
else
cout << "当前租金为"<<v.Fee(cmd)<<endl;
}
}
return 0;
}