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 14
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To find the position of the cheapest five-star hotel, we can use the following algorithm:
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.
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.
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...