B065: PROGRAMMING Variables 2.

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

IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
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.
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.
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.
Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
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.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
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.
M.T.Stanhope Oct Title : C++ Basics Bolton Institute - Faculty of Technology (Engineering) 1 C++ Basics u Data types. u Variables and Constants.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
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.
Introduction to Programming
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
Chapter 2 Variables.
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.
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.
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.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
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.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Constants, Data Types and Variables
Fundamentals 2.
Floating Point Numbers
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.
User Interaction and Variables
How Computers Store Variables
Data Types, Variables & Arithmetic
Data Types, Arithmetic Operations
EPSII 59:006 Spring 2004.
Chapter 2: Introduction to C++
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 Part 2 Programs And data
CHAPTER FOUR VARIABLES AND CONSTANTS
Chapter 2: Introduction to C++.
Data Types and Expressions
C++ Programming Lecture 3 C++ Basics – Part I
B065: PROGRAMMING Variables 1.
Chap 2. Identifiers, Keywords, and Types
Chapter 2 Variables.
Variables in C Topics Naming Variables Declaring Variables
Variables and Constants
Data Types and Expressions
Data Types and Expressions
Section 6 Primitive Data Types
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 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.

Recap: 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) 25.6744322 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!

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. Answer the questions on page 15 of the Console Handbook Create the Program in Topic 2 of the Windows Handbook

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?