of 10

# National 5 Data Types

National 5 Computing Science Data Types
Published on: Mar 3, 2016
Published in: Education
Source: www.slideshare.net

#### Transcripts - National 5 Data Types

• 1. Data Types
• 2. 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
• 3. 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
• 4. 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
• 5. 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
• 6. 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
• 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 An example array of integers: The winning lottery balls Uses: Write a program to loop through checking a user’s lottery numbers
• 9. 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
• 10. One Dimensional Arrays An example array of Strings: Pupil names Uses: Write a program to sort pupils into alphabetical order