Pemrograman Komputer Pertemuan 11 Array Bambang Heru Iswanto, Dr.rer.nat M.Si <ul><li>Jurusan Fisika </li></ul><ul><li>Fak...
Learning Outcomes <ul><li>Pada akhir pertemuan ini, diharapkan mahasiswa  </li></ul><ul><li>akan mampu : </li></ul><ul><li...
Outline Materi <ul><li>Introduction to Array </li></ul><ul><li>Declaring an Array </li></ul><ul><li>Using Arrays </li></ul...
Introduction to Array <ul><li>Up to now, we have dealt with single value data only: e.g. -47.29, True, “Smith” </li></ul><...
List Structures <ul><li>We can treat this kind of data as a group of related items, rather than separate ones </li></ul><u...
Array Subscripts <ul><li>The group (array or list) is given a name, but the individual items in the group are referred to ...
Why Use Arrays <ul><li>Being able to group data into lists or arrays is an advantage </li></ul><ul><ul><li>mirrors the rea...
Common Array Processing Task <ul><li>Array initialisation </li></ul><ul><li>Input of data to an array (from keyboard or ex...
Array <ul><li>Imagine we need to store the marks of a group of 10 students studying VB. We decide to store the marks in an...
Declaring an Array <ul><li>To declare an array, we need to: </li></ul><ul><ul><li>give the array an identifier </li></ul><...
Initialize the Array <ul><li>It is good practice to initialise (set to a known value) variables before use. </li></ul><ul>...
TERIMA  KASIH 01/02/11 ©  2010 Universitas Negeri Jakarta  |  www.unj.ac.id  |
Upcoming SlideShare
Loading in …5
×

Pemrograman komputer 11 (array)

709 views

Published on

unj fmipa-fisika

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
709
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Pemrograman komputer 11 (array)

  1. 1. Pemrograman Komputer Pertemuan 11 Array Bambang Heru Iswanto, Dr.rer.nat M.Si <ul><li>Jurusan Fisika </li></ul><ul><li>Fakultas Matematika dan Ilmu Pengetahuan Alam </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  2. 2. Learning Outcomes <ul><li>Pada akhir pertemuan ini, diharapkan mahasiswa </li></ul><ul><li>akan mampu : </li></ul><ul><li>Menerapkan penggunaan array dalam aplikasi </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  3. 3. Outline Materi <ul><li>Introduction to Array </li></ul><ul><li>Declaring an Array </li></ul><ul><li>Using Arrays </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  4. 4. Introduction to Array <ul><li>Up to now, we have dealt with single value data only: e.g. -47.29, True, “Smith” </li></ul><ul><li>For each data item we have used a single variable name: e.g. sum, endOfInput, aName </li></ul><ul><li>Suppose we need to store the names of everyone in this group. </li></ul><ul><li>We could use a unique name for each variable, e.g. name1, name2, name3 … </li></ul><ul><li>This would be time-consuming, tedious and unworkable with even larger sets of numbers </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  5. 5. List Structures <ul><li>We can treat this kind of data as a group of related items, rather than separate ones </li></ul><ul><li>We can reserve a storage area large enough for all the values then assign a name to the area </li></ul><ul><li>This data structure may be called a single-level table, a list, a vector or a one-dimensional array </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  6. 6. Array Subscripts <ul><li>The group (array or list) is given a name, but the individual items in the group are referred to by their position in the array – using a subscript in brackets </li></ul><ul><li>So with a group called students, students(3) is the 4 th value (as the numbering starts at 0). </li></ul><ul><li>It is similar to a street where all the houses have the same street name, but are distinguished by their house number. </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  7. 7. Why Use Arrays <ul><li>Being able to group data into lists or arrays is an advantage </li></ul><ul><ul><li>mirrors the real world way of working </li></ul></ul><ul><ul><ul><li>much data in business and science is already grouped </li></ul></ul></ul><ul><ul><li>allows computer memory to be used most effectively </li></ul></ul><ul><ul><ul><li>efficient allocation of storage to variables </li></ul></ul></ul><ul><ul><ul><li>faster data access to array elements </li></ul></ul></ul><ul><ul><li>allows the writing of efficient program code </li></ul></ul><ul><ul><ul><li>write the code to process one value in the array </li></ul></ul></ul><ul><ul><ul><li>then make it repeat for all the other values </li></ul></ul></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  8. 8. Common Array Processing Task <ul><li>Array initialisation </li></ul><ul><li>Input of data to an array (from keyboard or external data file) </li></ul><ul><li>Output of the contents of an array (to screen or external data file) </li></ul><ul><li>Searching an array for a specific value </li></ul><ul><li>Counting or summing values in the array </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  9. 9. Array <ul><li>Imagine we need to store the marks of a group of 10 students studying VB. We decide to store the marks in an array called VBmarks. </li></ul><ul><li>If we could visualise the array, it might look like this. </li></ul>VBmarks(0) VBmarks(9) 01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  10. 10. Declaring an Array <ul><li>To declare an array, we need to: </li></ul><ul><ul><li>give the array an identifier </li></ul></ul><ul><ul><li>state how many data elements the array should hold </li></ul></ul><ul><ul><li>specify the type of data to be held in that array </li></ul></ul><ul><li>E.g. </li></ul><ul><ul><li>Dim vbMarks (0 To 9) as Integer </li></ul></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  11. 11. Initialize the Array <ul><li>It is good practice to initialise (set to a known value) variables before use. </li></ul><ul><li>So we will initialise all the array elements to zero: </li></ul><ul><li>FOR posisi = 0 TO 9 </li></ul><ul><li>VBmarks( posisi ) = 0 </li></ul><ul><li>NEXT posisi </li></ul><ul><li>You might now visualise the array as this: </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id | 0 0 0 0 0 0 0 0 0 0
  12. 12. TERIMA KASIH 01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |

×