Data Types
Data Types
Computer programs need to process and store data
Programming languages define different data types to
store different types of data
We are interested in the following data types:
Integer, Real, String, Boolean, One-Dimensional Arrays
and Records
Integer
 An integer data type is used to store a whole number
 An integer can be positive or negative and includes 0
 e.g. 4, 1025, -27, 0, -911, 1
Real
 A real data type is used to store a decimal number
 A real can be positive or negative and includes 0
 e.g. 22.1, -13.775, 0.00, -5.15, 102.4258
String
 A string data type is used to represent alphanumeric
data (i.e. text)
 e.g. "Hello World", "0131 334 9262",
"How are you today?", "ABC-DEF-%£$-123"
 Most programming languages provide ways to
manipulate strings
e.g. get the string length, get the first character, get the
4th-6th characters, find the first space
Boolean
 A boolean data type can only represent 2 values: true
or false.
 Depending on the programming language true can also
be a 1 or yes, while false can be a 0 or no
One Dimensional Arrays
 An array is a series of objects all of which are the same type
 Each object in an array is called an array element
 The index of the first array element is normally zero
 Arrays are useful in programming because they can be used
with a loop
(eg count occurrences, linear search, find max/min)
One Dimensional Arrays
An example array of integers: The winning lottery balls
Uses:
Write a program to loop through checking a user’s
lottery numbers
One Dimensional Arrays
An example array of reals: Daily temperatures over a week
Uses:
Write a program to calculate the average daily
temperature in a week
One Dimensional Arrays
An example array of Strings: Pupil names
Uses:
Write a program to sort pupils into alphabetical order
Record
A record can be used to store variables of different data
types.
This pseudocode shows how to declare a record
structure.
Array of Records
In order to store multiple records, it is useful to use an
array.
This pseudocode shows how to declare an array of 20
records of data type UserRecord.
Array of Records
The following pseudocode shows how to loop through an
array of records, accessing individual fields.

SD & D Data Types

  • 1.
  • 2.
    Data Types Computer programsneed to process and store data Programming languages define different data types to store different types of data We are interested in the following data types: Integer, Real, String, Boolean, One-Dimensional Arrays and Records
  • 3.
    Integer  An integerdata type is used to store a whole number  An integer can be positive or negative and includes 0  e.g. 4, 1025, -27, 0, -911, 1
  • 4.
    Real  A realdata type is used to store a decimal number  A real can be positive or negative and includes 0  e.g. 22.1, -13.775, 0.00, -5.15, 102.4258
  • 5.
    String  A stringdata type is used to represent alphanumeric data (i.e. text)  e.g. "Hello World", "0131 334 9262", "How are you today?", "ABC-DEF-%£$-123"  Most programming languages provide ways to manipulate strings e.g. get the string length, get the first character, get the 4th-6th characters, find the first space
  • 6.
    Boolean  A booleandata type can only represent 2 values: true or false.  Depending on the programming language true can also be a 1 or yes, while false can be a 0 or no
  • 7.
    One Dimensional Arrays An array is a series of objects all of which are the same type  Each object in an array is called an array element  The index of the first array element is normally zero  Arrays are useful in programming because they can be used with a loop (eg count occurrences, linear search, find max/min)
  • 8.
    One Dimensional Arrays Anexample array of integers: The winning lottery balls Uses: Write a program to loop through checking a user’s lottery numbers
  • 9.
    One Dimensional Arrays Anexample array of reals: Daily temperatures over a week Uses: Write a program to calculate the average daily temperature in a week
  • 10.
    One Dimensional Arrays Anexample array of Strings: Pupil names Uses: Write a program to sort pupils into alphabetical order
  • 11.
    Record A record canbe used to store variables of different data types. This pseudocode shows how to declare a record structure.
  • 12.
    Array of Records Inorder to store multiple records, it is useful to use an array. This pseudocode shows how to declare an array of 20 records of data type UserRecord.
  • 13.
    Array of Records Thefollowing pseudocode shows how to loop through an array of records, accessing individual fields.