




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
A set of fortran90 programs and instructions for answering various engineering-related questions. The programs cover topics such as calculating the output of fortran90 codes, reading data from a file, and performing quadrature integrations using the mid-point rule. Students of structural engineering at cork institute of technology, or anyone interested in learning fortran90 programming, may find this document useful.
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Cork Institute of Technology
Bachelor of Engineering (Honours) in Structural Engineering - Stage 1
(NFQ – Level 8)
Autumn 2007
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 q1a implicit none !------------------------------------------------------------------- integer::eeny = 4, meeny = 3, myny = 5, moh = 6
eeny = eeny + 1 if(eeny == meeny + moh / meeny)then print *, 'Jelly' end if
eeny = eeny + 1 if(eeny == meeny)then print *, 'Sherbert' endif
if( (moh >= 6) .and. (myny + moh > 5) .and. & ( (5 + moh) <= (6 + myny) ) )then if(moh == 7)then print *, 'Carrott Cake' else print *, 'Ice Scream' end if end if
if((moh - myny - 1) /= 1)then print *, 'Corn Flakes' else print *, 'Angel Food Cake' end if !-------------------------------------------------------------------stop 'q1a.f90 ends' END PROGRAM q1a
Q1b[ 8 marks] What is the output of the following Fortran90 program for each of the following cases: m Í 45, n Í 15; m Í 36, n Í 24; m Í 15, n Í 28? Can you deduce what IT is in this program? NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.
PROGRAM q1b implicit none
integer::m, n, r, q !------------------------------------------------------------------- write(*,'(A)',advance='no')'gimmee an integer m --->' read , m write(,'(A)',advance='no')'gimmee an integer n --->' read *, n
do q = m / n r = mod(m, n) if(r == 0)then print*, 'so there it is --->', n, ' is IT' exit end if m = n n = r end do !------------------------------------------------------------------- stop'q1b.f90 ends ...' END PROGRAM q1b
Q1c[ 8 marks] What is the purpose of the following programming? Test it with the values 12, 15, 17, 35 and others if necessary. Find what is IT in each case. Deduce from your findings what the code does. NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.
PROGRAM q1c implicit none
integer::m, k logical::gotIT = .false. !------------------------------------------------------------------- write(*,'(A)',advance='no')'gimmee an integer m --->' read *, m
k = m / 2 do if(k <= 1)exit if(mod(m, k) == 0)then gotIT = .true. exit end if k = k - 1 end do print* if(gotIT)then print, 'so there it is --->', k, ' is IT' else print, 'so there is NO IT at all' end if print* !------------------------------------------------------------------- stop'q1c.f90 ends ...' END PROGRAM q1c
Q1e[ 8 marks] What is the purpose of the following Fortran90 program? Test it with the values 12, 123, 12345, 1234567 and others if necessary. Find what is WhatIsThis in each case. Deduce from your findings what the code does. NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.
PROGRAM q1_e implicit none integer::theInteger, whatIsThis, aHolder, bHolder !------------------------------------------------------------------- do write(, '(a)', advance='no')'gimmee an integer (0 to end)---> ' read, theInteger if(theInteger == 0)exit aHolder = theInteger bHolder = 0 do bHolder = bHolder * 10 + mod(aHolder, 10) aHolder = aHolder / 10 if(aHolder == 0)exit end do whatIsThis = bHolder
write(*,10) theInteger, ' ---> ', whatIsThis end do
10 format(1x, i15, a, i15) !------------------------------------------------------------------- stop'q1_e.f90 ends ...' END PROGRAM q1_e
The exam data for an important class are stored in the file f:\myExperiment\dse1Data.dat. The data is raw(without any explanatory text or headings) and each line contains the following data: surname, firstname, homework, exam_1, exam_2, final_exam as shown in fig 2.1 below 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 45% for homework, 30% for Christmas and Easter exams and 25% for the final exam
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 and standard deviation( definitions given in fig 2.3 , the maximum and minimum of the final grades awarded.
Cooper Dave 535 90 95 145 Murphy Mary 500 65 89 135 Kelleher John 250 88 89 110 O'Sullivan Fred 400 66 73 100
Enter name of data file: e:\q2.dat
name homework exam 1 exam 2 final exam final score ============================ ======== ====== ====== ========== =========== Cooper Dave 535 90 95 145 72. Murphy Mary 500 65 89 135 76. Kelleher John 250 88 89 110 60. O'Sullivan Fred 400 66 73 100 64.
average FinalGrade: 68. standard deviation FinalGrade: 6. maximum FinalGrade: 76. minimum FinalGrade: 60.
Press any key to continue
For data
x (^) 1 , x 2 , x 3 ,..., x n
n
x
x
n
i
∑ i = =^1
( ) ( ) 1 2
2
1
2
(^2) x n
x
n
x x s
n
i
i
n
i
i = −
∑ ∑ = =
Q5a(15 marks) Write , in module form, a function theDistance() to compute the distance between two points on a plane together with a driver to test it. The function will have four real numbers as parameters(the x and y coordinates of the two points) and it will return a real value (the distance between the two points. Thus getTheResult = theDistance (0.0, 0.0, 3.0, 4.0) will result in the variable getting the value 5.0. Note: (though I hardly need to?) The distance between the two points ( x 1 (^) , y 1 )and ( x (^) 2 , y 2 )is given by
( ) ( 2 1 )
2
and the sqrt() function returns the square root of a real.
Q5b(15 marks) Write, in module form, a function coolingState(yourTemperature) which will return the result of applying Cooper’s Social Rules(detailed below) to your temperature in °C. Include with it a driver to test it. e.g. coolingState( 65.43) Î ‘Gleaming’ coolingState(123.45) Î ‘Dripping
Doug Cooper once quoted the following ‘Genius, according to Thomas Edison, is 2% inspiration and 98% perspiration. Nowadays, of course, perspiration is usually socially inappropriate, except for men and horses. Alternative terms - sweating, glowing, dripping - exist, and it is important to know when to use them, regardless of the consequences to genius.’ Accordingly Cooper’s social secretary formulated the following rules for all students’ guidance:
Temperature ° C Cooling Mechanism
o
o
under 60 ° Cold
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