Tutorial 6 Introducing Variables, Memory Concepts & Arithmetic.

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.
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 in VB Keeping Track. Variables Variables are named places in the computer memory that hold information. Variables hold only a single value at.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Chapter 31 Fundamentals of Programming in VB(Continue I) Numbers Arithmetic Operations Variables Incrementing the Value of a Variable.
Chapter 2 Data Types, Declarations, and Displays
01- Intro-Java-part1 1 Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2008.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Chapter 2: Using Data.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
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.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
COMP Primitive and Class Types Yi Hong May 14, 2015.
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.
Monday, January 14 Homework #1 is posted on the website Homework #1 is posted on the website Due before class, Jan. 16 Due before class, Jan. 16.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
© A+ Computer Science - A reference variable stores the memory address of an object. Monster fred = new Monster(); Monster sally.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
Variables in VB. What is a variable? ► A named memory location that stores a value.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
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.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Data Type Summary (Visual Basic) Visual Basic typeCommon language runtime type structure Nominal storage allocation Value range Boolean Depends on implementing.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
7 - Programming 7J, K, L, M, N, O – Handling Data.
A variable is a name for a value stored in memory.
Chapter 2 Variables.
Data Types, Arithmetic Operations
ITEC113 Algorithms and Programming Techniques
Multiple variables can be created in one declaration
Introduction to C++ October 2, 2017.
Introduction to computers, the Internet & VB .Net
Introduction to Java, and DrJava part 1
Chapter 2 Variables.
Introduction to Java, and DrJava
The Data Element.
Primitive Types and Expressions
Unit 3: Variables in Java
B065: PROGRAMMING Variables 2.
Introduction to Java, and DrJava part 1
The Data Element.
Chapter 2 Variables.
Data Types and Maths Programming Guides.
DATA TYPES There are four basic data types associated with variables:
COMPUTING.
Presentation transcript:

Tutorial 6 Introducing Variables, Memory Concepts & Arithmetic

Variables Holds data Controls for Design Programming, Variables for Code Programming Text Property  Data  Variable Manipulate data w/o showing to users Store data w/o adding or using controls Hold numbers, data & time, text, and etc. Continue 

One type of variable can take the same type of data. E.g.  intCount = 15 (OK)  intCount = “Pat” (not OK)  intCount = “15” (not OK) Must be declared. E.g.  Dim intCount As Integer  Dim sngPrice As Single Continue 

Steps of Using Variables Declare Input: Assign a value by reading in from a control or other source Process: Use or manipulate Output: Put the value to a control or other object

Example 1: Dim intTotal As Integer intTotal = Val(txtTotal.Text) intTotal = intTotal + 10 txtTotal.Text = Str(intTotal)

Example 2: Dim intTotal As Integer Dim intExtra As Integer intTotal = Val(txtTotal.Text) intExtra = 10 intTotal = intTotal + intExtra txtTotal.Text = Str(intTotal)

Example 3: Dim intTotal As Integer Dim intExtra As Integer = 10 intTotal = Val(txtTotal.Text) intTotal = intTotal + intExtra txtTotal.Text = Str(intTotal)

Data Types of Variables Data TypeMemory AllocationValue Range Boolean2 bytesTrue or False. Char2 bytes0 through (unsigned). Date8 bytes0:00:00 on January 1, 0001 through 11:59:59 PM on December 31, StringDepends on platform0 to approximately 2 billion Unicode characters. Short2 bytes-32,768 through 32,767. Integer4 bytes-2,147,483,648 through 2,147,483,647. Long8 bytes-9,223,372,036,854,775,808 through 9,223,372,036,854,775,807. Single4 bytes E+38 through E-45 for negative values; E-45 through E+38 for positive values. Double8 bytes E+308 through E-324 for negative values; E-324 through E+308 for positive values. Decimal16 bytes0 through +/-79,228,162,514,264,337,593,543,950,335 with no decimal point; 0 through +/ with 28 places to the right of the decimal; smallest nonzero number is +/ (+/-1E-28).

Integer Stored as 32-bit (4-byte) integers ranging in value from -2,147,483,648 through 2,147,483,647. Provides optimal performance on a 32-bit processor, as the smaller integral types are slower to load and store from and to memory. You can convert the Integer data type to Long, Single, Double, or Decimal without encountering a System.OverflowException error.

Single Stored as IEEE 32-bit (4-byte) single-precision floating-point numbers ranging in value from E+38 through E-45 for negative values and from E-45 through E+38 for positive values. Single- precision numbers store an approximation of a real number. Can be converted to the Double or Decimal data type without encountering a System.OverflowException error.

String Stored as sequences of 16-bit (2-byte) numbers ranging in value from 0 through Each number represents a single Unicode character. A string can contain up to approximately 2 billion (2 ^ 31) Unicode characters The first 128 code points (0–127) of Unicode correspond to the letters and symbols on a standard U.S. keyboard The second 128 code points (128–255) represent special characters, such as Latin-based alphabet letters, accents, currency symbols, and fractions The remaining code points are used for a wide variety of symbols

Prefixes for Variables Data TypePrefixData TypePrefix BooleanblnIntegerint BytebytLonglng CurrencycurShortsht Date(time)dtmSinglesng DoubledblStringstr

Arithmetic Operators OrderOperatorMathematical OperationExample 1( )Parentheses 2^ExponentiationCubicSpace = Length ^ 3 8 = 2 ^ 3 3-Negation- Num1 4* or / Multiplication Division Total_Sales = Unit_Price * Count ClassAve = TotalScores / NumOfStudents 5\Integer Division (DIV). The whole number portion of the answer in a division. The decimal position is dropped. CarsCanFitIn = AreaOfLot \ CarDim 10 = 215 \ is leftover Continue 

OrderOperatorMathematical OperationExample 6MODInteger Remainder Division. The whole number portion of a remainder in a division. If the divider is greater than the number it is dividing, then the number become the remainder of the MOD division. BoothSpace = 3 MOD 10 3 = 3 MOD or - Addition Subtraction Total = Num1 + Num2 Profit = Sales - Expenses &String concatenationFullName$ = First$ & Last$

Using Debugger Demo