CS 313001 92704 PowerPoint PPT Presentation

presentation player overlay
1 / 27
About This Presentation
Transcript and Presenter's Notes

Title: CS 313001 92704


1
CS 313-0019/27/04
  • Recap
  • Chapters 1-4
  • Lab0, Lab1

2
Chapter 1Introduction to COBOL and Program
Development
3
Chapter 2A Complete COBOL Program
  • A spacing chart or printer spacing chart is often
    used in designing reports.
  • A spacing chart is divided into numbered rows and
    columns and can be a great help in the accurate
    coding of the output lines in your program.

4
Overall COBOL Hierarchy Chart
5
Hierarchy Chart for Tuition Billing Program
PREPARETUITIONREPORT
WRITEHEADINGLINE
READSTUDENTFILE
PROCESSSTUDENTRECORD
WRITEUNIVERSITYTOTALS
COMPUTEINDIVIDUALBILL
INCREMENTUNIVERSITYTOTALS
WRITEDETAILLINE
READSTUDENTFILE
COMPUTETUITION
COMPUTEUNIONFEE
COMPUTEACTIVITYFEE
COMPTUESCHOLARSHIP
(c) Complete Hierarchy Chart (Levels 1-4)
6
COBOL Notation (Page 35)
7
SWITCHES
  • Switches are used in the decision-making logic of
    a program

8
88 level entry
  • A condition name (88-level entry) is a special
    way of writing a relational condition that makes
    it (the condition) easier to read
  • Condition names are defined in the Data Division,
    then referenced in the Procedure Division.

9
88-level entry continue
  • The definition of a condition name in the Data
    Division simplifies subsequent coding in the
    Procedure Division.
  • The use of an 88-level entry also allows multiple
    codes to be grouped under a single data name.

10
Condition Names (88-level entries) Page 44
(a) Syntax
05 YEAR-CODE PIC 9. 88 FRESHMAN VALUE
1. 88 SOPHOMORE VALUE 2. 88
JUNIOR VALUE 3. 88 SENIOR VALUE 4.
88 GRAD-STUDENT VALUES ARE 5 THRU 8. 88
UNDER-CLASSMAN VALUES ARE 1, 2 88
UPPER-CLASSMAN VALUES ARE 3, 4. 88
VALID-CODES VALUES ARE 1 THRU 8. IF FRESHMAN
PERFORM WELCOME-NEW-STUDENTSEND-IF IF
VALID-CODES PERFORM PROCESS-STUDENT-RECORDEL
SE DISPLAY INCOMING YEAR CODE IS IN
ERROREND-IF.
(b) Examples
11
Accumulators visit in chapter 4
12
Chapter 3
13
Rules of the MOVE Statement (Elementary Data
Items)
14
Illustration of the MOVE statement Alphanumeric
Sending Field to Alphanumeric Receiving Field
15
Table 5.3 Illustration of the MOVE statement
Numeric Sending Field to Numeric Receiving Field
16
The ROUNDED Clause
DATA NAME
A B C
PICTURE 9V99 9V99 9V9
Value before execution 123
456 (immaterial) Value after execution of ADD
A B GIVING C 123 456 57 ADD A B
GIVING C ROUNDED 123 456 58
17
The COMPUTE Instruction
DATA NAME
A B C COMMENTS
Value before execution 2 3
10 Initial Values Value
after execution of COMPUTE C A B.
2 3 5
Simple addition COMPUTE C A B
2. 2 3 8
Multiplication before addition
COMPUTE C (A B) 2. 2
3 10 Parenthesis
evaluated first COMPUTE C A B.
2 3 8
algebraically, c ab COMPUTE C B
A. 2 3
9 algebraically, c ba
18
The COMPUTE Instruction (continued)
ALGEBRAIC EXPRESSION
COBOL COMPUTE
x a b COMPUTE X A B. x a b
COMPUTE X (A B) / 2. 2 x (a
b)c COMPUTE X (A B) C / 2.
2 x a b COMPUTE X (A B) / (2 C).
2c x ?a COMPUTE X A .5. x a?
b? COMPUTE X (A 2 B 2) / C 2
c2
19
Table 5.7 The ADD Instruction
DATA NAME
A B C
Value before execution 5 10
30 Value after execution of ADD A TO C
5 10 35 ADD A B TO C 5
10 45 ADD A TO B GIVING C 5
10 15 ADD A 18 B GIVING C 5
10 33 ADD A 18 B TO C 5
10 63 ADD 1 TO B C 5
11 31
20
Table 5.8 The SUBTRACT Instruction
DATA NAME
A B C D
Value before execution 5
10 30
100 Value after execution of SUBTRACT A FROM
C 5 10
25 100 SUBTRACT
A B FROM C 5
10 15
100 SUBTRACT A B FROM C GIVING D
5 10 30
15 SUBTRACT 10 FROM C D
5 10 20
90
21
Table 5.9 The MULTIPLY Instruction
DATA NAME
A B C
Value before execution 5 10
30 Value after execution of MULTIPLY B BY A
GIVING C 5 10 50 MULTIPLY A
BY B GIVING C 5 10
50 MULTIPLY A BY B 5 50
15 MULTIPLY B BY A 50 10
30 MULTIPLY A BY 3 GIVING B C 5 15
15
22
PROGRAMMING TIP
Use the COMPUTE Statement for Multiple
Arithmetic Operations
23
Table 5.10 The DIVIDE Instruction
DATA NAME
A B C
Value before execution 5 10
30 Value after execution of DIVIDE 2
INTO B. 5 5 30
DIVIDE 2 INTO B GIVING C. 5 10
5 DIVIDE B BY 5 GIVING A
2 10 30 DIVIDE A INTO B C
5 2 6 DIVIDE A
INTO B GIVING C 5 10 2
DIVIDE 3 INTO A GIVING B REMAINDER C
5 1 2
24
Table 5.11 Arithmetic on Fields with Assumed
Decimal Points
DATA NAME
A B C
PICTURE 99 99V9 99V99
Value before execution 12 345
4712 Value after execution of ADD B TO A
46 345 4712 ADD A TO B
12 465 4712 ADD B TO C 12
345 8162 ADD C TO B 12
816 4712 ADD C TO A 59
345 4712 ADD A TO C 12
465 5912
25
Table 5.7 The ADD Instruction
DATA NAME
A B C
Value before execution 5 10
30 Value after execution of ADD A TO C
5 10 35 ADD A B TO C 5
10 45 ADD A TO B GIVING C 5
10 15 ADD A 18 B GIVING C 5
10 33 ADD A 18 B TO C 5
10 63 ADD 1 TO B C 5
11 31
26
Table 5.8 The SUBTRACT Instruction
DATA NAME
A B C D
Value before execution 5
10 30
100 Value after execution of SUBTRACT A FROM
C 5 10
25 100 SUBTRACT
A B FROM C 5
10 15
100 SUBTRACT A B FROM C GIVING D
5 10 30
15 SUBTRACT 10 FROM C D
5 10 20
90
27
Table 5.9 The MULTIPLY Instruction
DATA NAME
A B C
Value before execution 5 10
30 Value after execution of MULTIPLY B BY A
GIVING C 5 10 50 MULTIPLY A
BY B GIVING C 5 10
50 MULTIPLY A BY B 5 50
15 MULTIPLY B BY A 50 10
30 MULTIPLY A BY 3 GIVING B C 5 15
15
Write a Comment
User Comments (0)
About PowerShow.com