题目描述
定义一个日期类Date,包含数据成员year\month\day,还包含构造函数及其他函数(根据需要自己添加)
定义一个会员类VIP,包含数据成员id和birth,其中id是整数表示会员编号;birth是Date类型表示生日。
类VIP包含构造函数和其他函数(根据需要自己添加),还包含一个折扣函数Discount。函数Discount返回结果为浮点数表示折扣,函数包含1个参数为日期类型,函数功能是判断参数日期是否会员生日,是则折扣为0.5,不是则折扣为0.95
编写程序实现上述类功能并实现输入输出的要求
输入
第一行输入年、月、日,表示今天日期
第二行输入t表示有t个会员
第三行输入第1个会员的ID、生日的年、月、日
第四行输入第1个会员的消费金额
依次类推输入下一个会员的两行数据…
输出
根据会员的消费金额,调用Discount函数判断今天是否会员生日并得到折扣,然后计算会员打完折的消费金额
每一行先输出会员编号,再输出会员打完折的消费金额,消费金额只需要输出整数部分
提示把浮点数转整数
double x = 123.456
cout<<int(x)<<endl;
输入样例1
2017 4 20
2
1111 2000 4 20
136
2222 2000 3 30
125
输出样例1
1111’s consumption is 68
2222’s consumption is 118
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
class Date
{
private:
int year, month, day; //树龄
public:
Date(int yval, int mval, int dval) : year(yval), month(mval), day(dval){}; //构造函数
~Date(){};
int gety() { return year; };
int getm() { return month; };
int getd() { return day; };
};
class VIP
{
private:
int id;
Date birth;
public:
VIP(int idval, int yval, int mval, int dval) : id(idval), birth(yval, mval, dval){};
~VIP(){};
int getid() { return id; };
double Discount(Date date)
{
if (birth.getm() == date.getm() && birth.getd() == date.getd())
return 0.5;
else
return 0.95;
}
};
int main()
{
int y, m, d, idv;
cin >> y >> m >> d;
Date date(y, m, d);
int t;
cin >> t;
while (t--)
{
cin >> idv >> y >> m >> d;
VIP vip(idv, y, m, d);
double b = 0;
cin >> b;
double dis = vip.Discount(date);
cout << vip.getid() << "'s consumption is " << int(dis * b) << endl;
}
return 0;
}