Presentation is loading. Please wait.

Presentation is loading. Please wait.

B065: PROGRAMMING Variables 1.

Similar presentations


Presentation on theme: "B065: PROGRAMMING Variables 1."— Presentation transcript:

1 B065: PROGRAMMING Variables 1

2 Starter Sort the cards you have been given into appropriate piles.
Think about similarities between the cards. Name each category. We will feedback in 5 minutes.

3 Starter Review How did you classify them?
Were you correct? Let’s see: ANSWERS

4 Objectives Develop our knowledge of programming.
Understand the concept of variables. Demonstrate the use of variables and variable types.

5 Variables So far, you have written programs which display information on screen. It does not remember this information though. A variable is the name for a storage location allocated to a piece of data. The value of the data can change. This is why it is called a variable. A variable is given a name so you refer to it in your code. This is called an identifier. Variables should be initialised with a starting value and then can be assigned data.

6 Why use Variables? Some Examples
What if you wanted to store customer details and work on them? What if you wanted to perform some calculations on some values, and keep the result for something? What if you want to keep information to save to file later? Without variables, your program would be VERY limited in functionality. It would not have any REAL functionality.

7 The Variable Concept Here there are FOUR variables in system memory.
strStudentName “Chris Jones” intTest1Score 12 intTest2Score 78 sngPercent 25.36 Here there are FOUR variables in system memory. Each are different TYPES They have been ASSIGNED specific values. They each have their own unique IDENTIFIERS. A variable only stores ONE type of data.

8 Variable Types When using variables, you need to think about:
Built-in-type Description Memory Allocated Range Example Integer Signed 32-bit number 4 bytes -2,147,483,648 to 2,147,483,648 12000 Byte Unsigned 8-bit number 1 byte 0 to 255 25 Single Single precision floating point number n/a (limited to 7 digits) 23.52 Double Double Precision floating point number 8 bytes n/a (limited to 15 digits) Decimal Used when minimising rounding errors, ideal for working with currency. 16 bytes - 12.34 Char A single Unicode character (e.g. a symbol) & $ £ String A set of characters together. As required – depends on length of string. “Hello World” When using variables, you need to think about: What data is being stored. What you need to do with the data. How much memory is taken up – this is IMPORTANT!

9 Working with Variables
Option Explicit On – THIS IS VITAL and good practice. A variable is created by “dimensioning” a part of memory, giving it a name, and stating its type. Refer back to HOUSE STYLE when using variable names. Once declared, you can ASSIGN values (This is called Assignment). E.g. strStudentName = “Hello”

10 Declaring Multiple Variables
You can declare multiple variables on the same line. It is considered good practice to only declare variables of the same type on any one line. Once declared, you can ASSIGN values (This is called Assignment). E.g. strStudentName = “Hello”

11 House Style Reminder Variable Type Example Name String strStudentName
Boolean blnFileFound Integer intTotalScore Double dblSalesMean Single sngPercentageSales Long (integer) lngSalesToDate

12 DEMONSTRATION Looking at a program which uses variables
Creating a program using variables (students and scores)

13 Tasks Have a go at the activities outlined in Chapter 2 of your handbook booklet. Think about: What VARIABLES you need. What TYPE each variable should be. Finished? Read up on Constants and try the example given on page 14 – Chapter 3

14 Objectives Review Develop our knowledge of programming.
Understand the concept of variables. Demonstrate the use of variables and variable types.

15 Required Reading Read Chapter 2 & 3
Each week you will be given required reading. If you fail to do this, you will 100% find the lessons which follow it EXTREMELY difficult. Before next lesson you should have read: Read Chapter 2 & 3 Homework – Answer questions 1-4 on page 15 Have a go at the extension ones as well on page 16


Download ppt "B065: PROGRAMMING Variables 1."

Similar presentations


Ads by Google