You are here:

C++/Computer Studies pseudocode algorithm

Advertisement


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

Answer
You 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  

C++

All Answers


Answers by Expert:


Ask Experts

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.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.