2. Chapter Objectives At the completion of this chapter, you
would have learnt: the different types of data; the different types
of data structures.
3. Introduction Data is any collection of numbers, characters
or other symbols that has been coded into a format that can be
input into a computer and processed. The main function of a
computer program is to process data to produce information. That
is, to accept data from the user as input, process the data and
present the information to the user as output
4. 3.1 Types of Data There are two fundamental types of data:
Numeric and Non-numeric. Numeric(Qualitative) Numbers used for sums
of money, ages, distances. For example 0.33, -0.1, 0.5, 2, 50.01,
-100, etc. Non-Numeric(Quantitative) Non numbers such as strings of
characters. For example John, AS1234G and 2@**556, etc.
5. DATA DIAGRAM Data Numeric Non Numeric Char String Logical
Pointer DatesInteger Real
6. 3.1.1 Numeric Divided into two main groups: Integer and
Real. Integer Whole numbers used to count things, example 1, 2,
3,... Count discrete objects such as number of bananas, orange or
pencils. Precise values. The range of integers provided in a
computer system depends on the hardware/language used.
7. REAL May have a fractional part, example 1.0, 234.66, ...
Can be positive or negative. To measure things like the length of a
piece of string, or the cost of an item in dollars and cents.
Generally NOT a precise value. Nearest value is according to the
method of storage and type of arithmetic used (e.g. for rounding
off method, 14.385 in this case will become 14.39 and 14.382 will
become 14.38 whereas for truncation to two decimal places both
14.385 and 14.382 will become 14.38).
8. 3.1.2 Non-Numeric 1. Character strings Character strings may
consist of Numbers, Alphabets or Alphanumeric. To represent such
character strings, quotes () are needed. For example the name JAMES
will need to be quoted as JAMES.
9. 2. String String characters are stored as codes using the
American Standard Code for Information Interchange (ASCII) or
Extended Binary Coded Decimal Interchange Code (EBCDIC) code
system. String operation usually involves comparison, concatenation
or selection to allow combinations of strings. Thus strings should
have different values also. For example, A < Z, ABC > AAA
Alpha < Alphabet and lowercase characters > Uppercase
characters
10. 3.Logical / Boolean data Consists of 2 values: True or
False. 4.Pointers which store the address of variables. 5. Dates
which allow arithmetic operation on calendar dates.
11. 3.1.3 Identifiers All data items used in a program need to
be declared before usage. This means to state down the name given
to each data item storage cell known as identifier. An identifier
may be numeric or non- numeric. The data type that can be contained
in the storage cell will depend on the declaration of the
cell.
12. These storage cells can be a constant storage cell or
variable storage cell. Constants It is a Read-only variable which
contains fixed data values that cannot be changed during the
program execution. Variables Their content changes according to the
users input or the processing of the program during execution.
13. 3.2 Types of Data Structure Data items grouped logically
together to give information about an individual. For example, an
address book is a data structure containing data items (names,
addresses, phone numbers etc.). 3.2.1 Arrays and Tables 3.2.2
Structured Diagrams 3.2.3 Static vs. Dynamic Data Structure 3.2.4
Files, Records and Fields
14. 3.2.1 Arrays and Tables An array is a sequence of
consecutive storage locations having a common name. Refer to the
contents of the storage cells of each array element by a subscript
or index which is enclosed with a square bracket, e.g. [1], [5,3]
or [counter]. Grouping of variables in an array of several
elements. For example, a one-dimensional array that stored 6 test
marks of a student. This array is called StudentFile. StudentFile
76 77 78 56 89 90 0 1 2 3 4 5
15. The value in each of the box stores a test mark. Refer to
the contents of the storage cell of each array element by a
subscript or index. For example, to refer to the test mark in box
number 3, what you will need to do is to call the array by its
name, followed by the subscript or index shown below it. In this
case, you can refer to the contents of box number 3 by calling
StudentFile[3]. A one dimensional array can only hold a students
test marks in this case, so if a data structure that is supposed to
be created to store all the test marks of a class of students, a
two dimensional array must be used. A two dimensional array is a
table that can store more information. An example is shown on the
next page.
16. A two-dimensional array that stores 6 tests marks of 3
students. StudentFile In this case, you can refer to the content of
the third box in the first row by calling StudentFile[1,3]. 1 76 77
78 56 89 90 2 76 89 87 47 85 58 3 56 34 78 67 98 76 1 2 3 4 5
6
17. 3.2.2 Structured Diagrams To show the grouping and
relationship of data items in a real case in pictorial form, we can
use data structure diagrams. Characteristics of a Structured
Diagram Shows how to sub-divide a data item into its parts using
the three data structure constructs. Three Data Structure
Constructs Simple elements such as address can be represented with
a rectangle box. 1. Sequence Construction 2. Selection Construction
3. Repetition/Iteration Construction Address
18. Three Data Structure Constructs Simple with lower level -
To show its contents more clearly, it is sub-divided into different
parts shown at the lower level in the following diagrams. Address
Street Name Postal CodeHouse Number (Sequence construct) (Selection
construct) CAR SALOON ESTATESPORTS O O O
19. Note: If one element connected upwards is a selection, all
elements connected up to the same point must be selections. Only
one selection will be made regardless of the number of choices.
Example: (Repetition / Iteration construct) Main Process EndIntro
*
20. Data Structure on an Address Book FILE RECORD TRAILERHEADER
* ADDRESS TELEPHONENAME INITIALSSURNAME UNIT-CODEAREA CODE STREET
TOWNHOUSE NAMENUMBER oo
21. 3.2.3 Static vs. Dynamic Data Structure STATIC data
structure - the size of the data structure needed to store
information CANNOT change as the program runs. E.g. array. DYNAMIC
data structure - the size of the data structure needed to store
information CAN change as the program runs. E.g. linked list. Each
member of the list essentially forms a record in the list. Each
member record is linked to the NEXT LOGICAL RECORD by means of a
special field within the record called a POINTER. The POINTER field
contains the address of the next logical record in the list. Note:
Not all languages have linked lists.
22. Types of linked lists are Binary tree Ring Start point
23. 3.2.4Files, Records and Fields File A file is defined as a
group of related data records handled as a logical unit. For
example, the stock master file contains data records of all stock
items in the warehouse, the payroll master file contains data
records of all employees currently on the payroll of the
organisation.
24. Record A record is defined as a group of related data items
called fields, forming a logical unit. For example, the stock
master record may contain data items like ITEM-CODE, DESCRIPTION,
UNIT-PRICE, QUANTITY-ON- HAND and so on. These data items make up
the stock master record, and they are called FIELDS.
25. Field A field is a data item forming a subdivision of a
record. Record no. 1 Student Number Student Name Date of Birth Sex
Exam Mark 1289 Cindy Bridges 080471 F 76 1290 Alan Lim 060970 M 80
Record no. 1 Record no. 2 File Fields
26. Record key Definition A record key is defined as a field
within a record that is used as the basis for ordering the records
in a sequential file and also as a means of direct access. Examples
STOCK MASTER file arranged in ascending order of item code which is
the record key that must be unique. SUPPLIER MASTER field arranged
in order of vendor number, which is the record key.