Fortran90 Exam Questions - Computing for Mechanical Engineering, Exams of Mathematical Methods for Numerical Analysis and Optimization

Exam questions from a computing and numerical methods module for students of mechanical engineering at cork institute of technology. The questions involve writing and debugging fortran90 programs, including calculating quotients and remainders, implementing function modules, and using the bisection root finding algorithm.

Typology: Exams

2012/2013

Uploaded on 04/13/2013

pannaaaa
pannaaaa 🇮🇳

4.8

(6)

68 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Cork Institute of Technology
Bachelor of Engineering (Honours) in Mechanical Engineering – Stage 1
(NFQ – Level 8)
Autumn 2007
Computing and Numerical Methods
Time: 3 Hours
Instructions: Examiners: Ms. J. English
Answer Question 1 and two others Mr. P. Clarke
Prof. M. Gilchrist
Q1 (40 marks) Please answer each of the following questions:
Q1 (a) (8 marks)
What output is produced from the following Fortran90 program given the following input values
7,9,6,5?
NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.
PROGRAM a2007_q1a
implicit none
integer value, k
!----------------------------------------------------
DO k = 1, 4, 1
write(*, '(a)', advance='no')'gimmee a value --->'
read*,value
if( (value > 3) .and. (value < 8))then
print*, 'Meath'
else if(value /= 0)then
print*, 'Galway'
else
print*, 'Cork'
end if
if(value == 6)then
print*, 'Kerry'
else if(value >= 4)then
value = value + 1
print*, 'Wicklow'
end if
END DO
!----------------------------------------------------
stop 'a2007_q1a has now ended …'
END PROGRAM a2007_q1a
pf3
pf4
pf5

Partial preview of the text

Download Fortran90 Exam Questions - Computing for Mechanical Engineering and more Exams Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

Cork Institute of Technology

Bachelor of Engineering (Honours) in Mechanical Engineering – Stage 1

(NFQ – Level 8)

Autumn 2007

Computing and Numerical Methods

Time: 3 Hours

Instructions: Examiners: Ms. J. English Answer Question 1 and two others Mr. P. Clarke Prof. M. Gilchrist

Q1 (40 marks) Please answer each of the following questions:

Q1 (a ) (8 marks)

What output is produced from the following Fortran90 program given the following input values 7,9,6,5? NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.

PROGRAM a2007_q1a implicit none integer value, k !---------------------------------------------------- DO k = 1, 4, 1 write(, '(a)', advance='no')'gimmee a value --->' read,value if( (value > 3) .and. (value < 8))then print, 'Meath' else if(value /= 0)then print, 'Galway' else print, 'Cork' end if if(value == 6)then print, 'Kerry' else if(value >= 4)then value = value + 1 print*, 'Wicklow' end if END DO !----------------------------------------------------

stop 'a2007_q1a has now ended …' END PROGRAM a2007_q1a

Q1 (b) (8 marks)

What is the output of the following Fortran90 program? NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.

Q1 (c) (8 marks)

What is the output of the following Fortran90 program for the inputs 14, 17, 33, 11 Deduce the purpose for the code?. NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.

PROGRAM a2007_q1b

implicit none

integer :: m,n,p

p = 5

do m = 1,p, do n = m,p, 2 if((m == 1).or.(m == p).or.(n == m).or.(n == p)) then write(,'(i1)',advance = 'no') n else write(,'(a)',advance = 'no') '*' end if end do print * end do !------------------------------------------------------------------- stop 'q1_b.f90 ends ...'

END PROGRAM a2007_q1b

PROGRAM a2007_ q1c implicit none PROGRAM q1c integer:: r, t logical:: gotIT = .false. !---------------------------------------------------- write(,'(A)',advance='no')'gimmee an integer r --->' read , r t = 2 do if (t >= r)exit if (mod(r, t) == 0)then gotIT = .true. exit end if t = t + 1 end do print if (gotIT) then print, 'so there it is --->', t, ' is IT' else print, 'so there is NO IT at all' end if print stop ' a2007q1c.f90 ends ...' END PROGRAM a2007_ q1c

Q2 (30 marks)

The distribution of overtime earnings for 200 operatives during the first quarter of 2006 are stored in the file inData.txt. The data is raw (without any explanatory text or headings) and each line contains the following data: x f as shown in fig. 2.1 below. We use x to represent the overtime amount and f to represent the frequency of this value.

Please write a Fortran90 program to connect to the file, to read the data and to transfer them to the new file Results.dat in tabular form as shown in fig 2.2 and append below the table details of the mean, the standard deviation and the variance of the overtime earnings as shown in fig 2.

The relevant formulae are also included.

Fig. 2.

x f

The average overtime earnings is ---> 292.69 euros

The standard deviation of the overtime earnings is ---> 113.27 euros

The variance of the overtime earnings is ---> 12830.13 euros

Fig. 2.

Mean =

fx

f

Standard Deviation =

2 2

fx fx

f f

Variance = the standard deviation squared

Q3[ 30 marks] Please answer each of the following questions.

Q3a[ 6 marks] Write a Fortran90 function module^ for the Fortran90 functions

FUNCTION g(x)

to the functions

y = f ( x ) =

3

x − 4 x + 2

Q3b[ 12 marks] Write a Fortran90 function module to implement the Bisection Root Finding Algorithm, SUBROUTINE BISECTION(a,b,eps) given

  • f(x) is the function defined in the module written to the definition in Q3a
  • arootb
  • the user-specified degree of accuracy(We’re happy we have the root at x if abs ( f ( x )) ≤ eps at x,

Q3c[ 12 marks] Write a Fortran90 driver program to use the above modules to search for and find the roots of f(x). This program will feature

  • a user option for a root search, a user-controlled loop where f(x) is evaluated for user nominated x. This allows the user to locate where f(x) value changes sign, thus giving the good estimates for root location, i.e. the left and right parameters of BISECTION().
  • a user option to repeat root search or to quit

Q4[ 30 marks] Please answer each of the following questions.

Q4a[ 12 marks] Write a menu-driven program that allows the user to convert measurements either from miles to kilometers (1 mile = 1. kilometers), from feet to meters ( 1 foot = 0.3048 meter), or from degrees Fahrenheit to degrees Celsius (C = (5/9)(F – 32)). A sample run of the program should proceed as follows:

Available options are:

  1. Display this menu.
  2. Convert feet to meters.
  3. Convert miles to kilometers.
  4. Convert degrees Fahrenheit to degrees Celsius.
  5. Quit.

Enter an option (1 to see menu): 1 Available options are:

  1. Display this menu.
  2. Convert feet to meters.
  3. Convert miles to kilometers.
  4. Convert degrees Fahrenheit to degrees Celsius.
  5. Quit.

Enter an option (1 to see menu): 3 Enter miles: 12 This is equivalent to 19.31 kilometers

Enter an option (1 to see menu): 2 Enter number of feet: 6 This is equivalent to 1.83 meters

Enter an option (1 to see menu): 5

Q4b[ 8 marks Write a SUBROUTINE that accepts two positive integers M and N and returns an array containing the first N powers of M e.g. if m = 6 and n = 5 the program should return the following values: 1 2 3 4 5

Q4c[ 10 marks]

Write a driver program to test the FUNCTION in part (b)