






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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A set of programming questions in fortran 90 as part of the computing & numerical methods module for the bachelor of engineering (honours) in structural engineering program at cork institute of technology. The questions cover various concepts including conditional statements, loops, input/output, and computations with integers and characters.
Typology: Exams
1 / 11
This page cannot be seen from the preview
Don't miss anything!
Bachelor of Engineering (Honours) in Structural Engineering – Stage 1
Summer 2006
COMPUTING & NUMERICAL METHODS
Time : 3 Hours
Q1a[ 8 marks] What is the output from the following Fortran90 program? NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.
program s2006_q1a //----------------------------------------------- implicit none
integer::i = 4, j = 3, k = 2 character(1):: c = 'a', b = 'c', a = 'b'
write(,'(a)') "-Part 1-"; if ((i < j) .and. (i < k))then write(,'(a)',advance='no') 'A' else if ((c > b) .or. (a > 'a'))then write(,'(a)',advance='no') 'B' else if ((b > c) .and. (k == j-1))then write(,'(a)',advance='no') 'C' else write(,'(a)',advance='no') 'D'; end if write(,'(a)')'X'
write(,'(a)')"--Part 2--" if (k < i)then if (a == b)then write(,'(a)',advance='no') 'E' else write(,'(a)',advance='no')'F' end if end if write(,'(a)') 'Y' write(,'(a)') "---Part 3---" select case (i + j) case (0) write(,'(a)',advance='no') 'G' case (1) write(,'(a)',advance='no') 'H' case default write(,'(a)',advance='no') 'I' end select write(*,'(a)') 'Z' print *
stop's2006_q1a.f90 ends' end program s2006_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 s2006_q1c //--------------------------------------------------------------------- implicit none
integer::cork, mayo, limerick, ennis, galway
do write(, '(a)', advance='no')'cork = ?, <0 to quit:--->' read, cork if(cork < 0)exit
write(,)'pytagorean triples are --->' write(, 20) 'limerick', 'ennis', 'galway' write(, 30)
do mayo = 1, cork - 1, 1 limerick = cork2 - mayo ennis = 2 * cork * mayo galway = cork2 + mayo write(, 40) limerick, ennis, galway end do write(, 30)
end do 10 format(1x,a) 20 format(1x, t5, a12, t20, a12, t35, a12) 30 format(1x, 45('-')) 40 format(1x, t5, i12, t20, i12, t35, i12)
stop 's2006_q1c.f90 is ending --->' end program s2006_q1c
Q1d[ 8 marks]
What is the output of the following Fortran90 program for the inputs 1, 2, 3, 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 s2006_q1d !------------------------------------------------------------------------ implicit none integer::k integer::r = 0, s = 0 integer::t = 0, u = 0
do write(,'(a)', advance='no')'gimmee an integer(+ve or -ve, 0 to END)' read, k if( k == 0)then exit else if( mod(k,2) == 0)then !even r = r + k t = t + 1 else if( mod(k,2) == 1 )then !odd s = s + k u = u + 1 end if end do
if(t > 0)then print 20, t, r, REAL(r)/t else print*, 'xxxxxx' end if
if(u > 0)then print 30, u, s, REAL(s)/u
else print*, 'zzzzzz' end if
20 format(//' ', t10, i5, " AAA BBB ",& / t20, " with CCC -->> ",i8, & / t20, " and DDD -->> ", f8.3 )
30 format(//' ', t10, i5, " EEE FFF ", & / t20, " with GGG -->> ", i8, & / t20, " and HHH -->> ", f8.3 ) !------------------------------------------------------------------------ stop's200_q1d.f90 ends ...' END PROGRAM s2006_q1d
Each line in the file contains the product code, the actual cost, the estimated cost for a particular piece. A sample file might be
The quality control engineer would like to analyze this information by calculating the error of each estimate as a
with appropriate headings, the first three being those in the original file and the fourth column containing the percentage error in the estimate. The engineer would also like to get a screen report to spot data that is especially anomalous i.e. where the percentage error is larger than some specified percentage.
Write a program that opens the files, requests the limit for spotting the anomalous errors, reads the data from
program run might be as follows for the data given above
however,
Thus your program might run like this:
Q5a(15 marks)
GCD(a, b) , the Greatest Common Divisor of two positive integers a and b is the largest positive integer that divides both a and b. Euclid’s Algorithm for finding it is as follows:
loop loop prompt for, read, store theA if theA > 0 exit loop end loop
loop prompt for, read, store theB if theB > 0 exit loop end loop
if(0 == theA) theEuclidGCD Í theB else if(0 == theB) theEuclidGCD Í theA else gotTheGCD Í false loop theQuotient Í theA / theB theRemainder Í theA – theB * theQuotient gotTheGCD Í (o == theRemainder) if(gotTheGCD)exit the loop theA Í theB theB Í theRemainder end loop theEuclidGCD Í theB end if display theEuclidGCD prompt for, read, store theDecision if(theDecision = ‘n’ or ‘N’)escape the loop end loop say goodbye
program variables as the code proceeds.
Q5b(15 marks)
Using pseudo-code, design a program that reads the coordinates of three points, and then determines whether they form a right-angle triangle and continues this work until the user decides to quit
the first --> 9 the second --> 27
their GCD is 9
thank you Euclid
the first --> 1260 the second --> 198
their GCD is 18
thank you Euclid
try again? YyNn --> n s2006_q5a.f90 is ending Press any key to continue
b
x a
n
k
k
b
x a
−
=
=
1
1
n
k
k
b
x a
−
=
−
=
=
1
1 ( 2 )
2
2 ( 2 )
n
k
k
n
k
k
b
x a