C++/Computer Studies pseudocode algorithm
Expert: vijayan - 5/27/2009
QuestionHi
i recently just wrote a computer studies exam where i was asked to write a simple algorithm in pseudocode with a question similar to the following: Create an algorithm that outputs daily flight details. Assuming the flight number format is like this: SW 333 (the first 2 letters stand for the airline name and it is followed by 3 random numbers), input all flight numbers and then output the total number of flights in a day by each of the three airlines: SW,KN,FA & the percentage total flights of each airline. Any validation rules for checking the flight numbers of each flight should be included in the algorithm.--- If you could please spot the correct loops for the algorithm it would be great. Thanks
AnswerYou require only one loop.
init:
sw_flights <- 0
kn_flights <- 0
fa_flights <- 0
loop:
try to read flight_number
if no more numbers exit loop
if first two chars are 'SW' increment sw_flights
else if first two chars are 'KN' increment kn_flights
else if first two chars are 'FA' increment fa_flights
else validation error
print_results:
total_flights <- sw_flights + kn_flights + fa_flights
print "#flights by SW is ", sw_flights, " percentage is ", sw_flights * 100 / total_flights
print "#flights by KN is ", kn_flights, " percentage is ", kn_flights * 100 / total_flights
print "#flights by FA is ", fa_flights, " percentage is ", sw_flights * 100 / total_flights