array 2011

24
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 1 AN INTRODUCTION TO ARRAY By: ATIQA , RAFIA RBIYA, RABBIA

Upload: atiqa-khan

Post on 16-Jan-2015

105 views

Category:

Education


1 download

DESCRIPTION

Arrays

TRANSCRIPT

Page 1: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

12011

AN INTRODUCTION

TOARRAY

By:

ATIQA , RAFIARBIYA,

RABBIA

Page 2: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

2

TABLE OF CONTENTS Introduction to the ARRAY Classification Array Declaration Array Initialization Array with FOR Loop Upper and lower limit of Array Advantages Disadvantages Conclusion

2011

Page 3: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

3

Introduction An Array is a group of memory location s

having same data type Data type specify the type of data it stores A group of CONTINOUS memory locations Example: Int A[0][1][2][3][4] Store JUST single variable C++ store list values in it Arrange in Rows/ Columns

2011

Page 4: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

4

To refer a particular location its Name and its “SUBSCRIPT “is specifiesWHAT IS A ‘SUBSCRIPT’?The number contained within Square bracketIt MUST be an integer or expression If its an integer expression then it is evaluated to describe the subscriptEXAMPLE: c[a+b] +=2; if a=5, and b=6

2011

Page 5: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

5

In some languages (e.g. COBOL) arrays are called “Tables”. An individual value in an array is called an “Element”

2011

Page 6: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

6

Classification There are divided into following types;1. One Dimensional Arrays: A[0][1][2][3][4][5][6]………………[n]2. Two Dimensional Arrays:

3. Multi Dimensional Arrays: 3D, 4D etc

2011

A[0][0] A[0][1] A[0][2] A[0][3] A[0][4]

A[1][0] A[1][1] A[1][2] A[1][3] A[1][4]

A[2][0] A[2][1] A[2][2] A[2][3] A[2][4]

Page 7: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

7

One Dimensinal Arrays

We Explore The Following Things in this Section:•Arrays Declaration •Arrays Initialization •With FOR Loop

2011

Page 8: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

8

Array DeclarationAs just in few steps…Lets have an example of OVERS in a cricket match, its 6 per over We declared it something like that…Int balls[5] Subscript/indexArray_name OR….

2011

Page 9: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

9

Its still the same!!!Int balls= {1,2,3,4,5,6}

More Examplex:Char city= {L,A,H,O,R,E}FLOAT NUM={1.2, 1.3, 1.4 ,1.5 }

2011

Page 10: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

10

Array Initialization

It can be intialized as they declaredDo not need to declared the subscript if initial values are defined What's the initial values we are talking about.. Int k[]= {12,13,14,15}

WE HAVENT SEPCIFY THE INDEX-ANOTHER NAME AND STIL IT WORKS

2011

Page 11: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

11

Because array automatically generate the space for itJUST FOR UNDERSTANDING!!! Int k [5]= {12,13,14,15}With index it something look like this…..C++ does not flag out any error if index go out of the bound… HOW?????Char k[7]={A,R,R,A,Y}Even the memory remains empty still it does not cerate any error…

2011

Page 12: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

12

Array Loops

Almost always needed to steep through the ARRAYThe loop is used is “FOR-LOOP”Can not do manipulation easily thenBUT WHY????? Loops are use to REPEATATION so as in the case of array we MUXT declared the index of ≥0 ; for C++ to pick up the required index it uses the loop.But just not used in some fewer cases

2011

Page 13: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

132011

ONE DIMENSIONAL ARRAY ENDZZZ….

Page 14: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

14

• We ‘r going to explore the following contents in this:

1. Introduction to 2D-Array2. 2D Array with nested FOR loop3. Upper and lower limit of array4. Advantages5. Disadvantages

2011

Page 15: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

15

Two Dimensinal Arrays

It has rows and columns…… just like a TABLEAlso known as MATRIXEXAMPLE:

2011

A[0][0] A[0][1] A[0][2] A[0][3] A[0][4]

A[1][0] A[1][1] A[1][2] A[1][3] A[1][4]

A[2][0] A[2][1] A[2][2] A[2][3] A[2][4]

Page 16: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

16

HOW TO DECLARE 2D-ARRAY??? This way Int temps[2][2]Row * column = 2*2: holding 4 integers

NOW HOW to INITIALIZE IT?????? JUST simple!!! Int temps[2][2]={{12,14} , {21,41}}:Value of each is held in {}

2011

Page 17: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

17

In GENERAL: ARRAY_NAME[row][column]={row}{column}

[SUBSCRIPT]Both parts of an index MUST be an integer

2011

Page 18: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

18

Arrays with Nested FOR Loops

Nested FOR loops to step through 2D-ArrayUSUALL FORMAT:FOR EACH ROW, FOR EACH COLUMNDo something to array[row][column]EXAMPLE:Int team[2][3];For(int row=0;orw<2;;row++){For(int row=0;orw<2;;row++){Team[row][column]=8: }}

2011

Page 19: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

19

TWO DIMENSIONAL ARRAYENDXXXX….

2011

Page 20: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

20

Upper And Lower Limit

Mid versions of BASIC allowed any starting and ending value. So we could have arrays like the following: EXAMPLE:     int years (1998 to 2008)     int tide. level(-5 to +5) Many “modern” languages do not allow this freedom with declaring arrays

2011

Page 21: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

21

Advantages

* simple and easy to create Any element of an array can be accessed time by its indexRandom accessConstant size arrays with arbitrary size (dynamically allocated array)array will always hold similar kind of information

2011

Page 22: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

22

DisadvantagesWe cant change the size of array during run time  Constant size WITH Constant data-type Array data structure is not completely dynamic.Insertion and deletion of an element in the array requires to shift the locations

2011

Page 23: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

23

CONCLUSIONThe Prospective of what we have presented now is to JUST enhance the ability of ourselves;Its up to US how we cater down al this in our practical LIFE… We have to crave what is perfect from INSIDE!!!!

2011

Page 24: Array 2011

Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia

24

REFERENCES1. C How to program, 4th edition by DEITEL2. WWW.gavilian.edu/adnvantages/histroy

/arrays.htm3. WWW.agolist.net/data-strcutures/arrays

2011