使用C++编写程序:
题目描述
某公园门票的票价是每人50元,一次购票满30张,每张可以少收2元。试编写自动计费系统程序。
输入
输入一个正整数,表示购票的数量。
输出
输出一个整数,表示用户实际需要支付的金额。
样例输入 Copy
30
样例输出 Copy
1440
程序代码如下:
#include<iostream>
#define ElemType unsigned
#define TicketPrice 50
using namespace std;
class TicketCharging
{
public:
TicketCharging(ElemType num) :Number(num) {};
void GetPaymentAmount();
private:
ElemType Number;
};
inline void TicketCharging::GetPaymentAmount()
{
if (Number < 30)
cout << fixed << TicketPrice * Number;
else
cout << fixed << (TicketPrice - 2)*Number;
}
int main()
{
ElemType Num;
cin >> Num;
TicketCharging T(Num);
T.GetPaymentAmount();
return 0;
}