Modifications to program Addda.cbl Please use speaker notes for additional information!

Slides:



Advertisements
Similar presentations
Check Digit - Mod 11 Please use speaker notes for additional information!
Advertisements

 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Scientific Notation.
Unit 4: Mathematics Introduce the laws of Logarithms. Aims Objectives
Transparency 2 Click the mouse button or press the Space Bar to display the answers.
Scientific Notation Notes
Scientific Notation.
Scientific Notation Recognize and use scientific notation.
Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges.
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
 What is a formula in Excel?  A formula is statement written by the user to be calculated. Formulas can be as simple or as complex as the user wants.
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
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.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Totals on the Screen Please use speaker notes for additional information!
Lesson 1 When mulitiplying or dividing by powers of ten (10, 100, 1,000, etc.), we can use a place value chart. **Please note that the symbol in the following.
Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed.
Warm-Up 37/15 211/32 7/24 12/18 21/10 8/15. Decimal Review.
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
Array - adding to array at run time Please see speaker notes for additional information!
Explanation of SAMPLEIF (if88in1.cbl or if88in1.html) Please use speaker notes for additional information!
Irving Middle School1 Integers Warm-Up Answer the Essential Question: When and where must you be able to solve problems with positive and negative numbers.
Any Questions!. Test Coming Up! Agenda Printing with Externally Described Printer Files Arrays.
COBOL Screens Please use speaker notes for additional information!
Warm-up, 3/28 Compute: 1. 2 x 2 x 2 x 2 = 2. 3 x 3 x 3 = 3. 2 x 2 x 3 x 3 x 3 = 4. 5 x 5 x 2 x 2 = 5. 2 x 2 x 4 =
Watch “Powers of 10” csu/powersof10/
1 Chapter 5 – The Procedure Division File handling statements –OPEN statement Initiates processing for a file Input Output Each file opened must have been.
Positive and Negative numbers. Negative numbers A positive or negative whole number, including zero, is called an integer. For example, –3 is an integer.
Chapter 2 Using Variables and Constant. What is a Constant ? The data in COBOL programs falls in two broad categories: – Constants and Variables A constant.
Aim: How to write in Scientific Notation DO NOW: 1. WHAT DOES 10 5 MEAN? 2. WHAT IS THE VALUE OF USING YOUR CALCULATOR, CALCULATE 4.5 X 10 6.
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
CS 141 Computer Programming 1 Branching Statements.
Addition Multiplication Subtraction Division. 1.If the signs are the same, add the numbers and keep the same sign = = If the.
Random update Please use speaker notes for additional information!
General Introduction Algorithms. Let’s write a program  A program is a collection of statements written in a language the computer understands.  A computer.
Introduction to Mathematics This prep course introduces decimals, percents, and fractions. Some reference websites can be found on the last slide of this.
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
What are big numbers? IIIImagine the # 1. It represents one object IIIIncrease this by one zero (power of 10) to #10 It represents ten of those.
Definition Measures the degree of confidence of a measurement.
Scientific Notation.
Scientific Notation.
Thinking Mathematically
Scientific Notation Scientific Notation is sometimes called exponential notation. SCI NOT is used when working with very large or very small numbers.
2.5 Another Java Application: Adding Integers
Objective The student will be able to:
Variables, Expressions, and IO
Objective The student will be able to:
Multiply Decimals.
Please use speaker notes for additional information!
Adding and Subtracting Numbers in Scientific Notation
Decimal Operations.
SCIENTIFIC NOTATION.
Scientific Notation section 5.6
Please use speaker notes for additional information!
Number and String Operations
Scientific Notation.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Scientific Notation.
Using screens and adding two numbers - addda.cbl
Date Conversion Program
Week 1 Real Numbers and Their Properties
Scientific Notation.
5.1 - Scientific Notation & Units
Scientific Notation.
Scientific Notation.
Scientific Notation section 5.2
Who was not here yesterday?
Scientific Notation.
Presentation transcript:

Modifications to program Addda.cbl Please use speaker notes for additional information!

IDENTIFICATION DIVISION. PROGRAM-ID. ADDPROG. AUTHOR. GROCER. *ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-AREA. 05 GET-ACCEPT-ANS PIC X VALUE SPACES. 05 FIRST-NUMBER PIC 999 VALUE SECOND-NUMBER PIC 999 VALUE ADD-ANS PIC 9999 VALUE 0. PROCEDURE DIVISION. MAINLINE. DISPLAY "ENTER THE FIRST NUMBER (UNDER 1000)". ACCEPT FIRST-NUMBER. DISPLAY "ENTER THE SECOND NUMBER (UNDER 1000)". ACCEPT SECOND-NUMBER. ADD FIRST-NUMBER TO SECOND-NUMBER GIVING ADD-ANS. * ADD FIRST-NUMBER SECOND-NUMBER * GIVING ADD-ANS. * ADD FIRST-NUMBER, SECOND-NUMBER * GIVING ADD-ANS. DISPLAY "THE ANSWER IS " ADD-ANS. DISPLAY "PRESS ENTER TO END THE PROGRAM". ACCEPT GET-ACCEPT-ANS. STOP RUN. ADDDA.CBL Two other ways that the ADD statement could have been written - shown as comments.

ADDDA1.CBL IDENTIFICATION DIVISION. PROGRAM-ID. ADDPROG. AUTHOR. GROCER. *ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-AREA. 05 GET-ACCEPT-ANS PIC X VALUE SPACES. 05 FIRST-NUMBER PIC 999 VALUE SECOND-NUMBER PIC 999 VALUE ADD-ANS PIC 9999 VALUE 0. PROCEDURE DIVISION. MAINLINE. DISPLAY "ENTER THE FIRST NUMBER (UNDER 1000)". ACCEPT FIRST-NUMBER. DISPLAY "ENTER THE SECOND NUMBER (UNDER 1000)". ACCEPT SECOND-NUMBER. COMPUTE ADD-ANS = FIRST-NUMBER + SECOND-NUMBER. DISPLAY "THE ANSWER IS " ADD-ANS. DISPLAY "PRESS ENTER TO END THE PROGRAM". ACCEPT GET-ACCEPT-ANS. STOP RUN. The COMPUTE statement is an alternate way to do mathematics. In this example I am saying COMPUTE ADD- ANS = to the sum of the data in FIRST- NUMBER and the data in SECOND- NUMBER.

ADDDA1.INT When I ran ADDDA1.INT, it produce the results shown above.

IDENTIFICATION DIVISION. PROGRAM-ID. ADDPROG. AUTHOR. GROCER. *ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-AREA. 05 GET-ACCEPT-ANS PIC X VALUE SPACES. 05 FIRST-NUMBER PIC 999 VALUE SECOND-NUMBER PIC 999 VALUE ADD-ANS PIC 9999 VALUE 0. PROCEDURE DIVISION. MAINLINE. DISPLAY "ENTER THE FIRST NUMBER (UNDER 1000)". ACCEPT FIRST-NUMBER. DISPLAY "ENTER THE SECOND NUMBER (UNDER 1000)". ACCEPT SECOND-NUMBER. COMPUTE ADD-ANS = FIRST-NUMBER + SECOND-NUMBER * 2. DISPLAY "THE ANSWER IS " ADD-ANS. DISPLAY "PRESS ENTER TO END THE PROGRAM". ACCEPT GET-ACCEPT-ANS. STOP RUN. ADDDA1A.CBL

Order of Operation: Works from left to right Resolves parenthesis first Order of mathematics: Exponentiation Multiplication or Division Addition or Subtraction Order of Operation

ADDDA1A.INT COMPUTE ADD-ANS = FIRST-NUMBER + SECOND-NUMBER * 2. = * 2 = = 0017

IDENTIFICATION DIVISION. PROGRAM-ID. ADDPROG. AUTHOR. GROCER. *ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-AREA. 05 GET-ACCEPT-ANS PIC X VALUE SPACES. 05 FIRST-NUMBER PIC 999 VALUE SECOND-NUMBER PIC 999 VALUE ADD-ANS PIC 9999 VALUE 0. PROCEDURE DIVISION. MAINLINE. DISPLAY "ENTER THE FIRST NUMBER (UNDER 1000)". ACCEPT FIRST-NUMBER. DISPLAY "ENTER THE SECOND NUMBER (UNDER 1000)". ACCEPT SECOND-NUMBER. COMPUTE ADD-ANS = (FIRST-NUMBER + SECOND-NUMBER) * 2. DISPLAY "THE ANSWER IS " ADD-ANS. DISPLAY "PRESS ENTER TO END THE PROGRAM". ACCEPT GET-ACCEPT-ANS. STOP RUN. ADDDA1B.CBL

ADDDA1B.INT COMPUTE ADD-ANS = (FIRST-NUMBER + SECOND-NUMBER) * 2. = ( ) * 2 = 11 * 2 = 0022

ADDDA2.CBL

IDENTIFICATION DIVISION. PROGRAM-ID. ADDPROG. AUTHOR. GROCER. *ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-AREA. 05 GET-ACCEPT-ANS PIC X VALUE SPACES. 05 FIRST-NUMBER PIC 999 VALUE SECOND-NUMBER PIC 999 VALUE ADD-ANS PIC 9999 VALUE FINAL-ANS PIC 9999 VALUE 0. PROCEDURE DIVISION. MAINLINE. DISPLAY "ENTER THE FIRST NUMBER (UNDER 1000)". ACCEPT FIRST-NUMBER. DISPLAY "ENTER THE SECOND NUMBER (UNDER 1000)". ACCEPT SECOND-NUMBER. ADD FIRST-NUMBER SECOND-NUMBER GIVING ADD-ANS. MULTIPLY ADD-ANS BY 2 GIVING FINAL-ANS. DISPLAY "THE ANSWER IS " ADD-ANS " " FINAL-ANS. DISPLAY "PRESS ENTER TO END THE PROGRAM". ACCEPT GET-ACCEPT-ANS. STOP RUN. ADDDA2.CBL

ADDDA2.INT ADD FIRST-NUMBER SECOND-NUMBER GIVING ADD-ANS = 29 MULTIPLY ADD-ANS BY 2 GIVING FINAL-ANS. 29 * 2 = 58

IDENTIFICATION DIVISION. PROGRAM-ID. ADDPROG. AUTHOR. GROCER. *ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-AREA. 05 GET-ACCEPT-ANS PIC X VALUE SPACES. 05 FIRST-NUMBER PIC 999 VALUE SECOND-NUMBER PIC 999 VALUE OUTPUT-AREA. 05 ADD-ANS PIC 9999 VALUE FINAL-ANS PIC 9999 VALUE 0. PROCEDURE DIVISION. MAINLINE. DISPLAY "ENTER THE FIRST NUMBER (UNDER 1000)". ACCEPT FIRST-NUMBER. DISPLAY "ENTER THE SECOND NUMBER (UNDER 1000)". ACCEPT SECOND-NUMBER. ADD FIRST-NUMBER SECOND-NUMBER GIVING ADD-ANS. MULTIPLY ADD-ANS BY 2 GIVING FINAL-ANS. DISPLAY "THE ANSWER IS " ADD-ANS " " FINAL-ANS. DISPLAY "PRESS ENTER TO END THE PROGRAM". ACCEPT GET-ACCEPT-ANS. STOP RUN. ADDDA2A.CBL This more accurately shows how the data is actually being used.

ADDDA3.CBL This is where I am storing the output, I have edited it so that a comma will be inserted if needed and so the Zs will suppress leading zeros. Notice that edited data does not have a value! The results of the calculations are being stored in ADD-ANS-WS and FINAL-ANS-WS. Note, the data is being stored in a pure numeric field without editing characters. When I am ready to display the data, I move it to the output areas(ADD-ANS-OUT and FINAL-ANS-OUT) that contain the editing characters and then display the output areas.

ADDDA3.INT The PIC Z,ZZ9 suppresses leading zeros so you now see the answers as 11 and 22. Note that there is a 9 in the units position, so if the answer was 0, the single 0 would print since the units position is not suppressed. The PIC Z,ZZ9 inserts the comma in the answers shown.

ADDDA4.CBL The pictures have now been defined so they can hold decimal numbers, not just whole numbers. The V is an assumed decimal point that essentially says assume that the decimal point is here when you do your calculations. The user wants to see an actual decimal point, so in the output pictures where I have done my editing, I use the actual decimal point.

ADDDA4.INT

ADDDA5.CBL S is used with the pictures where the answer is being stored. S remembers the sign. The actual sign is used in the output picture so the user can tell if the data is negative. Note that in one case the negative sign is in front of the data and in one case it is after the data.

ADDDA5.INT In the first example, the subtraction did not result in a negative answer so the negative sign in the output pictures turned to a space. In the second example, the answer was negative. The S remembered that it had a negative answer and the sign in the output picture showed the sign.

ADDDA6.CBL Input now supports negative data.

ADDDA6.INT Negative data was entered into the second number. When the subtraction was done, the answer also was a negative.