A road distance table may be used to give the distances between some towns as shown
below. To simplify the programming of distance tables, we assign numbers 0, 1, . . . to
the towns. Then we may get a distance table like this:
Towns Number
Alor Setar 0 0
Ipoh 1 1 258 1
Kangar 2 2 43 301 2
Kuala Lumpur 3 3 475 217 518 3
Mersing 4 4 876 616 918 401 4
Melaka 5 5 623 365 667 148 246
The distance from Kangar (location no. 2) to Kuala Lumpur (location no. 3) is found by
looking up row number 3 and then column number 2, where we see that the distance is
518 km.
Based on the above table, you are required to write
A. A function for int DistanceTable(int town1, int town2) which
returns the distance between town1 and town2. For instance, the call
DistanceTable(2,3) returns the distance between the Kangar and Kuala
Lumpur. The method DistanceTable will also return the same distance
between Kuala Lumpur and Kangar when called as DistanceTable(3,2).
This function also have a distance table of towns in array form
Figure 1-1: Representation number
to city
Figure 1-2: Town distances (in km)