Cit 736 Answers
Cit 736 Answers
The following steps are very necessary in dealing with errors in program
compilation and execution. They are:
a) Program writing and correction requires patience. The programmer
should carefully through the program for possible correction of any
error.
b) Use appropriate manuals and reference text books for the programming
language employed for possible assistance.
c) Double check for misspelled statements or omission of punctuation
marks
d) Check for proper use of data types
e) Make sure variables meant for counting purposes are properly initialized
Four compilers that are used to compile and execute a FORTRAN 90/95
programs
a) Lathey’s Fortran 90 compiler
b) Microsoft Fortran PowerStation 4.0 professional
c) NAGware Fortran 90 compiler
d) Microsoft Developer Studio (MS-DEV) Tool
What criteria would you use to assess the quality of the program?
Produce a large number, n say, of random numbers using the
RANDOM_NUMBER intrinsic subroutine as described above.
Now, count the number of random numbers falling in the range 0.0000000-
0.0999999, those between 0.1000000-0.1999999, and so on.
Print the values to a file. The distribution should be uniform
Write a program in FORTRAN to find the total and product of three numbers
“T, F, V”/ (This is also an example of a program structure using FORTRAN, use
A, B, C instead of T, F, V)
Program SUMPRODUCT - Line 1
IMPLICIT NONE - Line 2
INTEGER:: T, F, V, SUM, PRODUCT - Line 3
READ (*, *) T, F, V - Line 4
SUM = T + F + V - Line 5
PRODUCT = T * F * V - Line 6
WRITE (*, *) SUM, PRODUCT - Line 7
STOP - Line 8
END PROGRAM SUMPRODUCT - Line 9
3) 20 FORMAT (8F6.3)
20 is the format label.
8 - Values to be read
F - for floating point or real number
6 - Size of the value including the decimal point
3 - Number of decimal places
The binary numeral system is a way to write numbers using only two digits: 0
and 1. These are used in computers as a series of "off" and "on" switches.
Integer Numbers: an integer number has no decimal point. Examples are 67, -
234, 900 etc.
Real Numbers: a real number must have a decimal point and the decimal point
must appear between two digits. Examples are 0.01, 11.94, -5.6 etc.
b) Round-off Error: this occurs when a specific significant digits are used, for
example, 1/3 which supposed to be 0.3333333….. could be stored as 0.333.
d) Run-time Error: this error occurs when the translator come across wrong
mathematical operation during program execution. This could occur, as an
example, when a number is divided by zero.
e) Logical Error: program logic is always the cause of the error when the
sequences of programming steps are not executed properly. Logical error may
not have impact with the smooth translation process of the program but may
give wrong result. There could be successful interpretation or compilation of a
program that actually has a logical error. The logical errors are mostly noticed
upon execution of the program.
Assembler Compiler
We use Assembler to translate Compiler converts high level language
Assembly language to machine into machine language for the
language for the understanding of the understanding for the computer
computer
Interpreter Compiler
Reads the source program line by line Reads the source program as a whole
FORTRAN
FORTRAN is an acronym for Formula Translator. This is a high level
programming designed primarily for use by scientist, engineers and designers.
The statements used in the language resemble the formulae normally used by
such people. Some of its dialects are now being used for business computing
and character manipulation. This course material covers the transition from
the programming language Fortran 77 to the more modern Fortran 90/95, and
is aimed at guiding learners who require an understanding of the principles
and new features of Fortran 90/95.
Constant keep their value or string unchanged for the whole program.
ALLOCATABLE arrays are arrays that can have a given dimension, but with a
size that depends on something that happens in the code
Caching Buffering
cache improves the access speed to Buffering is mainly used to match the
frequently used data communication speed between the
sender and the receiver
Declare and assign 3.142 and 7.8 to constant variables C and D in FORTRAN
90/95
REAL :: C=3.142, D=7.8
Internal procedure
A subprogram which is placed inside a module procedure, an external
procedure, or a main program; inside a program unit
External procedure
A self-contained procedure (subroutine or function)
Program WhileDo;
Uses Crt;
Var Ch : Char;
Begin
Writeln('Press ''q'' to exit...');
Ch := Readkey;
While Ch <> 'q' do
Begin
Writeln('I told you press ''q'' to exit!!');
Ch := Readkey;
End;
End.
if var1 = 0 then
writeln('var1 is 0!') (*No semicolon before an 'Else' keyword*)
else if var1 = 1 then
begin
writeln('var1 is 1!');
(*More code*)
end (*No semicolon before an 'Else' keyword*)
else if var1 = 2 then
begin
writeln('var1 is 2!');
125
(*More code*)
end (*No semicolon before an 'Else' keyword*)
else
begin
writeln('var1 is not 0, 1, or 2!');
(*More code*)
end; (*Semicolon used to indicate the end of the If-then-else*)
Numbers are bunch of numerical figures which can include signs, decimal point
and exponent or scale factor. Commas and blank spaces are not included in
numbers but it can be preceded by plus (+) or negative (-) signs.
An array is a set (or collection) of related quantities of the same type with the
same symbolic name.
A dynamic array is declared when the lists contain unlimited number of items,
depending on the amount of computer memory.
Before we begin, let us first clarify the key difference between functions and
procedures. A procedure is set of instructions to be executed, with no return
value. A function is a procedure with a return value.
Categories of subprograms
a) Procedures
b) Functions