CHAPTER FOUR Performing Calculations and Manipulating Data: Expressions.

Slides:



Advertisements
Similar presentations
Java Programming, 3e Concepts and Techniques Chapter 3 Section 63 – Manipulating Data Using Methods – Day 2.
Advertisements

Types and Arithmetic Operators
Slide 1 VB Programming Fundamentals. Slide 2 Visual Basic Language v VB language is powerful and easy to use v Descendent of BASIC (Beginner's All-Purpose.
Introduction to C Programming
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.
Val Function A Function performs an action and returns a value The expression to operate upon, known as the argument, (or multiple arguments), must be.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
The number of calories burned per hour by cycling, jogging and swimming are 200, 475 and 275 respectively. A person loses 1pound of weight for each 3500.
1 Pertemuan 04 Expression Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
Data types and variables
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
Introduction to C Programming
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
CHAPTER THREE Representing Data: Constants and Variables.
Chapter 2 part #4 Operator
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
CHAPTER 2 PART #4 OPERATOR 2 nd semester King Saud University College of Applied studies and Community Service Csc 1101 By: Asma Alosaimi Edited.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
CPS120: Introduction to Computer Science Operations Lecture 9.
Manipulating Strings. What is a string? Data composed of text characters. The data is stored in consecutive bytes of memory. Each byte stores the ASCII.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Building Java Programs Primitive Data and Definite Loops.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Doing math In java.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Copyright © Don Kussee 1410-Ch4 #521 CNS 1120 Chapter 4 Performing Calculations & Manipulating Data 1120-Ch4.PPT.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
CHAPTER THREE Representing Data: Constants and Variables.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Representing Data: Constants and Variables
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
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
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Data Types, Arithmetic Operations
Data Types, Identifiers, and Expressions
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
Data Types, Identifiers, and Expressions
Chapter 8 JavaScript: Control Statements, Part 2
Arithmetic Expressions & Data Conversions
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.
Expressions.
Operator King Saud University
Arithmetic Expressions & Data Conversions
Building Java Programs
Presentation transcript:

CHAPTER FOUR Performing Calculations and Manipulating Data: Expressions

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Expressions Arithmetic expressions –To perform arithmetic operations. String expressions –To manipulate string data. Logical expressions –To select an appropriate action.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Using Expressions, Operators, and Functions in Visual Basic.NET Statements An expression tells the computer to manipulate data. The statement tells the computer what to do with the results of an expression. Expressions are composed of values, operators, and functions. lblGreeting.Text = “Hello “ & InputBox(“Enter Name:”) value operator function

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Using Expressions, Operators, and Functions in VB.NET Statements (cont.) Statements –Perform various tasks Evaluate expressions one at a time. Carry out tasks specified in expressions. Expressions –Single values or a combination of values, operators, and/or functions that reduce to a single value. –Evaluated by calculation or manipulation. –Result in numeric, string, or Boolean values.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Using Expressions, Operators, and Functions in VB.NET Statements (cont.) Operators –Symbols for a common operations such as addition or multiplication. –Most operators are binary operators. Functions –Descriptive names that specify a more complex operation than that performed by an operator. –Names are always followed by parentheses. –The value between the parentheses is called the argument. –The resulting value is called the return value.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Using Expressions, Operators, and Functions in VB.NET Statements (cont.) More Complicated Expressions –Operators and functions can be composed into complicated expressions. –A function’s argument may be complex. Ex. X = Math.Sqrt(10 + Math.Sqrt(Y + 29)) Expressions as a Part of Statements –An expression is always a part of a statement. Ex. Z = Math.Sqrt(X Y) + Math.Sqrt(4)

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Arithmetic Expressions Arithmetic operators and functions must be written according to Visual Basic.NET syntax. Arithmetic Operators and Operator Precedence –Arithmetic operations must adhere to the following order: 1. Exponentiations 2. Unary negations 3. Multiplications and Divisions 4. Integer divisions 5. Modulus operations 6. Additions and Subtractions

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Arithmetic Expressions (cont.) Integer Division –Calculates the number of times one integer goes into another, discarding the reminder. –Mod calculates the remainder when one integer is divided by another.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Arithmetic Expressions (cont.) Arithmetic Functions –Math.Sqrt() –Math.Abs() –Math.Sign() –Fix() –Math.Exp() –Math.Log() –Rnd() Type Conversion Functions –CBool() –CLng() –CDbl() –CShort() –CDec() –CSng() –CInt() –CStr()

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Arithmetic Expressions (cont.) Avoiding Arithmetic Errors –We must write arithmetic expressions carefully. –We must avoid certain pitfalls. –Overflow Errors Occur when computer attempts to store a number that is too large for its data type. –Roundoff Errors Occur when floating-point values or certain variables are used in a program. –Problems Caused by Limited Significant Digits Limitations on the number of significant digits. Digits may be loss at run time.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved String Expressions Manipulate strings using string operators and functions. –String Operators & is the only string operator in Visual Basic.NET. Joining two string values is called concatenation. –Functions Used with Strings Format() –Converts a numeric value to a string and formats it. Left(), Right(), and Mid() –Selects specific character(s) in a string.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved String Expressions –Functions Used with Strings (cont.) StrConv() –Converts a string into a new string using conversion rules. LTrim(), Rtrim(), and Trim() –Remove leading and trailing spaces. Len() –Determines the number of characters in a string. Space() –Indicates the number of spaces to create.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved String Expressions –Functions Used with Strings (cont.) InStr() –Conducts a string search. Asc() and Chr() –Access values in the ANSI table. Replace() –Perform a search and replace routine.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved The Try/Catch Block Revisited Used to detect and respond to error conditions. Can handle multiple error conditions.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Logical Expressions Used to select an action from alternative actions. Results in a True or False answer to a test. Also known as Boolean expressions. –Comparison Operators < <= > >= = <>

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Logical Expressions (cont.) –Comparison of Strings Strings are ranked alphabetically. –Logical Operators Combine simple logical expressions to create more complex expressions. Common operators are Not, And, and Or. –Logical Functions Common ones are IsNumeric() and IIf(). IsNumeric() is True if the argument is a valid number. IIf() chooses between two alternate paths.

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Quick Review What are the three type of expressions in VB? What four things can be contained within an expression? What are the symbols/keyword for exponentiation, multiplication, division, modulus arithmetic operators? What order would the operations in the following expression be evaluated? –A ^ B + (D / C) ^ E

McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Quick Review (cont.) What are three types of arithmetic errors that may occur? What functions translate a character into it’s corresponding ACSII value and vice versa? What is the symbol for the concatenation string operator? What are the symbols for the equality, inequality, and less than or equal to logical operators? What two values do all logical expressions evaluate to?