com221
Short Description
manual...
Description
NASARAWA STATE POLYTECHNIC, LAFIA DEPARTMENT OF COMPUTER SCIENCE STUDENT’S PRACTICAL MANUAL
COURSE TITLE: OBJECT ORIENTED FORTRAN COURSE CODE: COM 221 STUDENT’S NAME: ---------------------------------------------------------------------------------------------------------------------------------------------------------
REGISTRATION NUMBER: -------------------------------------------------------------------------------------------------------------------------------------
PROGRAMME: --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SEMESTER / SESSION: ---------------------------------------------------------------------------------------------------------------------------------------------
LECTURER / INSTRUCTOR: OKE, AFEEZ ADESHINA
TOTAL MARKS
SIGNATURE
………………………………%
…………………………………
LAB # 1
To use different types of constants in OOFORTRAN program and Demonstrate how to form valid variables
LAB#2
To demonstrate the use of Mathematical, Boolean and String expression using a simple OOFORTRAN program.
LAB # 3
To use Arithmetic, Input and Output statements in OOFORTRAN using simple Programs
LAB # 4
To use Logical and Comparison expressions in Fortran using simple Programs
LAB # 5
To implement looping using the various loop statements available in OOFORTRAN
LAB # 6
LAB#7
To demonstrate the implementation of subroutine and function
To implement single and multiple dimensional arrays in OOFORTRAN program.
Introduction FORTRAN is the oldest programming language, developed in 1957. It is renewed many times and the latest version is FORTRAN 2008. FORTRAN set the foundations of scientific computing with the version 77 and it is still the most widely used scientific language, due to its computing speed and extensive libraries on the internet. This course will use the FORTRAN 95 edition, which is the upgraded version of 77 and includes some extensions to the 90 version. a) Execution of a Program Execution involves several steps. After establishing an algorithm, the source code is written with a text editor. Then compiler software translates the code into a machine code. Finally the code is executed. For compiling we will use the “Silverfrost Plato FTN95 Personal Edition” software, which is free and can be downloaded from: http://www.silverfrost.com/32/ftn95/ftn95_personal_edition.aspx. Another option is “Force 2.0”. But it is not compatible with some of the new pcs. - Plato FTN95 This compiler can create different formats of file. The ones that we are going to use is the free format files with .f95 extension. The old 77 format is named as the fixed format which restricts the programmer with paragraphs at the beginning of each row and a maximum row length of 66 characters. The free format is like a text file with no paragraph requirement and a maximum row length of 128 characters. b) Notes on Code Writing Use spaces and indentation to make the code readable Use explanations, or in programming terminology: comments (explained in chapter 3), to make the code understandable.
LAB NO# 1 OBJECTIVES To use different types of constants in FORTRAN program and demonstrate how to form valid variables.
EXCERSICE 1 Are the following Fortran statements written correctly? a. character_string = Awake in the morning,& asleep in the evening.’ b. x = 0.4-6 c. answer = ’True & false’ d. low-limit = 0.0005E10 e. y = E6 State the reasons for your answers.
EXERCISE 2 Are the following declarations legal in Fortran: DOUBLE :: x CHARACTER(LEN=*), PARAMETER :: "Name" REAL :: pi = 22/7 REAL :: x = 2., y = -3 REAL :: pii = 22.0/7.0 REAL x = 1.0
LAB NO#2 OBJECTIVE To demonstrate the use of mathematical, boolean and string expression using a simple OOFORTRAN program.
EXERCISE 4 Write a program which declares variables to hold the following data: (a) an integer set to zero. (b) an integer set to minus one. (c) 64.0 (d) -1.56x1012 (this should be written as -1.56E12) Check the program by writing out variables to the screen.
EXERCISE 5 Given the following variable declarations and assignments evaluate the subsequent expressions and state the value and type of each result. Check your results by writing a program to write out the results of the expressions. Finally, insert brackets to clarify the meaning of these expressions according to operator precedence. REAL :: x=10.0 y=0.01, z=0.5 INTEGER :: i=10, j=25, k=3 i+j+k*i z * x / 10 + k z*k+z*j+z*i i*y-k/x+j x/i/z State the value and type of each result here:
Copy the sample program to write out the results of the expressions to the space provided below:
LAB NO#3 OBJECTIVES To use Arithmetic, Input and Output statements in OOFORTRAN using simple Programs THEORY Basic operators are used as they are, such as +,-,* and /. But for exponentiation ** is used instead of ^. The mathematical precedence of the operators is important in FORTRAN since all equations are written is a linear form.
EXERCISE 6 Write a program that reads in the radius as input and computes the area of a circle as output
EXERCISE 7 PROGRAM TEST INTEGER :: A,B REAL :: C,D,RES1,RES2 PRINT*,"INPUT A" READ*, A B=3
C=7;D=3 RES1 = A/B RES2 = C/D PRINT*, "RES1=", RES1,"RES2=", RES2 END PROGRAM TEST
What is the output of the program code above? What do you notice about the data type?
LAB NO#4 OBJECTIVE To use Logical and Comparison expressions in FORTRAN using simple Programs EXERCISE Given the values below, what is the value of each of the following expressions? INTEGER :: age=34, old=92, young=16 age /= old age >= young age = 62 (age==56 .AND. old/=92) (age==56 .OR. old/=92) (age==56 .OR. (.NOT.(old/=92))) .NOT. (age==56 .OR. old/=92)
Write a program to test your answers.
LAB NO#5 OBJECTIVE To implement looping using the various loop statements available in OOFORTRAN EXERCISE 8 program squares implicit none integer int,intsq do int = 1,10 intsq=int*int print*, 'The square of ',int,' = ',intsq end do stop end Run and compile the program above, what is the output of the program?
EXERCISE 9 Modify the program in Exercise 8 above to compute the sum of squares from 1 to 20 using the do loop.
LAB NO#6 OBJECTIVE To implement single and multiple dimensional arrays in OOFORTRAN program. THEORY It is often desirable to refer to a group of related items of the same type by giving them the same group name, and identifying the individual items by their positions within the set. Arrays are used for this purpose in Fortran. EXERCISE real, dimension (10,10) :: a, b, c ! matrices integer :: i, j, k ! here some code to fill the matrices a and b ... ! now perform matrix multiplication: c = a + b do i = 1, 10 do j = 1, 10 c(i, j) = 0.0 do k = 1, 10 c(i, j) = c(i, j) + a(i, k) + b(k, j) end do end do end do
Run and compile the program below, state the function of each line of code. What does the program accomplish?
LAB NO#7 OBJECTIVE To demonstrate the implementation of subroutine and function THEORY Functions and subroutines are FORTRAN's subprograms. Most problems that require a computer program to solve them are too complex to sit down and work all the way through them in one go. Using subprograms allows you to tackle bite size pieces of a problem individually. Once each piece is working correctly you then put the pieces together to create the whole solution. To implement functions and subroutines, first write a main program that references all of the subprograms in the desired order and then start writing the subprograms. This is similar to composing an outline for an essay before writing the essay and will help keep you on track.
EXERCISE Write a FUNCTION Subprogram which calculates the area of a triangle when the side lengths of a triangle are given.
EXERCISE Write a program which calculates the area of a triangle when the side lengths of a triangle are given. Use the FUNCTION subprogram in exercise above.
EXERCISE From the programs written in this Lab, what are the differences between Function and Subroutines sub programs.
View more...
Comments