Task 1

A diving company needs a program to process dive trip information.

A function, getCost(), takes a string array as a parameter. The pseudocode for the function header is:

FUNCTION getCost(dives : ARRAY[1:50] OF STRING) RETURNS REAL

Each string in the array stores the dive location and the cost of the dive. Some examples are:

"scapaflow-89.00", "stkilda-65.50", "ardnamurchan-95.89"

As you can see, the last 5 characters of each string represent the cost of the dive in pounds sterling.

The function will process the array and calculate the total cost of all of the dives stored in the array. It will return this cost.

Implement this function.

Here is a pseudocode based test-program:

DECLARE arr : ARRAY[1:50] OF STRING

//populate the array with strings

arr ← ["scapaflow-89.00", "stkilda-65.50", "ardnamurchan-95.89"..., ...]

//call the function, passing it arr as an argument.

totalCost = getCost(arr)

OUTPUT "The total cost is £", totalCost

A procedure, scapaFlowFile, also needs to be written.

This procedure takes an array of STRINGS as a parameter. The pseudocode header for the procedure is:

PROCEDURE scapaFlowFile(dives : ARRAY[1:50] OF STRING)

In structured English, this procedure will:

  1. OPEN the file scapaFlow.txt in append mode
  2. loop through the STRING array
  3. IF any dive in the array starts with scapaflow, INPUT the name of the boat and the number of crew and append this information into the file.
  4. After the array has been processed, CLOSE the file

When inputting the name of the boat and the number of crew, you can use any data to test it. The number of crew cannot be less than 1 or more than 5 - make sure your code validates this information before appending to file.

The boat/crew information should be appended on one line, seperated by a comma eg Jolene, 3

Here is an example of the textfile contents after several calls to the procedure scapaFlowFile

Jolene, 3

Seastar, 2

Logan, 5

Bounty, 2

Scapa Flow

After World War I ended, the British ordered the German fleet to Scapa Flow in Scotland to await a decision on its future.

The German admiral in charge decided to scuttle the fleet rather than allow the British and her allies an opportunity to divide the fleet amongst themselves.

These wrecks are now popular diving sites.