In: Computer Science
For each of the following problems provide: a. inputs b. outputs c. error conditions d. an algorithm using the pseudocode reference used in class e. a set of test cases. Be careful about corner cases f. the minimum number of operations executed in your algorithm g. the maximum number of operations executed in your algorithm
Q. Train Ticket for one person. Read a person’s age, then compute and display the price the person needs to pay for the train ride according to the following rules: Children younger than 7 years old ride for free. If the ticket is bought at the train station: A person over 65 years old pays $7.50. Everyone else pays $13.20. If ticket is bought inside the train, there is an extra charge of 20% compared to train station prices. Note that a persons’ age is within the range of 0 to 120 years. Other inputs are error conditions.
Please find the response below:
a,b) Set of inputs and outputs
Age (Input) |
Ticket Bought |
Fare ($) (Output) |
3 |
0 |
|
10 |
At train station |
13.20 |
50 |
At train station |
13.20 |
70 |
At train station |
7.5 |
10 |
Inside train |
15.84 |
50 |
Inside train |
15.84 |
70 |
Inside train |
9 |
c) Error Conditions:
Age : -1
Age : 121
Age: 200
d) Pseudo Algorithm
Input age
If age < 7
Fare = 0
Else
If age < 65
If Ticket Bought At
Station
Fare =
13.20
Else
Fare =
15.84
Else
If Ticket Bought At
Station
Fare = 7.5
Else
Fare = 9
Return Fare
e) Test Cases
Age |
Ticket Bought |
Fare($) |
6 |
0 |
|
7 |
At train station |
13.20 |
10 |
At train station |
13.20 |
50 |
At train station |
13.20 |
65 |
At train station |
13.20 |
66 |
At train station |
7.5 |
70 |
At train station |
7.5 |
10 |
Inside train |
15.84 |
50 |
Inside train |
15.84 |
65 |
Inside train |
15.84 |
70 |
Inside train |
9 |
f) Minimum number of operations in the algorithm
When age <7 = 4, number of operations = 4
g) Maximum number of operations in the algorithm
When age = 70, number of operations = 6