Data Structures [1] - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Data Structures [1]

Description:

Data Structures [1] CP1 Arrays All data must be the same data type . Eg. (Daily sales figures for John - to nearest ) Mon 240 Tue 230 Wed 180 Thu 270 Fri 120 (All ... – PowerPoint PPT presentation

Number of Views:217
Avg rating:3.0/5.0
Slides: 11
Provided by: pete3162
Category:

less

Transcript and Presenter's Notes

Title: Data Structures [1]


1
Data Structures 1
CP1
2
Arrays
  • All data must be the same data type.
  • Eg. (Daily sales figures for John - to nearest )
  • Mon 240
  • Tue 230
  • Wed 180
  • Thu 270
  • Fri 120
  • (All of data type Integer)

3
In Visual Basic
  • Dim Sales(5) As Integer
  • A one-dimensional array has one subscript to
    identify the element of the array.
  • Eg.
  • Mon 240
  • Tue 230
  • Wed 180
  • Thu 270
  • Fri 120

?Sales(4)
4
Two-dimensional Arrays
  • Data must be the same type.
  • A two-dimensional array has 2 subscripts.

Eg. Sales figures for John, Mary and
Sue John Mary Sue Mon 240 420 140 Tue 230 380 1
90 Wed 180 400 210 Thu 270 360 240 Fri 120 320 190
? Sales(4,2)
5
Three-dimensional Arrays
  • Data must be the same type.
  • A two-dimensional array has 3 subscripts.

Eg. Sales figures for John, Mary and Sue for each
of three different items
Item 1 John Mary Sue Mon 240 420 140 Tue 230 380 1
90 Wed 180 400 210 Thu 270 360 240 Fri 120 320 190

Item 2 John Mary Sue Mon 440 440 120 Tue 530 380 3
90 Wed 480 440 280 Thu 670 365 540 Fri 150 310 490

Item 3 John Mary Sue Mon 210 430 120 Tue 130 280 1
90 Wed 120 100 220 Thu 270 320 143 Fri 120 220 295

6
  • and YES! In programming you can have Arrays with
    more than three dimensions
  • All data must be of the same data type
  • An n-dimensional array would use n subscripts to
    identify each element.

7
Records
  • Data may be of different types
  • Eg. (Name, Form, DOB, Exam mark)
  • John Smith
  • 12 T
  • 12/04/85
  • 65

(Text strings, a date and a number)
8
In Visual Basic
  • Structure PupilType
  • Dim PupilName As String
  • Dim Form As String
  • Dim DOB As Date
  • Dim ExamMark As Integer
  • End Structure

9
  • Structure PupilType
  • Dim PupilName As String
  • Dim Form As String
  • Dim DOB As Date
  • Dim ExamMark As Integer
  • End Structure
  • A variable Pupil can be declared as being of type
    PupilType, and the fields assigned
  • Dim Pupil As PupilType
  • Pupil.PupilName John Smith
  • Pupil.Form 12T
  • Pupil.DOB12.04.85
  • Pupil.ExamMark 65

10
Arrays of Records
An array of records is sometimes called a
TABLE. Each record has a subscriptIf this table
was called Markbook, then Markbook(4).ExamMark
is 44.
PupilName Form DOB ExamMark
1 John Smith 12T 12/04/85 65
2 Sally Jones 12G 15/05/85 78
3 Tom Jenkins 12G 19/11/84 52
4 Ruby Day 12T 06/01/85 44
5 Jenny Thomas 12B 07/12/84 60
Write a Comment
User Comments (0)
About PowerShow.com