COSC 202 focuses on Object-Oriented FORTRAN programming, designed for scientists and engineers. Developed by S.M. Tukur, this course offers foundational knowledge for beginners in FORTRAN. Topics include the structure of FORTRAN programs, input/output operations, and control flow statements. Students will learn to write efficient code using loops and conditionals, making it suitable for programming tasks in scientific computing. Ideal for students in computer science or engineering looking to enhance their programming skills.

Key Points

  • Covers the basics of Object-Oriented FORTRAN programming for beginners
  • Includes practical examples of input/output operations in FORTRAN
  • Explains control flow statements like DO-loops and conditionals
  • Designed for students in science and engineering disciplines
farzy
Author:S.M. Tukur
Edition:May 2011
105 pages
Language:English
Type:Lecture Notes
farzy
Author:S.M. Tukur
Edition:May 2011
105 pages
Language:English
Type:Lecture Notes
142
/ 105
Ahmadu Bello University, Zaria Department of
Mathematics tics
Lecture Note For
COSC 202:Object-Oriented FORTRAN
programming Language.
Developed by S.M. Tukur
May,2011
2
Contents
Introduction .......................................................................................................................................................... 8
What this course is about .................................................................................................................................. 8
What is FORTRAN .............................................................................................................................................. 8
Who uses FORTRAN ........................................................................................................................................... 8
This programming language is designed for scientist and engineers. ...................................................................... 8
Elements of a FORTRAN program ................................................................................................................... 8
Fortran Alphabets .............................................................................................................................................. 8
Fortran Constants .............................................................................................................................................. 9
Integer Constants ................................................................................................................................... 9
Real Constants........................................................................................................................................ 9
Complex:...................................................................................................................................................... 10
Logical: ........................................................................................................................................................ 10
Character String ................................................................................................................................... 10
Fortran Identifiers A Fortran identifier must satisfy the following rules: ................................................ 11
Fortran Variables and Their Types ........................................................................................................................ 12
Fortran Variable Declarations .......................................................................................................................... 12
The PARAMTER Attribute ................................................................................................................................. 13
Examples: .................................................................................................................................................... 13
Variables Initialization ...................................................................................................................................... 14
Examples: .................................................................................................................................................... 14
The Assignment Statement .................................................................................................................................. 16
Introduction..................................................................................................................................................... 16
Examples: .................................................................................................................................................... 16
An Important Note: ...................................................................................................................................... 17
Arithmetic Operators ........................................................................................................................................... 18
Introduction..................................................................................................................................................... 18
Some Useful Notes: ...................................................................................................................................... 18
Single Mode Arithmetic Expressions ................................................................................................................ 18
Simple Examples: ......................................................................................................................................... 19
Rules for Evaluating Expressions ...................................................................................................................... 19
More Complicated Examples: ....................................................................................................................... 20
Mixed Mode Arithmetic Expressions ................................................................................................................ 20
3
Simple Examples: ......................................................................................................................................... 21
An Important Note: ...................................................................................................................................... 21
More Complicated Examples: ....................................................................................................................... 21
Fortran Built-In Functions .................................................................................................................................... 22
Introduction..................................................................................................................................................... 22
Mathematical functions: .................................................................................................................................. 22
Other functions:............................................................................................................................................... 23
Functions in an Expression: .......................................................................................................................... 23
An Example: ................................................................................................................................................. 23
Input Statement: ................................................................................................................................................. 25
The READ Statement ........................................................................................................................................ 25
Preparing Input Data: ....................................................................................................................................... 25
Output Statement:............................................................................................................................................... 28
The WRITE Statement ...................................................................................................................................... 28
Output Format: ............................................................................................................................................ 29
Example 1: Three Programming Traps .............................................................................................................. 29
Solution ....................................................................................................................................................... 29
Program Output ........................................................................................................................................... 30
Explanation .................................................................................................................................................. 30
Programming Example 2: Quadratic Equation Solver ........................................................................................ 31
Problem Statement ...................................................................................................................................... 31
Solution ....................................................................................................................................................... 31
Program Output ........................................................................................................................................... 32
Explanation .................................................................................................................................................. 32
Example 3: The Length of a Parabola Segment ................................................................................................. 32
Problem Statement ...................................................................................................................................... 32
Solution ....................................................................................................................................................... 33
Program Output ........................................................................................................................................... 33
Explanation .................................................................................................................................................. 34
Example 4: Projectile Motion ........................................................................................................................... 34
Problem Statement ...................................................................................................................................... 34
Solution ....................................................................................................................................................... 34
Program Output ........................................................................................................................................... 35
Explanation .................................................................................................................................................. 35
Character Operator and Substrings Processing..................................................................................................... 36
Concatenation Operator // .............................................................................................................................. 36
/ 105
End of Document
142

FAQs

What are the main elements of a FORTRAN program?
A FORTRAN program consists of several key elements including alphabets, variables, constants, and identifiers. The program structure typically includes a main program and possibly several subprograms. Each identifier must follow specific rules, such as being no longer than 31 characters and starting with a letter. Furthermore, the program utilizes various data types, including INTEGER, REAL, COMPLEX, LOGICAL, and CHARACTER, each serving different purposes in computations.
How does the assignment statement work in FORTRAN?
The assignment statement in FORTRAN follows the syntax 'Variable = expression'. The expression is evaluated first, and if its type matches the variable's type, the result is stored directly. If the types differ, the result is converted to the variable's type. For instance, if an INTEGER variable receives a REAL value, the fractional part is truncated. This method ensures that the variable holds the correct data type after the assignment.
What is the purpose of the PARAMETER attribute in FORTRAN?
The PARAMETER attribute in FORTRAN is used to assign a name to a constant value, allowing for easier reference throughout the program. By declaring a variable with the PARAMETER attribute, you create an alias for a specific value that does not change during execution. For example, using 'INTEGER, PARAMETER :: Limit = 30' allows you to use 'Limit' instead of typing '30' repeatedly, enhancing code readability and maintainability.
What are the types of constants in FORTRAN?
FORTRAN recognizes five types of constants: INTEGER, REAL, COMPLEX, LOGICAL, and CHARACTER strings. INTEGER constants are sequences of digits with optional signs, while REAL constants can be expressed in decimal or exponential form. COMPLEX constants are not covered in this course, and LOGICAL constants represent truth values. CHARACTER strings must be enclosed in quotes, with the length defined by the number of characters they contain.
How are arrays declared and used in FORTRAN?
In FORTRAN, arrays are declared using the DIMENSION keyword, specifying the type and size of the array. For example, 'REAL, DIMENSION(1:10) :: Array' declares an array with ten elements. Arrays can be one-dimensional or multi-dimensional and are indexed by integers. The elements can be accessed using their indices, and operations can be performed on them using loops or implied DO statements.
What is the significance of the READ statement in FORTRAN?
The READ statement in FORTRAN is crucial for inputting data into programs. It can read values from the keyboard or files, using various formats to interpret the data correctly. For instance, 'READ(*,*)' allows for list-directed input, while formatted input can specify the exact structure of the data being read. This flexibility enables programmers to handle user input efficiently and ensures that data types are correctly assigned to variables.