Data Structures, Arrays, and using Prerelease Material


One-dimensional arrays

In order to use a one-dimensional array in a computer program, you need to consider:

• what the array is going to be used for, so it can be given a meaningful name

• how many items are going to be stored, so the size of the array can be determined

• what sort of data is to be stored, so that the array can be the appropriate data type.

For example, if a one-dimensional array for all the students’ test marks in a class was to be set up:

• array name StudentMarkTest

• number of items = number of students in the class, this could be a constant NoStudents

• whole numbers need to be stored, data type Integer

Using a variable as an index in an array

In order to repeat the same task many times for all the items in a list, each item needs to be referred to in the same way using the index number for each element of the onedimensional array. If a variable is used for this index number, then the same code can be re-used for each item. This allows several arrays to be used together with the same index number to show related information

Using pre-release material

You need to practice applying your skills to the tasks mentioned in the scenario, which is different for each examination series. Here is a checklist of useful things to do.

1) Read through the pre-release material several times. Check with your teacher if there is anything at all that you do not understand.

2) For each task, write an algorithm using both pseudocode and a flowchart to show what is required.

3) Choose sets of test data that you will need to use, and work out the expected results. Remember to use normal, boundary and erroneous data. Be able to give reasons for your choice of test data.

4) Complete trace tables to test your pseudocode and flowcharts. This will enable you to ensure that both the pseudocode and the flowcharts work properly. It is a good idea to get another student to trace your algorithms as well.

5) Decide which works best for each task, pseudocode or a flowchart, and why.

6) Before starting to write your program for each task:

• decide the variables, including any arrays, and constants you will need

• decide the data types required for these

• decide the meaningful names you will use

• be able to explain your decisions.

7) If you are asked to repeat the same thing many times, for example adding up totals, complete the task for one and check it works before repeating it many times. 8) Write and test each task. You can use the same test data as you used for your pseudocode and flowcharts