1 / 16

Chapter 2: Data Types & Operations

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:

doris-burns
Download Presentation

Chapter 2: Data Types & Operations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ICS101: Computer Programming Chapter 2: Data Types & Operations Part 1 Al-Hashim, Amin G.

  2. Outline • Data Types • Constants • Variables

  3. Data Types • Data: form of recording • 4 basic types of data in FORTRAN: • Integer • Real • Character • Logical

  4. Constants • Fixed value • Types: • Integer constants • Real constants • Character constants • Logical constants

  5. Integer Constants • Numbers without a decimal point • E.g.: • 101 • 0 • -2008 • 1429

  6. Real Constants • Numbers with a decimal point • E.g.: • 3.4 • -0.0001 • 8710000000000.0 • -0.0000000000000012 • Representations in FORTRAN: • Ordinarily • Scientific Notation • xEy (0.1≤ x <1.0) …

  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 character • May contain digits • Should not contain special characters • Length should not exceed 6 characters • Must 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 variables • Real variables • Character variables • Logical variables

  12. Integer Variables • Hold only integer values • Definition: • Explicit … using the INTEGER statement • INETGER X, Y, Z, FIVE • Implicit … variable name starts with I, J, K, L, M, or N • ISUM, JAR, KILO • MUST be before any executable statement

  13. Real Variables • Hold only real values • Definition: • Explicit … using the REAL statement • REAL TAX, FEE, Z, FIVE • Implicit … variable name doesn’t start with I, J, K, L, M, or N • SLOPE, WEIGHT, F6 • MUST be before any executable statement

  14. Character Variables • Hold only character values • Definition: • ExplicitONLY… using the CHARACTER statement • CHARACTER NAME*6, COL*10, MAJOR • CHARACTER*6 NAME, COL*10, MAJOR • MUST be before any executable statement

  15. Logical Variables • Hold only logical values (.TRUE. | .FALSE.) • Definition: • ExplicitONLY… using the LOGICAL statement • LOGICAL FLAG, TEST, X, CONT • MUST be before any executable statement

  16. Exercise • Find the errors in the following FORTRAN code

More Related