chapter 2: data types & operations
DESCRIPTION
ICS101: Computer Programming. Chapter 2: Data Types & Operations. Part 1. Al-Hashim, Amin G. Outline. Data Types Constants Variables. Data Types. Data: form of recording 4 basic types of data in FORTRAN: Integer Real Character Logical. Constants. Fixed value Types: - PowerPoint PPT PresentationTRANSCRIPT
1
Chapter 2: Data Types & Operations
Part 1
ICS101: Computer Programming
Al-Hashim, Amin G.
2
Outline
Data Types Constants Variables
3
Data Types
Data: form of recording 4 basic types of data in FORTRAN:
IntegerRealCharacterLogical
4
Constants
Fixed value Types:
Integer constantsReal constantsCharacter constantsLogical constants
5
Integer Constants
Numbers without a decimal point E.g.:
1010 -20081429
6
Real Constants
Numbers with a decimal point E.g.:
3.4 -0.00018710000000000.0 -0.0000000000000012
Representations in FORTRAN:OrdinarilyScientific Notation
xEy (0.1≤ x <1.0) … yx 10
7
Character Constants
Any set of characters between single quotes
E.g.: ‘FORTRAN is an interesting PL’ ‘I’’am very interesting with ICS101’
8
Logical Constants
2 logical constants in FORTRAN: .TRUE. represents true .FALSE. represents false
9
Variables
Occupies a place at the computer memory Must have a name to be referenced Its value can be changed
10
Cont.
Rules of Naming Variables:Starts with an alphabetic characterMay contain digitsShould not contain special charactersLength should not exceed 6 charactersMust not contain blanks
Which of the following are legal variable names?(1) FIVE (2) 5IVE (3) F!VE (4) F I V E(5) FIVE55555 (6) F5
11
Cont.
Types of Variables : Integer variablesReal variablesCharacter variablesLogical variables
12
Integer Variables
Hold only integer values Definition:
Explicit … using the INTEGER statementINETGER X, Y, Z, FIVE
Implicit … variable name starts with I, J, K, L, M, or NISUM, JAR, KILO
MUST be before any executable statement
13
Real Variables
Hold only real values Definition:
Explicit … using the REAL statementREAL TAX, FEE, Z, FIVE
Implicit … variable name doesn’t start with I, J, K, L, M, or NSLOPE, WEIGHT, F6
MUST be before any executable statement
14
Character Variables
Hold only character values Definition:
Explicit ONLY… using the CHARACTER statementCHARACTER NAME*6, COL*10, MAJORCHARACTER*6 NAME, COL*10, MAJOR
MUST be before any executable statement
15
Logical Variables
Hold only logical values (.TRUE. | .FALSE.) Definition:
Explicit ONLY… using the LOGICAL statementLOGICAL FLAG, TEST, X, CONT
MUST be before any executable statement
16
Exercise
Find the errors in the following FORTRAN code
* FullOfErrors.forC By: Al-Hashim
INTEGER OFFICE#, HOURS, MINUTES SECONDSCHARACTER E-MAIL*100 LOGIC FLAGPRINT*, ICS101: COMPUTER PROGRAMMINGREAL CASH1, CASH2