Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Imagine a gas station that offers a rewards card program. When a customer buys gas, he or she is rewarded with rewards points that can
Imagine a gas station that offers a rewards card program. When a customer buys gas, he or she is rewarded with rewards points that can be used to purchase other goods. Write a function gas reward ) that takes the following arguments, in this order: 1. current-point s: the current rewards points (an integer) on the customer's gas rewards card 2. gas.type: the type of gasoline purchased (a string), which is one of the following Regular": $2.65 / gallon .Plus'$2.90/ gallon Premium $3.10/ gallon 3. money.spent: the amount of dollars spent on gas for a particular transaction. This number is needed to compute how many gallons of gas were purchased As previously mentioned, after each gas refill, the customer gets a certain amount of rewards points. The function calculates and returns the updated, new total rewards points of the customer. The rewards rules are as follows: 1. Normally, 5 points are rewarded for every ull dollar spent. For example, $6.83 spent will result in 5x6=30 new reward points. Hint: given a floating-point variable x, the code int (x) will truncate x, thereby giving only the integer part of x: integer-part int (x) 2. If at least 10 gallons of gas were purchased, the customer will be rewarded 200 reward points 3. If at least 15 gallons of gas were purchased, the customer will be rewarded 400 reward points 4. If at least 20 gallons of gas were purchased, the customer will be rewarded 550 reward points Note: Only one of the above rules can be applied per transaction. For example, if a customer bought 16 gallons of gas, he/she will get 400 and only 400 reward points. Rule 1 is applied for purchases of less than 10 gallons. Special Cases: Below are some special cases that the function must handle. Your code should check for these special cases in this order CSE 101 - Spring 2018 Homework #2 Page 2 . If money.spent is less than one dollar, this is considered an invalid transaction, and the function returns . If current points is less than 0, this is considered a faulty account, and the function returns error' . If gas.type is not one of the three kinds provided, this means it's not available, and the function returns current-points (a string) 'unavailable' (a string). Examples: Return Value 2545 Function Call gas.reward (1995, 'Regular,74.95480578251386) gas.reward (870, Regular, -23.705557429821557) 870 gas.reward (3054, Good', 27.80750330446164) gas.reward (4933, Plus', 76.8553245 6142764) gas.reward (393, 'Regular, 7.2454530 64858392) gas-reward (1981, Plus',5.83 8288853611488) ' unavailable 5483 393 2006
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started