






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The solutions to various fortran90 programming questions related to computing & numerical methods for the structural engineering degree at cork institute of technology. The questions involve writing and understanding fortran90 code, tracing the working of programs, and identifying the output of given programs.
Typology: Exams
1 / 10
This page cannot be seen from the preview
Don't miss anything!







Q1a[ 8 marks] Please list all possible output from the following Fortran90 program noting carefully what the input is in each case?
program a2006_q1a implicit none !----------------------------------------------------------- integer::zidane
do write(, '(a)', advance = 'no') 'gimmee an integer --->' read, zidane
if ((zidane < 0) .or. (zidane > 10) )exit
if((zidane == 2) .or. (zidane > 3))then print, '...materazzi' else if(zidane /= 1)then print, '..grosso' else print*, 'zambrotta' end if
if(zidane == 4)then print, 'canavaro...' else if(zidane == 3)then print, 'buffon..' end if
end do !----------------------------------------------------------- stop 'zinedine has now retired -' end program a2006_q1a
Q1c[ 8 marks] What is the output of the following Fortran90 program for the successive inputs 1, 2, 3 , 4, - Variable names have been chosen to hide their real purpose. Deduce the purpose for the code. NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.
PROGRAM a2006_q1c implicit none !------------------------------------------------------------------- integer::a, b, c c = 7 do a = 1, c, 1 do b = 1, c, 1
if( (a == 1) .or. (a == c) .or. (b == 1) .or. (b == c) )then write(, 14, advance='no')a else if(a == b)then write(, 12, advance='no')'' else if(a + b == c + 1)then write(, 12, advance='no')'#' else write(*, 14, advance='no')b end if
end do print* end do print* print*
12 format(a) 14 format(i1) !------------------------------------------------------------------- stop'q1_c ends ...' END PROGRAM a2006_q1c
Q1d[ 8 marks] What is the output of the following Fortran90 program for the inputs 1, 2, 3, -5, 1003, 4, 5, 6, 0 Deduce the purpose for the code and suggest what the texts AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH might more usefully be. NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.
PROGRAM a2006_q1d !-------------------------------------------------------------------------- implicit none integer::k integer::s = 0, t = 0 integer:: u = -1, v = 1001
do write(,'(a)', advance='no')'gimmee an integer(+ve or -ve, 0 to END)' read, k
if(0 == k)exit if((k > 1000) .or. (k < 0))then print*, '-.-.-rejected' cycle endif
if( k < v)then v = k else if( k > u)then u = k end if t = t + 1 s = s + k end do
if(t > 0)then print 20, t, u, v, REAL(s)/t else print*, 'xxxxxx' end if
20 format(//' ', t10, i5, " AAA BBB ",& / t20, " with CCC -->> ",i8, & / t20, " with DDD -->> ",i8, & / t20, " and EEE -->> ", f8.3 ) !-------------------------------------------------------------------------- stop'a2006_q1d.f90 ends ...' END PROGRAM a2006_q1d
The exam data for an important class are stored in the file d:\q2.dat. The data is raw(without any explanatory text or headings) and each line contains the following data: surname, firstname, assignments, christmas_exam, summer_exam as shown in fig 2.1 below for a sample file of 4 students, where
Please write a Fortran90 program to connect to this file, to read the data for each student, calculate for that student a final grade based on 20% for assignments, 10% for Christmas exam and 70% for the final exam i.e.
and to transfer all the data to the screen in the tabular form with headings as shown if fig. 2.2 below and append below the table detail of the mean, the maximum and minimum of the final mark awarded.
Cooper Dave 145 90 75 Murphy Mary 165 89 45 Kelleher John 77 35 55 O'Sullivan Fred 103 73 82
Enter name of data file: e:\q2.dat
name assignments christma summer final mark ============================ =========== ======== ====== ========== Cooper Dave 145 90 75 87. Murphy Mary 165 89 45 68. Kelleher John 77 35 55 54. O'Sullivan Fred 103 73 82 84.
average FinalMark: 73. maximum FinalMark: 87. minimum FinalMark: 54.
Press any key to continue
Thus your program might run like this:
Indicate modifications to this code which would get it to print all factors of theInteger:as shown here:
gimmee theInteger ( 0 to end) ---> 2 --> 1 * 2
gimmee theInteger ( 0 to end) ---> 6 --> 1 * 2 * 3
gimmee theInteger ( 0 to end) ---> 12 --> 1 * 2 * 2 * 3
gimmee theInteger ( 0 to end) ---> 48 --> 1 * 2 * 2 * 2 * 2 * 3
gimmee theInteger ( 0 to end) ---> 96 --> 1 * 2 * 2 * 2 * 2 * 2 * 3
gimmee theInteger ( 0 to end) ---> 125 --> 1 * 5 * 5 * 5
gimmee theInteger ( 0 to end) --->
q3.f90 ends ... Press any key to continue
gimmee an integer theInteger ( 0 to end) ---> 2 --> 1 & 2
gimmee an integer theInteger ( 0 to end) ---> 6 --> 1 & 2 & 3 & 6
gimmee an integer theInteger ( 0 to end) ---> 12 --> 1 & 2 & 3 & 4 & 6 & 12
gimmee an integer theInteger ( 0 to end) ---> 48 --> 1 & 2 & 3 & 4 & 6 & 8 & 12 & 16 & 24 & 48
gimmee an integer theInteger ( 0 to end) ---> 96 --> 1 & 2 & 3 & 4 & 6 & 8 & 12 & 16 & 24 & 32 & 48 & 96
gimmee an integer theInteger ( 0 to end) ---> 125 --> 1 & 5 & 25 & 125
gimmee an integer theInteger ( 0 to end) --->
q3.f90 ends ... Press any key to continue
Q5a(15 marks) tYour local mathematician knows the following interesting fact:
8
7
6
5
6
5
4
3
4
3
2
4
=
π
The following is the design, in pseudo-code, of a function to calculate π approximately using the first n terms of the above where the user chooses n: and next to it is a sample output from the program
theTop = 2. theBottom = 3. theProduct = 1. K = loop If(k > n)exit loop theProduct = theProduct * theTop / theBottom If(theTop < theBottom) theTop Í theTop + 2. else theBottom Í theBottom + 2. end if end loop approximatePi = 4.0*theProduct
Please code the design in Fortran90 as a function approximatePi(n) placed in a module called module PiApproximately
Q5b(15 marks)
Using pseudo-code, design a program that reads the coordinates of three points, and then determines whether they are collinear and continues this work until the user decides to quit