2.4 The Assignment Statement Values are assigned to variables using the assignment statement : variable = expression Examples: Ex.1: REAL :: XCoordinate,

Slides:



Advertisements
Similar presentations
Chapter 3 Program Design And Branching Structures.
Advertisements

Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
1 Chapter 2 Basic Elements of Fortran Programming.
A Review. a review of lessons learned so far… ( 2 steps forward - 1 step back) Software Development Cycle: design, implement, test, debug, document Large.
1 Basic I/O Input and Output. 2 The READ Statement Basic Version l Performs a list-directed read from the file (or device) indicated by the unit number.
C Language Elements (II) H&K Chapter 2 Instructor – Gokcen Cilingir Cpt S 121 (June 22, 2011) Washington State University.
23 March, 2000 CS1001 Lecture 5 Completion of Lecture 4 –Talked about Data Types & Arithmetic Errors –Continue with Operations and Functions –Program Testing.
17 March, 2000 CS1001 Lecture 2 Programming and problem solving Software engineering practices.
FORTRAN. The History of Fortran Before Fortran there was a dark computing abyss Before Fortran there was a dark computing abyss Assembly was the only.
10 November JavaScript. Presentation Hints What do YOU think makes a good presentation Some of my suggestions Don’t write full sentences on slides Talk,
The scanf Function The scanf function reads input from the standard input device into one or more variables Example: scanf(“%lf”, &miles); Reads a real.
Chapter 2 Basic Elements of Fortan
Chapter 5 Input / Output. 2 Control over input & output  The input and output are basically facilitates a communication between the user and the program.
Introduction to C Programming
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
1 BIL106E Introduction to Scientific & Engineering Computing Organizational matters Fortran 90 ( subset F ): Basics Example programs in detail.
Computer Science 101 Introduction to Programming.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
General Programming Introduction to Computing Science and Programming I.
Computer Science 101 Introduction to Programming.
1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.
Lecture 2 Fundamental Data Types. Variable Declaration.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Input, Output, and Processing
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
1 Week 2 n Organizational matters n Fortran 90 (subset F): Basics n Example programs in detail.
CHAPTER 2 PART #3 INPUT - OUTPUT 1 st semester King Saud University College of Applied studies and Community Service Csc
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
Introduction to Programming with RAPTOR
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Introduction to Computer Programming
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
1 Program Planning and Design Important stages before actual program is written.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
CHAPTER 1 INTRODUCTION TO COMPUTING 1.1 Introduction.
ERRORS. Types of errors: Syntax errors Logical errors.
TCU CoSc Introduction to Programming (with Java) Java Language Overview.
Introduction to Computer Sciences References: [1] Fortran 95/2003 for Scientists and Engineers (3e) by Stephen J. Chapman. [2] Using Fortran 90 by Chester.
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
صياغة البرنامج Coding the Program. خرائط التدفق Flowchart ويطلق عليها أيضاً خرائط سير العمليات وهي مجموعة من الرموز المتعارف عليها تستخدم لتوضيح الخطوات.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
CHAPTER 2:BASIC FORTRAN Data Types INTEGER REAL COMPLEX CHARACTER LOGICAL.
FUNCTIONS. Midterm questions (1-10) review 1. Every line in a C program should end with a semicolon. 2. In C language lowercase letters are significant.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Harvard Mark I Howard Aiken was a pioneer in computing and a creator of conceptual design for IBM in the 1940s. He envisioned an electro-mechanical computing.
Arithmetic Instructions. Integer and Float Conversions.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Introduction to Computing Science and Programming I
Chapter Topics The Basics of a C++ Program Data Types
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Lecture 3: Operators, Expressions and Type Conversion
Lecture 7: Repeating a Known Number of Times
Basic Elements of C++.
The Selection Structure
Programming Problem steps must be able to be fully & unambiguously described Problem types; Can be clearly described Cannot be clearly described (e.g.
Basic Elements of C++ Chapter 2.
Chapter 2 – Getting Started
Introduction to C++ Programming
Programming Errors Key Revision Points.
Lecture3.
Review of C++ Language Basics
Chapter 2 Primitive Data Types and Operations
DATA TYPES There are four basic data types associated with variables:
Presentation transcript:

2.4 The Assignment Statement Values are assigned to variables using the assignment statement : variable = expression Examples: Ex.1: REAL :: XCoordinate, YCoordinate INTEGER :: Number, Term XCoordinate = 5.23 YCoordinate = 25.0 Number = 17 Term = Number / XCoordinate = 2.0 * XCoordinate Print*, Xcoordinate,Ycoordinate,Number,Term

Ex.2: INTEGER :: N REAL :: Alpha, Beta N = 9 Alpha = 3 Beta = (N + 3) / 5 Print*,N,Alpha,Beta Ex.3: INTEGER :: I, Mu, Kappa REAL :: X X = 5.75 I = Kappa = X / 2.0 Mu = 1.0 / X Print*,I,Mu,Kappa,X

2.5 Numeric Functions FORTRAN provides some common functions that are encountered often. See Table 2.2 (Course Note) Examples on Numeric Functions: 1. SQRT(7.0) 2. SQRT(B ** 2 – 4 * A * C) 3. X ** (1.0 / REAL (N)) 4. REAL(NUM) ** (1.0 / REAL(N)) See Remarks on pp 18.

Character Operations The // is used to combine two character values. Example: “centi” // “meters”  “centimeters” if SquareUnit is a character variable =“square” then SquareUnit // “centi” // “meters”  “square centimeters”

Substrings Examples: CHARACTER(15) :: Course Course = “Engineering” Course (: 6)  “Engine” Course (8 : )  “ringbbbb” Course (3:6)  ”????” ”gine”

2.6 Input/Output Two types of input/output statements: List- directed and formatted list-directed Type: Read*,Input_list PRINT *, output_list WRITE (*, *) output_list

Examples: 1. PRINT *, “At time”, Time, “seconds”  At time seconds 2. PRINT *, “the vertical velocity is”, Velocity, “m / sec”  the vertical velocity is m/sec See Rules on pp21

2.7 Program Composition and Format FORTRAN Program Form: 1.Heading 2.Specification part 3.Execution part 4.Subprogram part 5.END program statement

1. program heading, has the form: PROGRAM name  name is a legal FORTRAN identifier.  This statement marks the beginning of the program and gives it a name. opening documentation explains the purpose of the program, clarifies the choice of variable names, and provides other information about the program. 2. specification part of a program must appear next. The first statement in this part should be: IMPLICIT NONE

3. execution part Includes ALL statements that specify actions to be performed during program execution. Examples: - assignment statements - input/output statements 4. END Program Statement: indicates to the compiler the end of the program

Program Format main rules of FORTRAN90 programming are: A line may have a maximum of 132 characters. A line may contain more than one statement, separated by (;). An (&) must be placed at the end of each line that is to be continued to the next line. At most 39 continuation lines are permitted. If a character string must be continued from one line to the next, an (&) must be placed at the end of the line containing 1st part of the string, and another (&) must be placed before the 1st character of the continuation of the string: example: PRINT *, “Enter the initial height (m) and & &the initial velocity (m/sec): “

Any characters after (!)—except within a string constant—form a comment. Example: INTEGER :: Number! Number of data values. If a statement requires a statement label, this label must precede the statement and must be separated from it by at least one blank. Statement labels must be integers in the range 1 through

2.8 Types of Errors Syntax errors or compile-time errors: Errors in the program’s syntax, such as incorrect punctuation or misspelling. will be detected during compilation Run-time errors: such as an attempt to divide by zero in an arithmetic expression. may not be detected until execution of the program Logic errors arise in the design of the algorithm or in the coding of the program that implements the algorithm. more subtle and difficult to be identified

Tutorials CW for Lab 1 (1 and 2) Lab#1 (1) Write a program that reads your full name, age and your car’s color, then write out your age and car’s color.