C++|【20分】D. 商旅信用卡(多重继承)

该文描述了一个旅游网站与银行合作推出的旅程信用卡系统,包括旅程会员卡、信用卡的功能以及衍生出的旅程信用卡。用户可通过输入卡信息和操作指令(如下单、消费、退款、积分兑换)来执行相应操作。文章提供了一段示例代码实现这些功能。


一、题目描述

某旅游网站(假设旅程网)和某银行推出旅游综合服务联名卡—旅程信用卡,兼具旅程会员卡和银行信用卡功能。

旅程会员卡,有会员卡号(int)、旅程积分(int),通过会员卡下订单,按订单金额累计旅程积分。

信用卡,有卡号(int)、姓名(string)、额度(int)、账单金额(float)、信用卡积分(int)。------请注意数据类型

信用卡消费金额m,若超额度,则不做操作;否则,账单金额+m,额度-m,信用卡积分按消费金额累加。

信用卡退款m,账单金额-m,信用卡积分减去退款金额。

通过旅程信用卡在旅程网下单,旅程积分和信用卡积分双重积分(即旅程积分和信用卡积分同时增加)。

旅程信用卡可以按 旅程积分:信用卡积分= 1:2 的比例将信用卡积分兑换为旅程积分。

初始假设信用卡积分、旅程积分、账单金额为0。

根据上述内容,定义旅程会员卡类、信用卡类,从两者派生出旅程信用卡类并定义三个类的构造函数和其它所需函数。

生成旅程信用卡对象,输入卡信息,调用对象成员函数完成旅程网下单、信用卡刷卡、信用卡退款、信用卡积分兑换为旅程积分等操作。


二、输入与输出

1.输入

第一行:输入旅程会员卡号 信用卡号 姓名 额度

第二行:测试次数n

第三行到第n+2行,每行:操作 金额或积分

o m(旅程网下订单,订单金额m)

c m(信用卡消费,消费金额m)

q m (信用卡退款,退款金额m)

t m(积分兑换,m信用卡积分兑换为旅程积分)

1000 2002  lili  3000
4
o 212.5
c 300
q 117.4
t 200


2.输出

输出所有操作后旅程信用卡的信息:

旅程号 旅程积分

信用卡号 姓名 账单金额 信用卡积分

1000 312
2002 lili 395.1 195

三、参考代码

#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;

class vip
{
protected:
	int no1;
	int sco;
public:
	vip(int n1) :no1(n1), sco(0) {};
	void display()
	{
		cout << no1 << " " << sco << endl;
	}
};
class credit
{
protected:
	int no2;
	string name;
	int balance;
	float mon;
	int sco;
public:
	credit(int n2,string n,int ba):no2(n2),name(n),balance(ba),mon(0),sco(0){}
	void display()
	{
		cout << no2 << " " << name << " " << mon << " " << sco << endl;
	}
};
class mycard :public vip, public credit
{
public:
	mycard(int n1,int n2,string n,int ba):vip(n1),credit(n2,n,ba){}
	void o()
	{
		float num;
		cin >> num;
		if (num + mon > balance)
		{
			return;
		}
		else 
		{
			mon += num;
			vip::sco += (int)num;
			credit::sco += (int)num;
		}
	}
	void c()
	{
		float num;
		cin >> num;
		if (num + mon > balance)
		{
			return;
		}
		else
		{
			mon += num;
			credit::sco += (int)num;
		}

	}
	void q()
	{
		float num;
		cin >> num;
		credit::sco -=(int)num;
		mon -= num;
	}
	void t()
	{
		float num;
		cin >> num;
		credit::sco -= (int)num;
		vip::sco += (int)num / 2;
	}
	void display()
	{
		vip::display();
		credit::display();
	}
};
int main()
{
	int no1, no2, ba;
	string name;
	int sum;
	char ch;
	cin >> no1 >> no2 >> name >> ba;
	cin >> sum;
	mycard a(no1, no2, name, ba);
	while (sum--)
	{
		cin >> ch;
		switch (ch)
		{
		default:
			break;
		case'o': 
			a.o();
			break;
		case'c': 
			a.c();
			break;
		case'q': 
			a.q();
			break;
		case't': 
			a.t();
			break;

		}
	}
	a.display();
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Z1Jxxx

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

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

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

打赏作者

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

抵扣说明:

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

余额充值