What email address or phone number would you like to use to sign in to Docs.com?
If you already have an account that you use with Office or other Microsoft services, enter it here.
Or sign in with:
Signing in allows you to download and like content, and it provides the authors analytical data about your interactions with their content.
Embed code for: HolidayDetailsFadedWELivecode
Select a size
Higher Computing Science
Software Design and Development
Programming Algorithms: Reading Code
Holiday Details v1
Write a program to provide details of holidays. The program should import from a text file the details of each holiday (resort, country and price) and display those details in a neat, 3 column table. The program should work out which holiday is the most expensive. Output from the program should display:
the details of each holiday
details of the most expensive holiday
Holiday Details v2
Extend the holiday details program to include an additional module. This additional module should count the number of holidays with (1) destinations in the USA and (2) the number of holidays with destinations in France or Spain. Output from the program should display:
the number of holidays with destinations in the US
the number of holidays with destinations in France or Spain
Details of each holiday
(resort, country and cost) from text file
Enter details of each holiday
Display details of each holiday
Work out which is the most expensive holiday
Display details of the most expensive holiday
Details of each holiday (resort, country and cost)
Details of the most expensive holiday (resort, country and cost)
1. declare variables to be used in program
2. initialise variables OUT: resort, country, cost, numberHolidays
3. import holiday details data flow
4. display holiday details data flow
5. work out and display most expensive holiday data flow
Refine Step 3
3.1 procedure importDetails data flow
3.2 declare local variable for loop and array index
3.3 declare local variable for file data
3.4 open file for read
3.5 read data from file until end of file is reached
3.6 store file data
3.7 start loop from 1 to 3
3.8 store word 1, 4, 7, … in resort array
3.9 store word 2, 5, 8, … in country array
3.10 store word 3, 6, 9, … in cost array
3.11 end loop
Refine Step 4
Refine Step 5
// procedure used to activate all process associated with this mouseUp event
// declare local variables
local resort = “” // string array used to store list of resorts
local country = “” // string array used to store list of countries
local cost =0.0 // real array used to store list of costs
local numberHolidays = 0 // integer variable to store number of holidays in file
set the defaultfolder to get_file_folder()
// activate processes
importDetails resort, country, cost, numberHolidays
displayDetails resort, country, cost, numberHolidays
mostExpensive resort, country, cost, numberHolidays
countDestinations country, numberHolidays
put the effective filename of this stack into tPath
set the itemDelimiter to slash
delete last item of tPath
code at lines 21 – 26 defines procedures importDetails and displayDetails
on mostExpensive hResort, hCountry, hCost, nHolidays
// procedure used to work out which holiday is the most expensive
local dearest // integer used to store index of most expensive holiday
local counter // integer variable used as loop and array index
// assign index of the expensive holiday to 1
put 1 into dearest
// use fixed loop to compare cost each holiday with most expensive holiday
repeat with counter = 2 to nHolidays
// update index of most expensive holiday if more expensive holiday is found
if hCost[counter] > hCost[dearest] then put counter into dearest
// display details of the most expensive holiday using dearest index
put "The most expensive holiday is to" && hResort[dearest] & "," && hCountry[dearest] && "and costs £" && hCost[dearest] & return after field "output"
on countDestinations hCountry, nHolidays
// procedure used to calculate the number of holidays to USA and to France or Spain
// declare local variables used in the procedure
local counter// integer variable used to as loop and array index
local numberUSA // integer variable used to store number of holidays to USA
local franceSpain // integer used to store num of holidays to France or Spain
// assign initial value to variables used to count each destination
put 0 into numberUSA
put 0 into franceSpain
// use fixed loop to compare each country with destinations being counted
repeat with counter = 1 to nHolidays
// add 1 to number of US cdestinations if country is USA
if hCountry[counter]="USA" then add 1 to numberUSA
// add 1 to number of France or Spain destinations if country is France or Spain
if hCountry[counter]="France" or hCountry[counter]="Spain" then add 1 to franceSpain
// display number of holidays to each destination
put "Number of holidays to the USA is" && numberUSA & return after field "output"
put "Number of holidays to France or Spain is" && franceSpain & return after field "output"
Since the holiday details will be imported from a text file, an integer variable will be needed to store the number of holiday details that are stored in the file. Explain how this variable will be used in the rest of the program.
Write down the data flow for steps 3, 4 and 5 of the algorithm and step 3.1 of procedure importDetails.
Refine steps 4 and 5 of the algorithm to provide sufficient detail for the programmer.
Explain why the module called importDetails has been implemented as a procedure and not a function.
Explain why the variable dearest has been declared as a local variable in the mostExpensive module and has not been passed as a parameter.
The following questions refer to Version 2 of the program which must include a new module to count the number of holidays in to the USA and to France or Spain.
Write down any additional Inputs, Processes and Outputs required in Version 2 of the program.
The adapted algorithm for Version 2 of the program is provide below:
2. initialise variables
3. import holiday details
4. display holiday details
5. work out and display most expensive holiday
6. calculate number of holidays to each destination data flow
Does Version 2 of the main program need any additional variables to be declared at step 1?
Explain your answer.
Write down the data flow for step 6 of the adapted algorithm.
Refine step 6 of the algorithm to provide sufficient detail for the programmer.
importDetails resort, country, cost, numberHolidays