Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.

Slides:



Advertisements
Similar presentations
UNIT IV.
Advertisements

ECE122 L14: Two Dimensional Arrays March 27, 2007 ECE 122 Engineering Problem Solving with Java Lecture 14 Two Dimensional Arrays.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 6 - Arrays Outline 6.1Introduction 6.2Arrays.
An Introduction to Programming with C++ Fifth Edition
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
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.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
Introduction to Programming with C++ Fourth Edition
C++ for Engineers and Scientists Third Edition
Introduction of Arrays. Arrays Array form an important part of almost all programming language. It provides a powerful feature and can be used as such.
Chapter 8 Arrays and Strings
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Programming Languages -1 (Introduction to C) arrays Instructor: M.Fatih AMASYALI
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 6 - Arrays Outline 6.1Introduction 6.2Arrays.
Arrays in C++ UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) 1 ADNAN BABAR MT14028 CR
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Arrays in C++ Numeric Character. Structured Data Type A structured data type is a type that stores a collection of individual components with one variable.
Chapter 8 Arrays and Strings
1 DATA STRUCTURES: LISTS. 2 LISTS ARE USED TO WORK WITH A GROUP OF VALUES IN AN ORGANIZED MANNER. A SERIES OF MEMORY LOCATIONS CAN BE DIRECTLY REFERENCED.
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Topics to be covered  Introduction to array Introduction to array  Types of array Types of array  One dimensional array One dimensional array  Declaration.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Course Title Object Oriented Programming with C++ Course instructor ADEEL ANJUM Chapter No: 05 ARRAY 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER) 1.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
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.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
Week # 2: Arrays.  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently  Types of data.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C arrays ❏ To be able to pass arrays and array elements to functions.
IN THE NAME OF ALLAH WHO IS THE MOST BENEFICENT AND MOST MERCIFUL.
Computer Programming Lecture 8 Arrays. 2 switch-statement Example (3) If use press left arrowIf use press right arrow If use press up arrow If use press.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
FP201 - PROGRAMMING FUNDAMENTALS Unit Understand the use of array PREPARED BY: MAZNAH AHMAD, JTMK PSIS.
UNIT-4 1. Arrays: Definition and declaration, Initialization, Accessing elements of arrays, Storing values in arrays, Inter-function Communication: Passing.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
Lec 13 Oct 21, 02. Array Initialization in the declaration statement ► int temp[5] = {98, 87, 92, 79,85}; ► char codes[6] = { ‘s’, ’a’, ‘m’, ‘p’, ‘l’,
Chapter 8: Part 3 Collections and Two-dimensional arrays.
Arrays in java Unit-1 Introduction to Java. Array There are situations where we might wish to store a group of similar type of values in a variable. Array.
Multidimensional Arrays tMyn1 Multidimensional Arrays It is possible to declare arrays that require two or more separate index values to access an element.
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.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Introduction to programming in java Lecture 21 Arrays – Part 1.
1 Two-Dimensional Arrays. 2 Terminology Two-dimensional arrays represent matrices A matrix contains a number of values of the same data type The values.
Beginning C for Engineers Fall 2005 Arrays, 2-D arrays, character strings Bettina Schimanski Lecture 5: Section 2 (9/28/05) Section 4 (9/29/05)
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
C Programming Lecture 15 Two Dimensional Arrays. Two-Dimensional Arrays b The C language allows arrays of any type, including arrays of arrays. With two.
Array in C# Array in C# RIHS Arshad Khan
Chapter 5: Arrays: Lists and Tables
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
Lecture 12 Oct 16, 02.
Review of Arrays and Pointers
Introduction To Programming Information Technology , 1’st Semester
Multidimensional Arrays
Data Structures (CS212D) Week # 2: Arrays.
Multidimensional array
Arrays Imran Rashid CTO at ManiWeber Technologies.
Data Structure(s) A way of storing and organizing data in a computer so that it can be used efficiently. e.g. Arrays Linked Lists stacks Queues Trees.
Presentation transcript:

Lecture #15 ARRAYS By Shahid Naseem (Lecturer)

2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also called “elements of array”. An array is represented in the computer memory by a consecutive group of storage locations. These locations are referenced by a single variable called “array name”. Each element of an array is referenced by its position in the array by an index value like [1]

3 USES OF ARRAYS Arrays are used to process a large amount of data of same type. The data is stored in an array. The array is accessed by a single variable name. The index values are used to access individual elements of the array. The use of arrays in a program reduces size of the program.

4 TYPES OF ARRAYS There are two types of arrays. 1. One-dimensional arrays. 2. Multi-dimensional arrays.

5 ONE-DIMENSIONAL ARRAY One dimensional array is also known as a list or a linear array. It consists of only one column or one row. For example, the temperature of each hour of a day is stored in an array. It has 24 elements. Defining the name of array, its types and the total number of elements of an array is called “Declaring of the array” Temp[0] Temp[1] Temp[2] Temp[4] Temp[23]

6 ACCESSING DATA IN ONE DIMENSIONAL ARRAY Each element of an array is referenced of an array is referenced by its index. The index of the first element is always 0 and of the last element is n-1. The index value is written within square brackets after the array name. Data is entered in an array by using individual elements of the array. To print the data from an array, the output statements are used.

7 PROGRAM #include void main() { float a[5]; int i; a[0]=9.9; a[1]=12.9;for (i=0;i<=4;i++) a[2]=13.1;cout<<“value in a[“<<i<<“]=“a[i]<<endl; a[3]=8.9;} a[4]=10.6;

8 STRING VARIABLES String variables are declared in the same way as character type variables are declared. String variable is an array of character type. The length of the string is the total number of elements of the array. The syntax is char variable_name[n] e.g. char str[15]

9 PROGRAM \\write\\write a program to initialize a string with the word “Pakistan” and then print it on the screen. # include main () { char str[15]=“pakistan”; clrscr(); cout<<str; }

10 SORTING ARRAYS The process of arranging data is a specified order is called sorting. Numeric type data may be arranged either in ascending or in descending order. Character type data may be arranged in alphabetical order. There are different methods to sort data in a list. The most commonly used methods are 1. Bubble Sort 2. Selection Sort

11 SORTING ARRAYS Bubble Sort: The bubble short method is used to arrange values in ascending or in descending order. To arrange an array in ascending order, two neighbouring elements are compared. If one element is larger than the other, the two are exchanged. Through the exchange of elements, the larger value slowly floats or bubbles up to the top. In descending order, the smaller value slowly floats up to the top.

12 SORTING ARRAYS Selection Sort: This method is also used for sorting arrays in ascending or in descending order. Following method is used to sort an array in ascending order using selection sort. First replace 1 to 4, then 4 to 19 and then 13 and

13 MULTI-DIMENSIONAL ARRAYS A multi-dimensional array is an array of more than one array. An array of two one-dimensional arrays is called two dimensional array. It is also known as table or matrix. A two dimensional array consists of columns and rows. Each element of the two-dimensional array is referenced by its index values. The index value of a two-dimensional array consists of two subscripts. One represents row number and second represents the column number.

14 MULTI-DIMENSIONAL ARRAYS If “temp” is a two dimensional array having 7 rows and 3 column, its first element is temp [0][0] and last element is temp[6]][2]. Temp[0][0]Temp[0][1]Temp[0][2] Temp[1][0] Temp[6][0]Temp[6][2]

15 PROGRAM \\write\\write a program to initialize value to a table xyz having 4 columns and 3 rows at the time of declaration. Also prinnt data form the table in tabular form. # include main () { int xyz[3][4] = {{2,3,10,1},{6,12,16,3},{4,3,13,17}}; int r,c; clrscr(); for (r=0;r<=2;r++)

16 PROGRAM { for(c=0;c<=3;c++) { cout<<xyz[r][c]<<“\t”; } cout<<endl; Getch(); }