Photo AI

A travel company performs a search on a particular location and exports the following data about hotels to a text file - Scottish Highers Computing Science - Question 14 - 2019

Question icon

Question 14

A-travel-company-performs-a-search-on-a-particular-location-and-exports-the-following-data-about-hotels-to-a-text-file-Scottish Highers Computing Science-Question 14-2019.png

A travel company performs a search on a particular location and exports the following data about hotels to a text file. - Hotel name - Star rating from 1 to 5 - The... show full transcript

Worked Solution & Example Answer:A travel company performs a search on a particular location and exports the following data about hotels to a text file - Scottish Highers Computing Science - Question 14 - 2019

Step 1

IN: stars[], price[]

96%

114 rated

Answer

In step 2, the data flow will take the stars[] and price[] arrays as input. These arrays contain the star ratings and prices of the hotels imported previously. The output will include the position variable which will store the index of the cheapest five-star hotel, along with the hotelName[], stars[], price[], and reviews[], which will be maintained from previous steps.

Step 2

Step 2 finds the position of the cheapest hotel with five stars.

99%

104 rated

Answer

To find the position of the cheapest five-star hotel, we can use the following algorithm:

  1. Initialisation:

    • Set position to a suitable high value (like -1), which indicates that no position has been assigned yet.
    • Set lowest to a very high number to ensure that any room price will be lower.
  2. Loop through each hotel:

    • For each hotel, check if the stars rating is equal to 5.
    • If the current price is less than lowest, update lowest to the current price and set position to the index of this hotel.
  3. End Loop:

    • After looping through all hotels, the position will contain the index of the cheapest five-star hotel or -1 if none is found.

Join the Scottish Highers students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;