Numbers.

Slides:



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

L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Types and Arithmetic Operators
Chapter 3.3 Numeric Data Types and Variables. Slide 2 Objectives Create variables to store information while a solution runs Perform computations with.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Data types and variables
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
JavaScript, Fourth Edition
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
JavaScript, Third Edition
VB DATATYPES, VARIABLES, CONSTANTS & CALCULATIONS.
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
Variables & Math Operators CE 311 K - Introduction to Computer Methods Daene C. McKinney.
CS0004: Introduction to Programming Variables – Numbers.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Primitive Data Types and Operations Identifiers, Variables, and Constants Primitive Data Types Byte, short, int, long, float, double, char, boolean Casting.
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
Chapter 2: Using Data.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
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)
Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
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.
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.
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.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Egyptian Language School Computer Department
A variable is a name for a value stored in memory.
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
Chapter 2 Basic Computation
BASIC ELEMENTS OF A COMPUTER PROGRAM
Visual Basic Variables
Fundamentals of PL/SQL part 1 (Basics)
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.
Multiple variables can be created in one declaration
Java Programming: From Problem Analysis to Program Design, 4e
2.1 Parts of a C++ Program.
Introduction to C++ Programming
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Numerical Data Types.
Fundamentals of Programming in VB.NET
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
Chapter 2 Variables.
C++ Data Types Data Type
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Core Objects, Variables, Input, and Output
SELECTIONS STATEMENTS
Chapter 2: Introduction to C++.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Introduction to Primitives
Introduction to Primitives
An Introduction to Programming with C++ Fifth Edition
Primitive Types and Expressions
Module 2 Variables, Data Types and Arithmetic
Chapter 2 Variables.
Chapter 2 Primitive Data Types and Operations
Variables and Constants
Presentation transcript:

Numbers

Numbers Arithmetic Operations Display numbers in VB.NET Variables Built_in Functions Three types of errors 12/1/2018 Numbers

Arithmetic Operations Numbers are called numeric literals Five arithmetic operations in VB.NET + addition 3 + 2 - subtraction 3 - 2 * multiplication 3 * 2 / division 3 / 2 ^ exponentiation 3 ^ 2 12/1/2018 Numbers

Precedence of Arithmetic operation Level of precedence: () Inner to outer,left to right ^ Left to right in expression * / Left to right in expression + - Left to right in expression 12/1/2018 Numbers

Scientific Notation Scientific notation represents a number by using power of 10 to stand for zeros In VB.Net b • 10 r is written as bEr 12/1/2018 Numbers

Scientific Notation 10 –20 10 ^ - 20 1E-20 r is two digit number preceded by plus sign if r is positive and by a minus sign if r is negative 10 –20 10 ^ - 20 1E-20 1.2 • 10 13 1.2 * 10 ^ 13 1.2E+13 VB.NET’s choice of whether to display a number in a scientific or standard form depends on the magnitude of the number 12/1/2018 Numbers

Display numbers One way to show numbers on screen is to display them in a list box. lstNumbers.Items.Add(n) - Display number n as the last item in the list box lstNumbers.Items.Clear() - Erase all the items in the list box 12/1/2018 Numbers

Demonstration List a set of numbers in a list box. 12/1/2018 Numbers

Variables A variable is a name that is used to refer to an item of data. The value assigned to the variable may change. Up to 16,838 characters long Begin with a letter or an underscore Consist of only letters,digits and underscores A Variable name is written in lowercase letters except for the first letters of additional words, such as costOfIT201. 12/1/2018 Numbers

Data Type Type Stores Range Of Values Boolean Logical Values True or False Double Float-Point Numbers +/- 5E-324 to 1.8E308 Integer Integers -32,768 to 32767 Long +/- 2 billion Single Floating Point Numbers +/- 1E-45 to 3E38 String Text Information Fixed Length: 1 to 65,400 12/1/2018 Numbers

Const constantName As dataType = value Variable Declaration Declaration: Dim varName As dataType Variable name Data type Const constantName As dataType = value Variable that can’t change 12/1/2018 Numbers

Variable Declaration Dim declares a variable named varName to be of type dataType Dim causes computer to set aside a location in memory with the same name varName Dim also put the number zero in that memory location if varName is a numberic variable 12/1/2018 Numbers

Multiple Declarations multiple-declaration statements : Dim a, b As Double Dim a As Double, b As Integer Dim c As Double = 2, b As Integer = 5 12/1/2018 Numbers

Variable Initialization Numeric variables are automatically initialized to 0: Dim varName As Double To specify a nonzero initial value Dim varName As Double = 50 declares a variable named varName to be of type Double. Actually, the Dim statement causes the computer to set aside a location in memory with the name varName. Since varName is a numeric variable, the Dim statement also places the number zero in that memory location. (We say that zero is the initial value or default value of the variable.) 12/1/2018 Numbers

Assignment statement Assignment:(n is a literal) varName = n varName = expression 12/1/2018 Numbers

Rules for assigning variables Assign Integer, Long data type to a variable to store whole numbers Assign Single, Double to a variable to store decimal fraction Assign String to a variable to store a list of characters Assign Boolean data type to a variable whose value will be True or false Assign Date data type to a variable to store date and time information Assign Object data type to a variable to store reference to an object Choosing the data type in each group depending on the size o 12/1/2018 Numbers

Increment variable value To add 1 to the numeric variable var var = var + 1 Or as a shortcut var +=1 12/1/2018 Numbers

Built-in Functions Functions associates with one or more values and returns a value(output) Math.sqrt(n): Returns the square root of n. Math.Sqrt(9) is 3 Int(n): Returns greatest integer less than or equal to n Int(9.7) is 3 12/1/2018 Numbers

Built-in Functions Math.Round(2.5) is 2 Math.Round(n, r): number n rounded to r decimal places Math.Round(2.317,1) is 2.3 Math.Round(2.7) is 3 When n is halfway between two successive whole number, then it rounds to the nearest even number Math.Round(2.5) is 2 Math.Round(3.5) is 4 12/1/2018 Numbers

Three Types of Errors Syntax error – grammatical errors Run-time error misspellings, omissions,incorrect punctuation Run-time error occurs when program is running Logic error program doesn’t perform as it is intended 12/1/2018 Numbers