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)

What have you tried so far? You need to show as some effort first.

My avatar is my actual reaction when evidently all that OP did was copy/pasting the text from his homework excercise, down to Figure 1-1 and Figure 1-2

Op, at least try to do your homework first and then you come to us when you hit a roadblock

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.