chapter 2: data types & operations

16
1 Chapter 2: Data Types & Operations Part 1 ICS101: Computer Programmin l-Hashim, Amin G.

Upload: doris-burns

Post on 31-Dec-2015

60 views

Category:

Documents


5 download

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 Presentation

TRANSCRIPT

Page 1: Chapter 2: Data Types & Operations

1

Chapter 2: Data Types & Operations

Part 1

ICS101: Computer Programming

Al-Hashim, Amin G.

Page 2: Chapter 2: Data Types & Operations

2

Outline

Data Types Constants Variables

Page 3: Chapter 2: Data Types & Operations

3

Data Types

Data: form of recording 4 basic types of data in FORTRAN:

IntegerRealCharacterLogical

Page 4: Chapter 2: Data Types & Operations

4

Constants

Fixed value Types:

Integer constantsReal constantsCharacter constantsLogical constants

Page 5: Chapter 2: Data Types & Operations

5

Integer Constants

Numbers without a decimal point E.g.:

1010 -20081429

Page 6: Chapter 2: Data Types & Operations

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

Page 7: Chapter 2: Data Types & Operations

7

Character Constants

Any set of characters between single quotes

E.g.: ‘FORTRAN is an interesting PL’ ‘I’’am very interesting with ICS101’

Page 8: Chapter 2: Data Types & Operations

8

Logical Constants

2 logical constants in FORTRAN: .TRUE. represents true .FALSE. represents false

Page 9: Chapter 2: Data Types & Operations

9

Variables

Occupies a place at the computer memory Must have a name to be referenced Its value can be changed

Page 10: Chapter 2: Data Types & Operations

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

Page 11: Chapter 2: Data Types & Operations

11

Cont.

Types of Variables : Integer variablesReal variablesCharacter variablesLogical variables

Page 12: Chapter 2: Data Types & Operations

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

Page 13: Chapter 2: Data Types & Operations

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

Page 14: Chapter 2: Data Types & Operations

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

Page 15: Chapter 2: Data Types & Operations

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

Page 16: Chapter 2: Data Types & Operations

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