Chapter 8 Introduction to Arrays Part II Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Chapter 8: Arrays.
Introduction to arrays
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1 Overview 7.1 Introduction to Arrays 7.2 Arrays in Functions 7.3.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Chapter 4. Loops and Character Manipulation Loops in FORTRAN are constructs that permits us to execute a sequence of statements more than once. Type of.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Introduction to Arrays.
Chapter 5 Basic I/O Concepts Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul - Turkey Tel:
Chapter 10 Additional Features of Arrays Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Chapter 3 Program Design and Branching Structures Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering.
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Chapter 7 Introduction to Arrays Part I Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Chapter 2 Basic Elements of Fortan
Loops – While, Do, For Repetition Statements Introduction to Arrays
Chapter 11 Additional Intrinsic Data Types Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Chapter 8. 2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays as Arguments Two-Dimensional Arrays Common.
Chapter 4 Loops and Character Manipulation Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
 2006 Pearson Education, Inc. All rights reserved Arrays.
Chapter 5 - Arrays CSC 200 Matt Kayala 2/27/06. Learning Objectives  Introduction to Arrays  Declaring and referencing arrays  For-loops and arrays.
Chapter 8 Arrays and Strings
Chapter 9 Introduction to Procedures Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul -
Chapter 6 AN INTRODUCTION TO FILES AND FILE PROCESSING Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
IE 212: Computational Methods for Industrial Engineering
Multi-Dimensional Arrays
 2006 Pearson Education, Inc. All rights reserved Arrays.
A First Book of ANSI C Fourth Edition
Array Dependence Analysis COMP 621 Special Topics By Nurudeen Lameed
Chapter 8 Arrays and Strings
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Some Fortran programming tips ATM 562 Fall 2015 Fovell (see also PDF file on class page) 1.
Arrays Arrays in C++ An array is a data structure which allows a collective name to be given to a group of elements which all have.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter Arrays, Timers, and More 8.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays.
Slide 1 Chapter 5 Arrays. Slide 2 Learning Objectives  Introduction to Arrays  Declaring and referencing arrays  For-loops and arrays  Arrays in memory.
Chapter 5 Arrays. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 5-2 Learning Objectives  Introduction to Arrays  Declaring and referencing.
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
1. 1. Introduction to Array 2. Arrays of Data 3. Array Declaration 4. Array Initialization 5. Operations on Array 6. Multidimensional Arrays 7. Index.
Introduction to Computer Sciences References: [1] Fortran 95/2003 for Scientists and Engineers (3e) by Stephen J. Chapman. [2] Using Fortran 90 by Chester.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Processing Arrays Lesson 9 McManusCOP Overview One-Dimensional Arrays –Entering Data into an Array –Printing an Array –Accumulating the elements.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Fortran: Control Structures Session Three ICoCSIS.
© Janice Regan, CMPT 128, January CMPT 128: Introduction to Computing Science for Engineering Students Introduction to Arrays.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
A FIRST BOOK OF C++ CHAPTER 8 ARRAYS AND POINTERS.
CHAPTER 6 ARRAYS IN C 1 st semester King Saud University College of Applied studies and Community Service Csc 1101 F. Alakeel.
Chapter 5 Arrays Copyright © 2016 Pearson, Inc. All rights reserved.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
C++ for Engineers and Scientists Second Edition Chapter 12 Pointers.
Objectives You should be able to describe: One-Dimensional Arrays
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
Chapter 8: More on the Repetition Structure
An Introduction to Programming with C++ Sixth Edition
Programming For Nuclear Engineers Lecture 6 Arrays
7 Arrays.
7 Arrays.
Presentation transcript:

Chapter 8 Introduction to Arrays Part II Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul - Turkey Tel: +90 ( ) Fax: +90 ( )

Introduction to Arrays – Part II Input and Output of Array Elements We previously stated that an array element is a variable just like any other variable, and that an array element may be used in any place where an ordinary variable of the same type may be used. Therefore, READ and WRITE statements containing array elements are just like READ and WRITE statements for any other variables. To write out specific elements from an array, just name them in the argument list of the WRITE statement. For example, the following code writes out the first five elements of the real array a. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 2

Introduction to Arrays – Part II The Implied DO Loop The implied DO loop is also permitted in I/O statements. It allows an argument list to be written many times as a function of an index variable. Every argument in the argument list is written once for each value of the index variable in the implied DO loop. With an implied DO loop, the previous statement becomes: The argument list in this case contains only one item: a(i). This list is repeated once for each value of the index variable i. Since i takes on the values from 1 to 5, the array elements a(1), a(2), a(3), a (4), and a(5) will be written. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 3

Introduction to Arrays – Part II The general form of a WRITE or READ statement with an implied DO loop is: where arg1, arg2, etc., are the values to be written or read. The variable index is the DO loop index, and istart, iend, and incr are respectively the starting value, ending value, and increment of the loop index variable. The index and all of the loop control parameters should be of type INTEGER. For a WRITE statement containing an implied DO loop, each argument in the argument list is written once each time the loop is executed. Therefore, a statement like © 2010, Dr. ALİ CAN TAKİNACI Slide No: 4

Introduction to Arrays – Part II © 2010, Dr. ALİ CAN TAKİNACI Slide No: 5

Introduction to Arrays – Part II Nested Implied DO Loops Like ordinary DO loops, implied DO loops may be nested. If they are nested, the inner loop will execute completely for each step in the outer loop. As a simple example, consider the following statements There are two implicit DO loops in this WRITE statement. The index variable of the inner loop is j, and the index variable of the outer loop is i. When the WRITE statement is executed, variable j will take on values 1, 2, and 3 while i is 1, and then 1, 2, and 3 while i is 2. The output from this statement will be Nested implied DO loops are important in working with arrays having two or more dimensions, as we will see later in Chapter 8. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 6

Introduction to Arrays – Part II Input and Output of Whole Arrays and Array Sections Entire arrays or array sections may also be read or written with READ and WRITE statements. If an array name is mentioned without subscripts in a Fortran I/O statement, then the compiler assumes that every element in the array is to be read in or written out. If an array section is mentioned in a Fortran I/O statement, then the compiler assumes that the entire section is to be read in or written out. Figure 6-11 shows a simple example of using an array and two array sections in I/O statements. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 7

Introduction to Arrays – Part II © 2010, Dr. ALİ CAN TAKİNACI Slide No: 8

Introduction to Arrays – Part II Summary of Good Programming Practice The following guidelines should be adhered to when working with arrays. 1. Before writing a program that uses arrays, you should decide whether an array is really needed to solve the problem or not. If arrays are not needed, don't use them! 2. All array sizes should be declared by using named constants. If the sizes are declared by using named constants, and if those same named constants are used in any size tests within the program, then it will be very easy to modify the maximum capacity of the program at a later time. 3. All arrays should be initialized before use. The results of using an uninitialized array are unpredictable and vary from processor to processor. 4. The most common problem in programming with arrays is attempting to read from or write to locations outside the bounds of the array. To detect these problems, the bounds checking option of your compiler should always be turned on during program testing and debugging. © 2010, Dr. ALİ CAN TAKİNACI Slide No: 9