B065: PROGRAMMING Variables 2. Starter  What is wrong with the following piece of code: Option Explicit Off Dim num1 as string Dim num2 as integer num1.

Slides:



Advertisements
Similar presentations
Ch. 3 Variables VB.Net Programming. Data Types Boolean – True or False values Short – Small integers (+/- 32,767) Integer – Medium-size integers (+/-
Advertisements

Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Variables and Constants
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 2 Data Types, Declarations, and Displays
Chapter 2 Data Types, Declarations, and Displays.
.NET Data types. Introduction ٭ A "data type" is a class that is primarily used just to hold data. ٭ This is different from most other classes since they're.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Chapter 2: Using Data.
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Tutorial 6 Introducing Variables, Memory Concepts & Arithmetic.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Java Simple Types CSIS 3701: Advanced Object Oriented Programming.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Python Programming Using Variables and input. Objectives We’re learning to use basic knowledge of variables combined with user input. Outcomes Continue.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
Introduction to Programming
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Chapter 2 Variables.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Programming with Microsoft Visual Basic th Edition
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
1.2 Primitive Data Types and Variables
VB.NET 2008 Introduction to Variables Part 1. Overview.NET Languages –Source Code –Compiler –MSIL –CLR & Windows Variables –Data Types –Converting.
DATA TYPES, VARIABLES AND CONSTANTS. LEARNING OBJECTIVES  Be able to identify and explain the difference between data and information  Be able to identify,
Data Handling in Algorithms. Activity 1 Starter Task: Quickly complete the sheet 5mins!
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Introduction to Python Lesson 2a Print and Types.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Chapter # 2 Part 2 Programs And data
Last week: We talked about: History of C Compiler for C programming
Week 2 - Wednesday CS 121.
Chapter 2 Variables.
Data Types, Arithmetic Operations
Variables ,Data Types and Constants
CS1S467 GUI Programming Lecture 3 Variables 2.
Introduction to Abstract Data Types
Chapter 2 Variables.
C++ Data Types Data Type
Chapter 2: Java Fundamentals
Chapter # 2 Part 2 Programs And data
CHAPTER FOUR VARIABLES AND CONSTANTS
B065: PROGRAMMING Variables 1.
Chap 2. Identifiers, Keywords, and Types
B065: PROGRAMMING Variables 2.
Chapter 2 Variables.
Variables and Constants
Data Types and Expressions
Data Types and Expressions
Presentation transcript:

B065: PROGRAMMING Variables 2

Starter  What is wrong with the following piece of code: Option Explicit Off Dim num1 as string Dim num2 as integer num1 = 12 num2 = 19 num3 = num1+num2 console.writeline(num3)

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

Recap: Variables 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.

Recap: The Variable Concept 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. SYSTEM MEMORY strStudentName “Chris Jones” strStudentName “Chris Jones” intTest1Score 12 intTest1Score 12 intTest2Score 78 intTest2Score 78 sngPercent sngPercent 25.36

Recap: Variable Types Built-in-typeDescriptionMemory AllocatedRangeExample IntegerSigned 32-bit number4 bytes -2,147,483,648 to 2,147,483, ByteUnsigned 8-bit number1 byte0 to Single Single precision floating point number 4 bytes n/a (limited to 7 digits) 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 Char A single Unicode character (e.g. a symbol) 1 byte-& $ £ StringA 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!

Recap: 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”

Recap: 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”

Variables vs. Constants We know that a variable is something which changes. What if we want to use a value which does not change within our code. For example VAT. Yes we could put it in a variable, but what if we accidently assign a value to it and overwrite the VAT rate. Instead we could use a CONSTANT.

Constant Declaration This is done in a similar way to variable declarations. Instead of the word “Dim,” you use “Const.” The biggest difference is that you assign a value at the same time as declaration. E.g. Const VAT as Single = 17.5 You can refer to it in the normal way. Let’s look at an example. Comments have been removed. See if you can explain what is going on.

Tasks Come up with your own working example of the use of a constant.

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

Plenary Questions: – How do you declare a variable? – How do you declare a constant? – What is a constant and why would you use it? – How many variable TYPES can you name?

Required Reading 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: Pre-reading Chapter 4 of your handbook