贵州大学oj C++ 第五次 10.顾客积分计算

记录学习日常 代码可能有错 大家多多包涵 有好的建议提出的话 我会开心接纳 初学阶段 

​定义一个抽象的顾客类Customer,该类有一个数据成员:points(积分,double型),用于存储顾客的积分。该类还有一个纯虚函数recordPoints(记录积分函数),用于根据顾客每次的购物金额(即该纯虚函数的参数)为顾客增加相应积分,积分计算的规则如下:

(A)普通顾客,每次购物后积分增加的值为此次购物金额*0.20;

(B)会员顾客,每次购物后积分增加的值为此次购物金额*0.30;

(C)VIP会员顾客,每次购物后积分增加的值为会员顾客增加的积分再上浮20%。

请根据以上描述完成下面的任务:

(1)请完成Customer类的定义,包括你认为必要的任何成员函数。

 

为了满足用户的需求,以下是一个贵州大学 OJ 平台上面向对象编程第八次作业内容相关的题目及答案。该题目涉及使用虚函数和抽象的概念。 ### 题目描述 编写一个抽象 `Shape`,在此基础上派生出两个子 `Rectangle`(长方形)和 `Circle`(圆)。这两个需要实现计算面积的函数 `getArea()` 和计算周长的函数 `getPerim()`。 为了避免精度问题,取圆周率 π=3。 --- ### 代码实现 ```cpp #include <bits/stdc++.h> using namespace std; // 抽象 Shape class Shape { public: virtual int getArea() = 0; // 纯虚函数,获取面积 virtual int getPerim() = 0; // 纯虚函数,获取周长 }; // Rectangle 继承自 Shape class Rectangle : public Shape { private: int length, width; public: Rectangle(int l, int w) : length(l), width(w) {} int getArea() override { return length * width; } int getPerim() override { return 2 * (length + width); } }; // Circle 继承自 Shape class Circle : public Shape { private: int radius; public: Circle(int r) : radius(r) {} int getArea() override { return 3 * radius * radius; // π = 3 } int getPerim() override { return 2 * 3 * radius; // π = 3 } }; // 主函数 int main() { int x, y, r; cin >> x >> y >> r; Shape* shape = new Rectangle(x, y); cout << shape->getArea() << '-' << shape->getPerim() << " "; shape = new Circle(r); cout << shape->getArea() << '-' << shape->getPerim() << " "; delete shape; // 释放内 return 0; } ``` --- ### 示例输入输出 **输入:** ``` 5 3 4 ``` **输出:** ``` 15-16 48-24 ``` **解释:** - 长方形的长为 5,宽为 3: - 面积 = 5 × 3 = 15 - 周长 = 2 × (5 + 3) = 16 - 圆的半径为 4: - 面积 = 3 × 4² = 48 - 周长 = 2 × 3 × 4 = 24 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值