Docsity

CS1371 - Computing for Engineers Test 1 Version D Problem 3 Solution: busFare Function - P, Exams of Computer Science

Toggle sidebar
bg1
CS1371 - Computing for Engineers Test 1 Version D September 20th, 2006
Problem 3 – Functions [20 Points]
Write a function called busFare that returns the type of ticket issued and the fare for that
ticket. The function takes in the number of stops that the person wishes to travel and
calculates the type of ticket issued and the fare according to the following classifications:
If the number of stops >=1 and <=3: Type: ‘Type 1’ Fare: $1.00
If the number of stops >=4 and <=6: Type: ‘Type 2’ Fare: $2.25
If the number of stops >=7 and <=10: Type: ‘Type 3’ Fare: $3.00
If the number of stops >=11 Type: ‘Type 4’ Fare: $4.00
Example: [type, fare] = busFare(7)
Returns: type = ‘Type 3’
fare = 3
Page 6 of 9

Partial preview of the text

Download CS1371 - Computing for Engineers Test 1 Version D Problem 3 Solution: busFare Function - P and more Exams Computer Science in PDF only on Docsity!

CS1371 - Computing for Engineers Test 1 Version D September 20th, 2006

Problem 3 – Functions [20 Points]

Write a function called busFare that returns the type of ticket issued and the fare for that ticket. The function takes in the number of stops that the person wishes to travel and calculates the type of ticket issued and the fare according to the following classifications: If the number of stops >=1 and <=3: Type: ‘Type 1’ Fare: $1. If the number of stops >=4 and <=6: Type: ‘Type 2’ Fare: $2. If the number of stops >=7 and <=10: Type: ‘Type 3’ Fare: $3. If the number of stops >=11 Type: ‘Type 4’ Fare: $4. Example: [type, fare] = busFare(7) Returns: type = ‘Type 3’ fare = 3 Page 6 of 9