SDT Topic - 08

50 %
50 %
Information about SDT Topic - 08
Education

Published on September 19, 2013

Author: PradipKharbuja

Source: slideshare.net

TOPIC 8 : ARRAY Er. Pradip Kharbuja

Introduction ◦ Until now we have been working with single units of data. ◦ A whole number contains a single number, no more. ◦ Today we are going to introduce a new kind of data structure. ◦ The Array ◦ This is a list of similarly types variables. ◦ A list of whole numbers ◦ A list of characters ◦ A list of string

The Problem So Far ◦ Scalability ◦ We can write a program to discover the largest number in a set of five numbers. ◦ But that becomes a much more time-consuming prospect if we want to find the largest in a set of thousand numbers. ◦ The array is used to manage this problem.

The Array ◦ We decide on the size of an array. ◦ We decide on the type of things it will store. ◦ In our pseudocode, we can create an array using the following syntax: ◦ data myArray as array of (10) whole numbers  This creates an array of whole numbers, and provides ten compartments starting the compartment number from 0.  So, compartment number of first compartment is 0.  Compartment number five is the sixth compartment in an array.

The Array ◦ We can put something into a compartment like so: ◦ myArray[5] = 100 ◦ This puts the value 100 into the compartment marked as 5 ◦ It is the sixth compartment. ◦ myArray[7] = 10 ◦ myArray[2] = 40 ◦ We can get information out too: ◦ output myArray[5]

The Array ◦ The number that indicates a compartment is known technically as an index. ◦ The compartment is known as the element.

The Structure of an Array Index Value 0 10 1 50 2 203 3 56 4 79  This is an array of size five.  The contents of myArray[2] would be 203  The square brackets indicate the index

Finding the Largest Number of 7 inputs

Finding the Largest Number of 7 inputs

Finding the Largest Number of 1000 inputs

Passing an Array to a Function ◦ When we pass an array to a function, we do not specify its size. ◦ There is a size of function that gives you the size of the array. ◦ But not how many elements have been filled.

Passing an Array to a Function ◦ Pseudocode to pass data as array of whole number in function and display it.

Main Program

Desk-Checking an Array ◦ We do this by separating the elements of an array in its column by a comma. Line Num nums i len Output Remarks 1 20, 30, 15 0 2 20, 30, 15 0 0 3 20, 30, 15 0 3 4 20, 30, 15 0 3 Loop while i is less than len(3) 5 20, 30, 15 0 3 20 6 20, 30, 15 1 3 7 20, 30, 15 1 3 Goto line 4

Returning an Array ◦ You can return arrays from your functions just like they were our usual variables. ◦ There are some complications though ◦ If you return an array, it will overwrite in every the array you are using to hold it. ◦ It will overwrite the size. ◦ It will overwrite existing contents. ◦ You can also declare an array without giving a size. ◦ But that sets it as null in your desk-check.

Returning an Array

Desk-Checking Function Line Num a Remarks 1 0, 0, 0 2 20, 0, 0 3 20, 40, 0 4 20, 40, 57 5 20, 40, 57 return a

Main Program

Desk-Checking Main Function Line Num b i sizeof(b) output Remarks 1 null 2 null 0 3 20, 40, 57 0 0 Returning from function 4 20, 40, 57 0 3 Loop while i is less than sizeof b (3). 5 20, 40, 57 0 3 20 6 20, 40, 57 1 3 7 20, 40, 57 1 3 Goto 4

Two Dimensional Arrays ◦ The concepts are identical. ◦ You just need two indexes, and two sets of sizes. ◦ These are grids of data. ◦ Two dimensional arrays allow for several kinds of programs that would otherwise be very difficult. ◦ Especially games

Two Dimensional Arrays ◦ Creating ◦ data myGrid as array (10, 10) of whole numbers ◦ Or ◦ Data myGrid as array (10)(10) of whole numbers ◦ Setting ◦ myGrid[10, 5] = 100 ◦ Or ◦ myGrid[10][5] = 100

Two Dimensional Arrays ◦ Getting ◦ Output myGrid [10, 5] ◦ Or ◦ Output myGrid[10][5]

Two Dimensional Arrays Example 1. data i as whole number 2. data j as whole number 3. data str as array(2)(2) of String 4. str[0][0] = "Nepal" 5. str[0][1] = "America" 6. str[1][0] = "Australia" 7. str[1][1] = "England"

Two Dimensional Arrays Example 8. i = 0 9. loop while i is less than sizeof(str) 10. j = 0 11. loop while j is less than sizeof(str[i]) 12. Output str[i][j] 13. j = j + 1 14. end loop 15. i = i + 1 16. end loop

END OF TOPIC 8

Add a comment

Related presentations

Related pages

SDT Topic - 08 - Education - documents

1. Topic 8 : Array Software Development Techniques . 2. Finding the Highest Number of 3 inputs . 3. Finding the Highest Number of 6 inputs . 4 ...
Read more

Sdt | LinkedIn

SDT Topic - 08. 1,173 Views. SandeepJhunjhunwala. TP including SDT and DTAA. 52 Views. nelmezzodelnulla. Us sdt 2014_globaloutsourcinginsourcingsurvey ...
Read more

SDT Topic 06: Functions - Education - documents.mx

SDT Topic 06: Functions Jan 18, 2015 Education ... SDT Topic - 08. SDT Topic - 04. Ess topic 2.5 functions. Topic 06. Portfolio Management. Topic 06 : HTML ...
Read more

Samba4 und Netzlauferke • debianforum.de

von snyborg am 30.08.2015 11:54:14 . Hi, ich habe unseren Sambaserver von der Version 3 auf 4 gebracht, ... sdt.nethauser, SDThauser, SDT.NEThauser
Read more

SDT Ultrasonic Trending and amplification level | AMP ...

Like This Topic Follow This Topic. ... rotating equipment condition with a SDT 170 ultrasonic meter ... SDT Ultrasonic Trending and amplification level;
Read more

Sdt | LinkedIn

View 3605 Sdt posts, presentations, experts, and more. Get the professional knowledge you need on LinkedIn.
Read more

December '08 Meeting - Google Groups

Its time again to have more fun with Asterisk. This next meeting we will be configuring Asterisk servers to commuicate using DUNDi. With DUNDi, server can ...
Read more