Fortran90 Program for Structural Engineering Exam - Computing & Numerical Methods, Exams of Mathematical Methods for Numerical Analysis and Optimization

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

2012/2013

Uploaded on 03/28/2013

shona
shona 🇮🇳

4

(1)

18 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Cork Institute of Technology
Bachelor of Engineering (Honours) in Structural Engineering – Stage 1
(NFQ – Level 8)
Autumn 2006
COMPUTING & NUMERICAL METHODS
Time : 3 Hours
Answer Question 1 and 2 other questions. Examiners :
Prof. P.E.O’Donoghue
Mr. T.Corcoran
Dr M.G. Murphy
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

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

Cork Institute of Technology

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

(NFQ – Level 8)

Autumn 2006

COMPUTING & NUMERICAL METHODS

Time : 3 Hours

Answer Question 1 and 2 other questions. Examiners :

Prof. P.E.O’Donoghue

Mr. T.Corcoran

Dr M.G. Murphy

Q1 continues

Q1[ 40 marks] Please answer each of the following questions.

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

Q1 continues

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

Q1 continues

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

Q2 ends

Q2[ 30 marks]

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

  • assignments is the total mark(max 170)gained from homework assignments,.
  • christmas_exam are the marks earned(max 100) in the exams held at Christmas,
  • summer_exam is the mark(max 100) for the final exam

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.

final_mark Í 70

_

_

 assignments christmas exam summer 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, 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

Fig 2.

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

Fig 2.

Q3 ends

Q3[ 30 marks]

Write a Fortran90 program which will display the prime factors for the positive integer called theInteger

  • prompts for and reads theInteger and ensures that it is positive
  • then generates each of its prime factors. and prints them to screen
  • wraps your code in a loop to allow the user to continue processing by entering a '#'. This will allow for easier testing.

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

Simple Quadratures

Q5 ends

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

Q5a(15 marks) tYour local mathematician knows the following interesting fact:

  • ... 7

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

algorithm