PSUEDOCODE
main()
DISPLAY_TRAIN_TICKET
CALL menu()
CALL fare=price()
CALL paymentMethod()
Call display(fare)
END
menu()
SELECT_CHOICE
PROMPT and GET choice
CALL choice = errorchecking(input)
DOWHILE choice<1 OR choice>2
PROMPT and GET input
CALL choice = errorchecking(input)
ENDDO
IF choice==2
CALL exit()
ENDIF
END
price()
CALCULATE_PRICE
REPEAT
REPEAT
PROMPT and GET input
CALL selection_a = errorchecking(input)
CASEOF selection_a
1 : DISPLAY “Departure : Tai Pei”
Departure = 0
2 : DISPLAY “Departure : Ban Ciao”
Departure = 40
3 : DISPLAY “Departure : Tao Yuan”
Departure = 160
4 : DISPLAY “Departure : Hsin Chu”
Departure = 290
5 : DISPLAY “Departure : Tai Chung”
Departure = 700
6 : DISPLAY “Departure : Chia Yi”
Departure = 1080
7 : DISPLAY “Departure : Tai Nan”
Departure = 1350
8 : DISPLAY “Departure : Zuo Ying”
Departure = 1490
OTHER: DISPLAY “Invalid Selection”
ENDCASE
IF selection_a>0 AND selection_a<9
PROMPT and GET exit
ENDIF
UNTIL selection_a>0 OR selection_a<9 OR exit!=0
REPEAT
PROMPT and GET input
CALL selection_b = errorchecking(input)
CASEOF selection_a
1 : DISPLAY “Arrival: Tai Pei”
Arrival = 0
2 : DISPLAY “Arrival: Ban Ciao”
Arrival = 40
3 : DISPLAY “Arrival: Tao Yuan”
Arrival = 160
4 : DISPLAY “Arrival: Hsin Chu”
Arrival = 290
5 : DISPLAY “Arrival: Tai Chung”
Arrival = 700
6 : DISPLAY “Arrival: Chia Yi”
Arrival = 1080
7 : DISPLAY “Arrival: Tai Nan”
Arrival = 1350
8 : DISPLAY “Arrival: Zuo Ying”
Arrival = 1490
OTHER: DISPLAY “Invalid Selection”
ENDCASE
IF selection_b>0 AND selection_b<9
PROMPT and GET exit
ENDIF
UNTIL selection_b>0 OR selection_b<9 OR exit!=0
UNTIL selection_a != selection_b
CALCULATE fare = abs(arrival – departure)
CALL fare = age(fare)
CALL fare = traintype(fare)
CALL time(selection_a , selection_b)
RETURN fare
END
time(int selected_a, int selected_b)
CALCULATE_DURATION
CASEOF selected_a
1 : departure_hour_x = 0
departure_min_x = 0
*departureDestination = “Tai Pei”
2 : departure_hour_x = 0
departure_min_x = 15
*departureDestination = “Ban Ciao”
3 : departure_hour_x = 0
departure_min_x = 21
*departureDestination = “Tao Yuan”
4 : departure_hour_x = 0
departure_min_x = 33
*departureDestination = “Hsin Chu”
5 : departure_hour_x = 0
departure_min_x = 40
*departureDestination = “Tai Chung”
6 : departure_hour_x = 0
departure_min_x = 50
*departureDestination = “Chia Yi”
7 : departure_hour_x = 1
departure_min_x = 7
*departureDestination = “Tai Nan”
8 : departure_hour_x = 1
departure_min_x = 18
*departureDestination = “Zuo Ying”
ENDCASE
CASEOF selected_a
1 : arrival_hour_x = 0
arrival_min_x = 0
*departureDestination = “Tai Pei”
2 : arrival_hour_x = 0
arrival_min_x = 15
*arrivalDestination = “Ban Ciao”
3 : arrival_hour_x = 0
arrival_min_x = 21
* arrivalDestination = “Tao Yuan”
4 : arrival_hour_x = 0
arrival_min_x = 33
* arrivalDestination = “Hsin Chu”
5 : arrival_hour_x = 0
arriaval _min_x = 40
* arrivalDestination = “Tai Chung”
6 : arrival_hour_x = 0
arrival_min_x = 50
* arrivalDestination = “Chia Yi”
7 : arrival_hour_x = 1
arrival_min_x = 7
* arrivalDestination = “Tai Nan”
8 : arrival_hour_x = 1
arrival_min_x = 18
* arrivalDestination = “Zuo Ying”
ENDCASE
CALCULATE duration_hour = abs(arrival_hour_x – departure_hour_x)
CALCULATE duration_min = abs(arrival_min_x – departure_min_x)
REPEAT
PROMPT and GET input
CALL selection = errorchecking(input)
CASEOF selection
1 : departure_hour = 8
departure_min = 30
DISPLAY “Departure time : 0830 (GMT +8)”
2 : departure_hour = 13
departure_min = 30
DISPLAY “Departure time : 1330 (GMT +8)”
3 : departure_hour = 16
departure_min = 00
DISPLAY “Departure time : 1600 (GMT +8)”
4 : departure_hour = 20
departure_min = 30
DISPLAY “Departure time : 2030 (GMT +8)”
5 : departure_hour = 22
departure_min = 00
DISPLAY “Departure time : 2200 (GMT +8)”
OTHER: DISPLAY “Invalid Input”
ENDCASE
IF selection>0 AND selection<6
PROMPT and GET exit
UNTIL selection>0 OR selection<6 OR exit != 0
CALCULATE arrival_hour = departure_hour + duration_hour
CALCULATE arrival_min = departure_min + duration_min
IF arrival_min>60
CALCULATE arrival_min -60
CALCULATE arrival_hour +1
ENDIF
END
age(float fare)
CALCULATE_AGE
PROMPT and GET input
CALL childrenAge = errorchecking(input)
PROMPT and GET input
CALL adultAge = errorchecking(input)
PROMPT and GET input
CALL seniorAge = errorchecking(input)
CALCULATE discountPrice = (childrenAge*fare*0.8) + (adultAge*fare) + (seniorAge*fare*0.7)
CALCULATE totalpassenger = childrenAge + adultAge + seniorAge
END
traintype(float discountPrice)
SELECT_TRAIN_TYPE
REPEAT
PROMPT and GET input
CALL type = errorchecking(input)
CASEOF type
1 : CALCULATE price1 = discountPrice*2
2 : CALCULATE price1 = discountPrice * 1.5
3 : CALCULATE price1 = discountPrice
OTHER : DISPLAY “Invalid selection”
UNTIL type>=1 OR type<=3
REPEAT
PROMPT and GET input
CALL trip = errorchecking(input)
CASEOF trip
1 : CALCULATE newprice = price1*2
2 : CALCULATE newprice = price1
OTHER : DISPLAY “Invalid selection”
ENDCASE
UNTIL trip>=1 OR trip<=2
REPEAT
PROMPT and GET input
PROMPT and GET input
CALL select = errorchecking(input)
CASEOF select
1 : CALCULATE price2 = newprice*0.8
2 : CALCULATE price2 = newprice
OTHER : DISPLAY “Invalid selection”
ENDCASE
UNTIL select == 1 OR select == 2
RETURN price2
END
paymentMethod()
SELECT_PAYMENT_METHOD
REPEAT
PROMPT and GET input
CALL selection = errorchecking(input)
CASEOF selection
1 : *paymethod = “Paypal”
2 : *paymethod = “Online Banking”
3 : *paymethod = “Credit and Debit Card Payment”
ENDCASE
UNTIL selection<=3 OR selection>=1
END
display(float fare)
DISPLAY_TICKET_SUMMARY
DISPLAY arrivalDestination
DISPLAY departure_hour,departure_min
DISPLAY arrival_hour,arrival_min
DISPLAY fare
DISPLAY paymethod
DO x = 3 TO x <= totalpassenger
DISPLAY x
ENDDO
END
errorchecking(char x[99])
ERROR_CHECKING
CALL returnvalue = atoi(x)
END
SCREENSHOTS
![]() |
Main Menu |
![]() |
Choose Departure Destination |
![]() |
Choose Arrival Destination |
![]() |
Choose Departure Time |
![]() |
Choose the number of passenger according to the age |
![]() |
Choose Train Type |
![]() |
Choose Trip Type |
![]() |
Seasonal Promotion |
![]() |
Choose Payment Method |
![]() |
Ticket Summary and Provided Seat |
![]() |
Data Validation, if user entered other than 1 and 2, the system should be able to detect the error and allow user to enter the input again. |
![]() |
Data Validation, if the user entered both same departure and arrival destination, the system should able to detect the error and require the user to enter a valid destinations again.
|
Tiada ulasan:
Catat Ulasan