Read a data file describing a social network into a two dimensional array, say F
ID: 3529152 • Letter: R
Question
Read a data file describing a social network into a two dimensional array, say F. The file will consist of a line with the number of members of the array, n, followed by n lines which describe the "friends" of the corresponding member. A sample of data for a network with 27 members is provided below. You will be provided with more sets of data on MyCourses for testing your program. Your program should not make assumptions about the size of the data set other than to assume a maximum size such as 1000. Define a subroutine to compute the product of two square n by n matrices. Your program should use this subroutine to multiply the "friends" array by itself and produce the array F2. Define a subroutine which, given an n by n matrix, counts the number of how many members have 0, 1, 2, 3, 4, 5 or more than 5 mutual friends. In the sample data there is only one pair with 3 mutual friends but several with 2 mutual friends. Be careful not to double-count pairs of members. The matrix is symmetric so F2(i,j) and F2(j,i) will have the same values but should only be counted once. Also be careful not to count the diagonal entries since a member cannot be friends with him or herself. The subroutine should generate and return an array of length 7 with the counts for each category. Your program should use this subroutine to determine how interconnected the social network is. It should output the results of this search. Output a list of "suggested friends". The suggested friends are those in the top two non-zero categories. In the sample data provided below, the top non-zero entry is the one with 3 mutual friends. For this sample data your program should output "suggested friends" for members are not already friends and have 2 or 3 mutual friends. Again, do not output the same pair twice.Explanation / Answer
program main INTERFACE subroutine sub1(x) real, dimension(:):: x real C end subroutine sub1 subroutine sub2(x) real, dimension(:):: x real C end subroutine sub2 END INTERFACE real, dimension(:), allocatable:: x allocate(x(1:10)) ! First executable command in main x(1) = 5. call sub1(x) write(*,*) 'result = ',x(1) deallocate(x) end program main subroutine sub1(x) ! The first subroutine real, dimension(:):: x real C call sub2(x) end subroutine sub1 subroutine sub2(x) ! The second subroutine real, dimension(:):: x real C C2=x(1) end subroutine sub2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.