Separate speaker notes to accompany PowerPoint presentation on two dimensional arrays called twodimarray:


Slide #1:

This will look at two dimensional arrays in theory.  I have not implement the array in this example.

Slide #2:

I have a table/array that gives me information on fares based on where I am flying from and where I am flying to.  In this particular example, I am assuming that I am flying from either Boston, Providence or New York and that I am flying to Istanbul, Budapest, Frankfort, London or Prague.

Slide #3:

We have seen that it is easy to reference tables/arrays with numbers in sequence like 1, 2, 3, 4, 5 so in this example I am going to assign numbers to the cities.

Slide #4:

This shows a couple of more examples of flying from a FROMCITY to a TOCITY and determining the fare. 

Slide #5:

Note that I am using the format fare(row, column).  This can be set up differently depending on the language. The format I am using puts the index/subscript/pointer inside parenthesis and separates the row index/subscript/pointer from the column index/subscript/pointer with a comma.

Slide #6:

This shows two additional fares using the fare(row,column) methodology. Again remember that fare(row,column) means that I select the row first and then the column.  I take the intersection as the fare.

Slide #7:

Using fromCity and toCity as the index/subscript/pointer makes the code more versatile.  I can now take in input and use the input numbers to move the correct fare or add the correct fare or manipulate the correct fare in anyway I need to in my code.

Slide #8:

Another example of taking input and accessing the correct fare by using the input as subscript/index/pointer. The format is fare(fromCity,toCity) which means I go to the row which is represented by fromCity and then to the column which is represented by toCity.

Slide #9:

Note that I am not checking for validity.  If I do not trust my data, I need to do that.  Out of range index/subscript/pointer will make the program crash. I am assuming here that fromCity is 1, 2 or 3 and that toCity is 1, 2, 3, 4 or 5.  If the user is inputting the data or if the file I am reading can not be trusted, I need to validate the date.  See the logic on the next flowchart.

Slide #10:

This shows the logic for checking to make sure that the index/subscript/pointer is in the valid range.  If it is not in the valid range, I put out an error message.  If they are both valid (a classic AND structure), I get the fare.