You are here:

C++/Computer Studies pseudocode algorithm

Question
Hi
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

You require only one loop.

init:
sw_flights <- 0
kn_flights <- 0
fa_flights <- 0

loop:
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
Questioner's Rating
 Rating(1-10) Knowledgeability = 10 Clarity of Response = 10 Politeness = 10 Comment Thanks that helped. What i did in the exam was similar so hopefully ill get good marks :). Thanks for replying so quickly.

C++

Volunteer

vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.