 “Regular” variable ◦ Holds a single value ◦ For example Dim Student1 as String Dim Student2 as String Dim Student3 as String … Dim Studentn as String.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Introduction to arrays
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
Arrays. What is an Array? An array is a way to structure multiple pieces of data of the same type and have them readily available for multiple operations.
Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.
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.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
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.
Chapter 9: Arrays and Strings
Chapter 8 Arrays and Strings
ISAT 252 Introduction to Arrays. Should have read 2 Chapter 8 –pp , and pp
IE 212: Computational Methods for Industrial Engineering
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
Multi-Dimensional Arrays
 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning.
Chapter 8 Arrays Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Chapter 8 Arrays and Strings
C Programming n General Information on C n Data Types n Arithmetic Operators n Relational Operators n if, if-else, for, while by Kulapan Waranyuwat.
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.
© 2012 EMC Publishing, LLC Slide 1 Chapter 8 Arrays  Can store many of the same type of data together.  Allows a collection of related values to be stored.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
1 Chapter 7 – Arrays 7.1 Creating and Using Arrays 7.4 Two-Dimensional Arrays.
Arrays Group of variables that have a similar type
© 1999, by Que Education and Training, Chapter 8, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
‘Tirgul’ # 3 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #3.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
CPS120: Introduction to Computer Science Lecture 15 Arrays.
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
Chapter 71 Arrays Creating and Accessing Arrays Using Arrays Some Additional Types of Arrays.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter Arrays, Timers, and More 8.
Arrays. Related data items Collection of the same types of data. Static entity – Same size throughout program.
Chapter 9 Processing Lists with Arrays. Class 9: Arrays Understand the concept of random numbers and how to generate random numbers Describe the similarities.
CHAPTER 9 PART II. MULTIDIMENSIONAL ARRAYS Used to represent tables of values arranged in rows and columns. Table element requires two indexes: row and.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Arrays.
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
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.
ADVANCED POINTERS. Overview Review on pointers and arrays Common troubles with pointers Multidimensional arrays Pointers as function arguments Functions.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
Visual Basic CDA College Paphos Campus COM123 Visual Programming 1 Lecture: Charalambous Sotiris Week 8: COM123 Visual Programming 1 Lecture: Charalambous.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
© 2004 Pearson Addison-Wesley. All rights reserved7-1 Array review Array of primitives int [] count; count = new int[10]; Array of objects Grade [] cs239;
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Chapter 9 Introduction to Arrays Fundamentals of Java.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Arrays 1.
Arrays and Collections
Computer Programming BCT 1113
IS 350 Arrays.
Collection in PL/SQL.
Visual Basic .NET BASICS
VBScript Session 2 Dani Vainstein.
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections
Lbound and Ubound Functions
EKT150 : Computer Programming
Arrays An array is a collection of variables that all have the same name and the same data type. Each member of the array is known as an element of the.
Arrays.
VBScript Session 2 Dani Vainstein.
CIS16 Application Development and Programming using Visual Basic.net
EXCEL Creating An Array In VBA
Presentation transcript:

 “Regular” variable ◦ Holds a single value ◦ For example Dim Student1 as String Dim Student2 as String Dim Student3 as String … Dim Studentn as String ◦ If you have 10 students, you can also have variables representing students’ grades  You can total up and average these grades for the “class” of 10 students ClassAvg = StudentGrade1 + StudentGrade2 + …  What happens if you have 1000 students?

 An array is a set of values that are logically related to each other ◦ Monthly rainfall for the year ◦ Number of students in each grade in a grade school ◦ Number of employees in each department of an organization ◦ Employees within a single department  Arrays let us refer to values by the same name ◦ Individual items are referred to as elements and we use a number to indicate which specific element in the array we want ◦ Element number is called the “index” or “subscript”

 Dim Students(6) as Integer ◦ Creates an array using the name “Students” with “containers” called “elements” ◦ Elements start number at “0”  7 elements exist in the Students array Elements of the "students" array

 Assignment statements are used to place a value into a specific element ◦ We just need to specify which element Students(4) = 18  Places the value of 18 into the 5 th element (we start counting at 0) of the array  Retrieving a value is as simple as specifying the element number ◦ System.Console.WriteLine( Cstr( Students(4) ) )

 Assuming that we have an array “Students” which represents the grades kindergarten through 6 th grade (kindergarten being grade “0”) Dim Students(6) as Integer Students(0)=11 Students(1)=14 Students(2)=17 Students(3)=11 Students(4)=19 Students(5)=21 Students(6)=10 Students

 We can get the total number of students in the school by adding the values in all the elements together TotalStudents = Students(0) + Students(1) + Students(2) + Students(3) + Students(4) + Students(5) + Students(6) ◦ Typical processing of an array is by using a “LOOP” Dim Grade,TotalStudents as Integer TotalStudents = 0 For Grade = 0 to 6 TotalStudents = TotalStudents + Students(Grade) Next Grade Students

Students

 If you decide to include up to the 8 th Grade ReDim Students(8)  Anything in the array will be lost!

 Suppose we have a company with 100 employees ◦ Each employee has an Employee ID #  A “whole counting number” ◦ We wish to keep track of his/her salary  Could be a decimal  Create an array to hold this information Dim Employee(2,100) as Single  Create a 3 x 101 matrix  Note: data is of type “single” even though employee number is an integer  Salary is a decimal type (non-integer), so employee # 21 is in the array  We don’t have to use the “0 th ” row or column, they can remain empty  Alternatively Dim Employee(1,99) as Single

 Add as many pairs of parentheses after the variable name as there are levels of nested arrays ◦ Dim x as Integer( ) ( ) = New Integer( ) ( ) { }  Add the same number of paired parentheses to the “New” clause ◦ You don’t need more that one pair of braces if you’re not giving an element values

 Two dimensional, but not “rectangular” ◦ Array of months  Each element is an array of days Dim sales()() As Double = New Double(11)( ) { } Dim month As Integer Dim days As Integer For month = 0 To 11 days = DateTime.DaysInMonth(Year(Now), month + 1) sales(month) = New Double(days - 1) {} Next month  declares an array variable to hold an array of arrays with elements of the Double Data Type  Each element or the array “sales” is itself an array representing a month  Each month holds values for each day in that month

 Technically you cannot do this ◦ Arrays are of the same type  The type we will use is “Object” Dim x as Object( ) = New Object( ) { }  Example Dim employeeData(3) as Object employeeData(0) = “John Doe” employeeData(1) = “13 East North Rd.” employeeData(2) = 22 employeeData(3) = #04/01/1982# Age = CInt( employeeData(2) ) DOB = CDate( employeeData(3) )  Negative performance consideration

 Errors in declaring / initializing ◦ Supplying the “new” clause after specifying dimension lengths ◦ Omitting “new” when specifying element values ◦ Using the “new” clause without braces  Out of bounds ◦ Going beyond the upper or lower bounds of the dimensions  Specifying dimension ◦ GetLowerBound and GetUpperBound methods are “0-based” ◦ Lbound and Ubound are “1-based”