Lecture 41 Arithmetic Clauses The ROUNDED clause –Place ROUNDED after the variable that holds the result ADD A TO B ROUNDED. ADD A TO B GIVING C ROUNDED.

Slides:



Advertisements
Similar presentations
College Algebra Review Section 1 Objectives of this Section Classify Numbers Evaluate Numerical Expressions Work with Properties of Real Numbers.
Advertisements

Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
7.1Variable Notation.
CHAPTER 9 Introduction to Real Numbers and Algebraic Expressions Slide 2Copyright 2012, 2008, 2004, 2000 Pearson Education, Inc. 9.1Introduction to Algebra.
Section I: Distributive Property Section II: Order of Operations.
7-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
Properties of Logarithms
Sullivan Algebra and Trigonometry: Section R.1 Real Numbers Objectives of this Section Classify Numbers Evaluate Numerical Expressions Work with Properties.
Taks Objective 2 Properties and attributes of function.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
Order Of Operations.
1.2 Algebraic Expressions 8/23/13
Chapter 5 Using Data and COBOL Operators. Initializing Variables When you define a variable in WORKING- STORAGE, you also can assign it an initial value.
1.3 What you should learn Why you should learn it Order of Operations
ORDER OF OPERATIONS x 2 Evaluate the following arithmetic expression: x 2 Each student interpreted the problem differently, resulting in.
Order of Operations Topic
7-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
7-1 Chapter 7.  Basic Arithmetic Verbs  Options Available with Arithmetic Verbs  COMPUTE Statement  Signed Numbers in Arithmetic Operations  Intrinsic.
PRESENTATION 11 What Is Algebra. ALGEBRAIC EXPRESSIONS An algebraic expression is a word statement put into mathematical form by using variables, arithmetic.
1.2 Algebraic Expressions 8/24/12. Vocabulary Variable: A letter used to represent one or more numbers Exponent: The number or variable that represents.
CPS120: Introduction to Computer Science Operations Lecture 9.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Order of Operations - rules for arithmetic and algebra that describe what sequence to follow to evaluate an expression involving more than one operation.
Thinking Mathematically
Module 6 Arithmetic. Arithmetic Verb Template  Most COBOL arithmetic verbs conform to the template above. For example; ADD Takings TO CashTotal. ADD.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
Order of Operations 1-2. Objectives Evaluate numerical expressions by using the order of operations Evaluate algebraic expressions by using the order.
Variables and Algebraic Expressions 1-3. Vocabulary Variable- a letter represents a number that can vary. Constant- a number that does not change. Algebraic.
7-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
MM150 Unit 3 Seminar Agenda Seminar Topics Order of Operations Linear Equations in One Variable Formulas Applications of Linear Equations.
1-2 Order of Operations and Evaluating Expressions.
Significant Figure Rules RulesExamples The following are always significant Non zero digits Zeros between non zero digits Zero to the right of a non zero.
1 Chapter 5 – The Procedure Division File handling statements –OPEN statement Initiates processing for a file Input Output Each file opened must have been.
Lecture III Start programming in Fortran Yi Lin Jan 11, 2007.
This will all add up in the end. Assignment operator =Simple Assignment operator Arithmetic Operators +Additive operator – Subtraction operator * Multiplication.
CMSC 104, Version 8/061L10ArithmeticOps.ppt Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class.
Any Questions! 2 Agenda Moving data Arithmetic Verbs Compute statement.
Equations Inequalities = > 3 5(8) - 4 Numerical
ORDER OF OPERATIONS LESSON 2.
Notes 2.1 Order of Operations PEMDAS If an expression has only numbers and symbols, it is a numerical expression. If it has a variable it is a variable.
§ 1.4 Introduction to Variable Expressions and Equations.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
§ 1.8 Exponents and Order of Operations. Definition of Natural Number Exponent If b is a real number and n is a natural number, b is the base and n is.
CSC Programming for Science Lecture 5: Actual Programming.
Section I: Distributive Property Section II: Order of Operations
So, to simplify an expression using order of operations, you should:
Assignment statement:
1 Introduction to Algebra: Integers.
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.
4 Chapter Chapter 2 Decimals.
Introduction to Algebra
Lecture Set 4 Data Types and Variables
Order Of Operations.
Arithmetic Operator Operation Example + addition x + y
Lecture 3 Expressions Richard Gesick.
SCIENTIFIC NOTATION.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Order of Operations and Evaluating Expressions
THE COMPUTE STATEMENT Purpose: performs mathematical calculations
Chapter 3: Lesson 3 Order of Operations
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.
Order of Operations 1-2 Objective: Students will evaluate numerical expressions and algebraic expressions using the order of operations. S. Calahan 2008.
Data Types and Expressions
Week 1 Real Numbers and Their Properties
Algebra 1 Section 1.8.
Evaluating Expressions
Ch 1-2 Order of Operations
Data Types and Expressions
Data Types and Expressions
Presentation transcript:

lecture 41 Arithmetic Clauses The ROUNDED clause –Place ROUNDED after the variable that holds the result ADD A TO B ROUNDED. ADD A TO B GIVING C ROUNDED. SUBTRACT A FROM B ROUNDED. MULTIPLY A BY B ROUNDED. DIVIDE A INTO B ROUNDED. –Rounds the computed value to the PIC specification of the result field –If ROUNDED is not used then truncation occurs

lecture 42 ROUNDED Clause Examples 9.99 ROUNDED into 99V9  10.0 ( = 10.4) 9.94 ROUNDED into 9V9  9.9 ( = 9.99) Adds.05 then truncates then moves to PIC clause 89.5 ROUNDED into 99  90 ( = 90.0) 89.4 ROUNDED into 99  89 ( = 89.9) Adds.5 then truncates then moves to PIC clause

lecture 43 ON SIZE ERROR Clause Generates a warning when a calculation is too large for the resultant field Used to detect overflow Appears after ROUNDED option Can execute a statement on this condition Example A = 150 PIC 999, B = 60 PIC 99 ADD A TO B ON SIZE ERROR MOVE ‘OVERFLOW’ TO WS-ERROR-MSG.

lecture 44 COMPUTE Statement COMPUTE data-name = arithmetic expression. Use for multiple arithmetic operations Operations –+, -, *, /, ** –5 ** 3  5 * 5 * 5

lecture 45 COMPUTE Statement All variables in the arithmetic expression must be numeric items You can code the Rounded clause whenever you will lose decimal places in a calculation If the Rounded clause is not used, the extra decimal places are truncated! If the variable that receives the arithmetic expression is numeric edited then that variable cannot be used in the arithmetic expression. Otherwise, it must be numeric

lecture 46 MULTIPLY B BY B GIVING B-SQUARED. MULTIPLY 4 BY A GIVING FOUR-A. MULTIPLY FOUR-A BY C GIVING FOUR-A-C. SUBTRACT FOUR-A-C FROM B-SQUARED GIVING RESULT-1. COMPUTE RESULT-2 = RESULT-1 **.5. SUBTRACT B FROM RESULT-2 GIVING NUMERATOR. MULTIPLY 2 BY A GIVING DENOMINATOR. DIVIDE NUMERATOR BY DENOMINATOR GIVING X. COMPUTE X = (-B + (B ** 2 - ( 4 * A * C)) **.5) / ( 2 * A). Both sets of code apply to the quadratic formula X = -B +  B 2 -4AC 2A Poor Code Improved Code

lecture 47 Operator Precedence Parentheses (inside out and left to right) Exponentiation Multiplication, division (left to right) Addition, subtraction (left to right) You can always clarify the sequence in which the operations are done by placing parenthesis

lecture 48 DATA NAMEA BC COMMENTS Value before execution Initial Values Value after execution of: COMPUTE C = A + B Simple addition COMPUTE C = A + B * Multiplication before addition COMPUTE C = (A + B) * Parenthesis evaluated first COMPUTE C = A ** B algebraically, c = a b COMPUTE C = B ** A algebraically, c = b a

lecture 49 ALGEBRAIC EXPRESSION COBOL COMPUTE x = a + bCOMPUTE X = A + B. x = a + b COMPUTE X = (A + B) / 2. 2 x = (a + b)cCOMPUTE X = (A + B) * C / 2. 2 x = a + bCOMPUTE X = (A + B) / (2 * C). 2c x =  aCOMPUTE X = A **.5. x = a 2 + b 2 COMPUTE X = (A ** 2 + B ** 2) / C ** 2 c 2

lecture 410 Intermediate Results An intermediate result is computed when an expression consists of two or more operations. How is precision to the right of the decimal place preserved in intermediate results? –i.e., when you have PICs with different decimal precision –The final PIC used for the intermediate result can be compiler dependent Addition & Subtraction –Maximum no. of decimal places of the PICs Multiplication –Sum of the decimal places of the PICs Division –No. of decimal places in the PIC of the numerator Two solutions : –Redefine the fields used in the operations –Re-sequence the operations in the expression