CT243 lab3


http://geminga.it.nuigalway.ie/~gettrick/courses/CT243/labs/l3.html



In this lab we will program using two-dimensional arrays.

  1. Consider the (20x20) array of numbers here. Lets say this represents a matrix A of distances (in kilometers) between cities. Note that A is symmetric A(i,j) = A(j,i) and all its diagonal elements are zero. Suppose Vladimir from city i and Petra from city j want to meet up in some third city k (i, j and k are all different). Conscious about their carbon footprint (!), they want k to be as near as possible: specifically the sum of the distances both has to travel should be minimum. Given i and j, write a program in VB .net that determines what k should be. Do not worry in your program about "reading in" A: Just hard code it in to the code. So in your interface, just ask for the two cities (i and j) where Vladimir and Petra live. From your program, calculate the answer for
    1. i=3, j=13
    2. i=18, j=4
  2. Suppose this matrix is now taken to represent a table of total exports (in billions of euro) from country i to country j in some specific year. So for example, the total exports from country 1 to country 2 were valued at 106 billion euro, and the exports in the reverse direction from 2 to 1 at 126 billion euro. (Now of course matrix A is not symmetric, but the diagonal entries are still zero, A(i,i) = 0 for all i). We will refer equally to A(i,j) as the exports from i to j, or the imports of j from i. Write a program that calculates the median imports of country k (from amongst the 19 other countries with whom it trades). Your input should simply be the value of k. The median is the number such that half of the numbers fall above its value and half below. Some short examples are
    1. [1,2,5] median is 2
    2. [1,2,8] median is 2
    3. [1,5,6,7] median is 5.5
    (Note it is not the same as the average). Use your program to calculate this median import for city 13 and for city 16.


© NUI, Galway