Week 8 Lab Wed
Session A: Lab Assignment
Problem 1 (100 points):
The frequent flyer rewards program allows customer to earn
points for every dollar spent on the flight ticket and then use
rewards points for future ticket purchases. The amount and type
of fare customer chooses determines how many points customer
earns. For Business Fare, customers earn 12 points per dollar
and for Coach Fare customers earn 10 points per dollar. For
example, if the business fare ticket cost $220, customer will
earn 12*220 = 2640 points for that flight.
Write a function flight_points that has two parameters:
ticket_price and the fare_indicator
(the integer 1 or 2, where 1 indicates business fare and
2 coach fare). The function returns the number of points
customer earned for the flight.
Assume that the customer
purchased 3 flights in one year. Write a program that reads
ticket price (INTEGER) and flight indicator (INTEGER) for each flight. Use
function
flight_points to find the
number of points customer earned for each flight, and then
determine if the customer is eligible for free domestic flight
or free international flight. Use the following rule: free
international flight cost 60000 points and free domestic flight
cost 35000 points.
The program MUST print the number of points for EACH
flight, TOTAL number of points for three flights and the message indicating
eligibility for free ticket. Assume that input is VALID
Example:
Input: 1500 1 2200 1 500 2
Output:
points for flight1: 18000
points for flight2: 26400
points for flight3: 5000
Total points:49400
Eligible for domestic free flight, NOT eligible for international free
flight
Session B: Lab Practice
- Problem 1
- Problem 2:
Write a function FtoC that converts Fahrenheit temperature to
Celsius temperature.
The equation for converting a Fahrenheit to Celsius is:
- Celsius= (5/9)*(Fahrenheit - 32)
Write a function CtoF that
converts Celsius
temperature to the correspondent Fahrenheit
temperature.
The equation for converting a Celsius temperature to
Fahrenheit is
Fahrenheit=(9*Celsius/5)+32
Write a program that asks user to enter Fahrenheit temperature for TWO
days
and finds the corresponding Celsius
temperatures for these two days. Then the program will ask user to enter
Celsius temperature for TWO days and
finds the corresponding Fahrenheit temperature for these TWO days.
- Problem 3: Write a function aveDigits that finds and RETURNS an
average of the
digits of the 4-digit positive integer (function parameter). Write a
function average that
finds and RETURNS an average of three integer numbers (function
parameters). Write a function
aveLast that finds and RETURNS an average of the last digits of three
integer numbers (function parameters). Write a program that first reads 1
integer, if the
integer is positive and even, the program reads 3 integers and finds their
average. If the number is positive and odd, the program reads 3 integers
and finds the average of their last digits, otherwise, the program asks
user to enter one 4-digit integer number and finds the average of the
digits of the input number.