Numbers1 Working with Numbers There are times that we have to work with numerical values. When we count things, we need Integers or whole numbers. When.

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.
1 C Fundamentals - I Math 130 Lecture # 2 B Smith: Sp05: With discussion on labs, this took 53 minutes. Score 3. Many caveats. B Smith: Sp05: With discussion.
Types and Arithmetic Operators
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
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.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 04.
CS180 Recitation 3. Lecture: Overflow byte b; b = 127; b += 1; System.out.println("b is" + b); b is -128 byte b; b = 128; //will not compile! b went out.
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Objectives You should be able to describe: Data Types
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
D ATA T YPE. NUMBERS A number is an immutable type – means that changing or updating its value result in a newly allocated object. There are several types.
Python Types Python values are of various “types” Ints, Floats, Strings, Characters, and more Two representations of numbers 1 vs 1.0.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 3A Integral Data (Concepts)
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.
Operators in Python. Arithmetic operators Some operators in Python will look familiar (+, -, *, /) Others are new to you (%, //, **) All of these do work.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Equation Jeopardy Add Mixed Multiply/ Divide Fractions Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy Subtract.
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.
Boolean Logic Logical Operators Comparison Operators Truth tables.
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
Primitive Variables.
Lesson Two: Everything You Need to Know
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Programming with Visual C++: Concepts and Projects Chapter 3A: Integral Data (Concepts)
Copyright © – Curt Hill Types What they do.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
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)
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
Doing math In java.
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.
Chapter One Lesson Three DATA TYPES ©
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
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.
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.
What will each of the following lines print? System.out.println("number" ); number645 System.out.println("number" + (6 + 4)+ 5); number105 System.out.println(6.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
1.
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
Visual Basic Variables
Data Representation Binary Numbers Binary Addition
ITEC113 Algorithms and Programming Techniques
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Data Structures Mohammed Thajeel To the second year students
Visual Basic 6 Programming.
Numbers.
Chapter 2 Variables.
CSI 101 Elements of Computing Spring 2009
CHAPTER FOUR VARIABLES AND CONSTANTS
VB Variables and Data
Primitive Types and Expressions
Text Copyright (c) 2017 by Dr. E. Horvath
Variables and Constants
Primitive Data Types and Operators
Presentation transcript:

Numbers1 Working with Numbers There are times that we have to work with numerical values. When we count things, we need Integers or whole numbers. When we measure things, we need Rea Numbers or fractions.

Numbers2 Counting Things BYTE  Small range of values, 0 to 255 INTEGER  -32,768 to +32,767 LONG (integer)  -2,147,483,648 to +2,147,483,647 (no fractions, no rounding, fast and efficient means of working with whole numbers)

Numbers3 Measuring Things SINGLE (precision floating point)  E-45 to E38 DOUBLE (precision floating point)  E-327 to E308 (same range for negative numbers, data is rounded to either 7 or 14 digits of accuracy)

Numbers4 Highest Precision CURRENCY (scaled integer)  +/-922,337,203,685, DECIMAL  +/-79,228,162,514,262,337,593,543,950,335 or +/ (no rounding, slow but sure) BOOLEAN  False to True

Numbers5 Storage Space & Prefixes BYTE 1 byte byt INTEGER 2 bytesint LONG 4 byteslng SINGLE 4 bytessng DOUBLE 8 bytesdbl BOOLEAN 2 bytesbln CURRENCY 8 bytescur DECIMAL14 bytesdec

Numbers6 Good Practice You should give a numerical variables in Visual Basic a name that begins with an appropriate 3 character string. The 3 character string used is a good clue to the limits and the accuracy of the data type chosen. (The name is seen only by programmers)

Numbers7 Establishing Values Dim intValue as integer intValue = 12 intValue = ”12” intValue = 12.5 intValue = all result in the integer variable intValue being set to the number 12

Numbers8 Operators 1.^  Exponentiation 2.-  Unary Negation 3.* /  Multiplication and Division 4.\  Integer Division 5. MOD  Remainder  Addition and Subtraction (otherwise left to right)

Numbers9 Precedence Examples sng A = ( ) / ( ) results: sng A = sng B = ( ) / results: sng B = 0.50 sng C = 3 * 4 / 2 * 3 results: sng C = sng D = ( 3 * 4 ) / ( 2 * 3 ) results: sng D = 2.00

Numbers10 Real & Integer Arithmetic sng A = 5 / 2 results: sngA = 2.50 sng B = 5 \ 2 results: sngB = 2.00 int C = 5 MOD 2 results: int C = 1 int D = 5 / 2 results: intD = 2

Numbers11 Numerical Functions In addition to the operators, there are a great many functions that may be used to process numbers. A few of them follow this slide.

Numbers12 Numerical Functions intA = ABS( -5 ) results: int A = 5 (zero or positive) intB = SGN( -3 ) results: int B = -1 (either 1, 0 or -1) intC = INT( 6 * RND + 1 ) results: intC will be 1, 2, 3, 4, 5 or 6

Numbers13 Format Function (1)

Numbers14 Format Function (2) sngFoo = val(txtFoobar.Text) Label1.Caption = _ (note the underscores) Format(sngFoo, ”$#,##0.00”) Label2.Caption = _ Format(sngFoo, ”h:mmAMPM”) Label3.Caption = _ Format(sngFoo, "0.000e+00")

Numbers15 Format Function (3) For more information on the Format Function see page 82 and page 264 in the textbook.

Numbers16 To Learn More... Using VB Help, remember to get into the “visual basic documentation” active subset. Enter the keyword “format” and click on “format function”.