Lesson 9 Arrays. Miscellaneous About Arrays An array is an object. Because of this, the array name is a reference variable Therefore, in order to start.

Slides:



Advertisements
Similar presentations
Copyright © 2003 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.
One Dimensional Arrays
Arrays. What is an array An array is used to store a collection of data It is a collection of variables of the same type.
Passing Arrays to Functions Programming. COMP102 Prog. Fundamentals I: Passing Arrays to Function / Slide 2 Passing Arrays as Parameters l Arrays are.
Arrays Chapter 6. Outline Array Basics Arrays in Classes and Methods Sorting Arrays Multidimensional Arrays.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 14, 2005.
COMP 10 Introduction to Programming Mr. Joshua Stough October 29, 2007.
COMP 14 Introduction to Programming Miguel A. Otaduy June 4, 2004.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
Chapter 7 Arrays. © 2004 Pearson Addison-Wesley. All rights reserved7-2 Arrays Arrays are objects that help us organize large amounts of information Chapter.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Arrays Chapter 8 page /24/07CS150 Introduction to Computer Science 1 Arrays (8.1)  One variable that can store a group of values of the same.
Chapter 9: Arrays and Strings
Introduction to Programming with C++ Fourth Edition
C++ for Engineers and Scientists Third Edition
Chapter 8 Arrays and Strings
Arrays. Objectives Learn about arrays Explore how to declare and manipulate data into arrays Learn about “array index out of bounds” Become familiar with.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.
Arrays.
COMP 14 Introduction to Programming Miguel A. Otaduy June 1, 2004.
© 2011 Pearson Education, publishing as Addison-Wesley 1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 6 focuses.
Chapter 8 Arrays and Strings
Chapter 7 One-Dimensional Arrays 7.1 Arrays in C One of the more useful features of C is the ability to create arrays for storing a collection of related.
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
COMP102 Lab 081 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
Java Programming: From Problem Analysis to Program Design, 4e
Java Basics Elizabeth MacDonald
ARRAYS 1 TOPIC 8 l Array Basics l Arrays and Methods l Programming with Arrays Arrays.
Chapter 9: Arrays J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 19, 2005.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
1 Topic: Array Topic: Array. 2 Arrays Arrays In this chapter, we will : Learn about arrays Learn about arrays Explore how to declare and manipulate data.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
CHAPTER 6 ARRAYS IN C++ 2 nd Semester King Saud University College of Applied studies and Community Service CSC 1101 By: Fatimah Alakeel Edited.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Arrays An array is an indexed data structure which is used to store data elements of the same data type. An array is an indexed data structure which is.
Two Dimensional Arrays Found in chapter 8, Section 8.9.
An Object-Oriented Approach to Programming Logic and Design Chapter 8 Advanced Array Concepts.
1 Chapter 9 Arrays Java Programming from Thomson Course Tech, adopted by kcluk.
Chapter 5: ARRAYS ARRAYS. Why Do We Need Arrays? Java Programming: From Problem Analysis to Program Design, 4e 2  We want to write a Java program that.
Java Programming: Chapter 9: Arrays
Opening Input/Output Files ifstream infile; ofstream outfile; char inFileName[40]; char outFileName[40]; coutinFileName;
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
C++ Array 1. C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used.
1 Chapter 9 Arrays Java Programming from Thomson Course Tech, adopted by kcluk.
Chapter 9 Arrays. Chapter Objectives Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of “array index.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Chapter 9 Arrays. Chapter Objectives Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of “array index.
Arrays Chapter 12. One-Dimensional Arrays If you wanted to read in 1000 ints and print them in reverse order, it would take a program that’s over 3000.
Arrays. Arrays are objects that help us organize large amounts of information.
CHAPTER 6 ARRAYS IN C 1 st semester King Saud University College of Applied studies and Community Service Csc 1101 F. Alakeel.
 2005 Pearson Education, Inc. All rights reserved Arrays.
Chapter 9 Introduction to Arrays Fundamentals of Java.
1 Why do we need arrays? Problem - Input 5 test scores => int test1,test2,test3,test4,test5 100 test scores? 10,000 employees? A structured data type is.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Array 1 ARRAY. array 2 Learn about arrays. Explore how to declare and manipulate data into arrays. Understand the meaning of “array index out of bounds.”
Chapter 9: Arrays J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
Chapter 6 Arrays in C++ 2nd Semester King Saud University
Lecture 9 Objectives Learn about arrays.
Java Programming: Program Design Including Data Structures
Presentation transcript:

Lesson 9 Arrays

Miscellaneous About Arrays An array is an object. Because of this, the array name is a reference variable Therefore, in order to start using an array, it must be instantiated just like any other object. For this chapter, we will discuss –one-dimensional arrays –two-dimensional arrays

One-dimensional array Two-dimensional array

Defining One-Dimensional Arrays To define an array you must specify three things: –the data type of the array elements –the name of the array –the size of the array int list[]; int[] list;

Array Subscripts Subscripts are used to refer to a specific array element. The first element is assigned subscript of 0; the next, a subscript of 1, and so on The subscript range of an array is listed in brackets in the array declaration And individual array element must have a subscript which is within the allowed subscript values.

Giving an Array and Element a Value Through Direct Assignment int[] x = new int[5]; x[1] = 5;

Reading and Writing to Arrays The easiest way to read or write to an array is by using loops. Often times you will want to use the loop control variable as the array subscript. It is not necessary to know array size at compile time. arrayName.length returns the number of components in an array

Example of a 1-Dimensional Array int[] examp = new int[3]; for (int x = 0; x < examp.length; x ++) examp[x] = x + 1; for (int x = 0; x<3; x++) System.out.print(examp[x] + “,”);

Specifying an Array Size During Program Execution int arraySize; System.out.print(“Enter the size of the array: “); arraySize = Integer.parseInt(keyboard.readLine()); int[] list = new int[arraySize]

Code to Initialize Entire Array to Specific Value (0.00) for(index = 0; index < sale.length; index++) sale[index] = 0.00

Code to read data into an array for(index = 0; index <sale.length; index++) sale[index] = Integer.parseInt(keyboard.readLine());

Code to Print an Array for(index = 0; index < sale.length; index++) System.out.print(sale[index] + “ “);

Code to Find Sum and Average of an Array sum = 0; for(index = 0; index <sale.length; index++) sum = sum + sale[index]; if(sale.length !=0) average = sum / sale.length; else average = 0.0;

Determining Largest Element in an Array maxIndex = 0; for(index = 1; index < sale.length; index++) if(sale[maxIndex] < sale[index]) maxIndex = index; largestSale = sale[maxIndex];

Array Index Out of Bounds Array in bounds if: 0 <= index <= arraySize -1 if index arraySize: ArrayIndexOutOfBoundsException

Two – Dimensional Arrays

Bottoms Up