B065: PROGRAMMING Variables 1.

Slides:



Advertisements
Similar presentations
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Advertisements

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.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Data types and variables
Chapter 2 Data Types, Declarations, and Displays
Objectives You should be able to describe: Data Types
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.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
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.
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.
Lecture #5 Introduction to C++
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.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
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.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
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
Chapter One Lesson Three DATA TYPES ©
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
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.
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.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
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.
Objectives Today: P4 Data Types – Floating Points P4 Variable Quiz P3 Iteration and Selection Practical Are you logged on? Then come around the table Unit.
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.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
User Interaction and Variables
Chapter 2 Basic Computation
Chapter 6: Data Types Lectures # 10.
Data Types, Arithmetic Operations
Objectives Identify the built-in data types in C++
EPSII 59:006 Spring 2004.
Other Kinds of Arrays Chapter 11
Starter Question In your jotter write the pseudocode to take in two numbers, add them together then display the answer. Declare variables RECEIVE firstNumber.
Variables ,Data Types and Constants
IDENTIFIERS CSC 111.
CS1S467 GUI Programming Lecture 3 Variables 2.
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Introduction to Abstract Data Types
Chapter 2 Variables.
Chapter 2: Java Fundamentals
CHAPTER FOUR VARIABLES AND CONSTANTS
Chapter 2: Java Fundamentals
Chapter 2: Introduction to C++.
C++ Programming Lecture 3 C++ Basics – Part I
Data Types and Expressions
EECE.2160 ECE Application Programming
Variables Here we go.
Unit 3: Variables in Java
B065: PROGRAMMING Variables 2.
Chapter 2 Variables.
EECE.2160 ECE Application Programming
Variables and Constants
Python Creating a calculator.
Section 6 Primitive Data Types
Presentation transcript:

B065: PROGRAMMING Variables 1

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.

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

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

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.

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.

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.

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!

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”

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”

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

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

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

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

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