Review for test 2 - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Review for test 2

Description:

PERFORM PARA-2 VARYING X FROM 1 BY 1 UNTIL X 5. 10 ... PERFORM WITH TEST AFTER VARYING. POP-INDEX FROM 1 BY 1 UNTIL POP-INDEX = 50 ... – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 18
Provided by: DavidT128
Learn more at: http://courses.cs.vt.edu
Category:
Tags: review | test | varying

less

Transcript and Presenter's Notes

Title: Review for test 2


1
Review for test 2
  • Chapters 7, 8, 9, 11, 12

2
  • What is wrong with the following paragraphs?
  • PARA-A. PARA-B.
  • ADD A TO B MOVE 0 TO X
  • PERFROM PARA-A PERFORM UNTIL X 10
  • MOVE A TO C ADD 3 TO X
  • END-PERFORM
  • will give an infinite loop, x will never
    equal 10
  • PARA-C. MOVE 10 TO X
  • SUBTRACT X FROM X MOVE 1 TO SUM
  • PERFORM PARA-X UNTIL X 14. PERFORM UNTIL X
    0
  • ADD 1 TO SUM
  • PARA-X. END-PERFORM
  • ADD 5 TO X you want to change the value of x
    in
  • Never equals 14 the loop, will be infinite
    loop
  • .

3
  • Consider the following paragraph
  • PARA-A.
  • ADD 3 To X
  • SUBTRACT 2 FROM Y
  • MOVE 4 TO Z.
  • How many times will PARA-A be executed for each
    of the following code segments?
  • a. MOVE 1 TO X
  • PERFORM PARA-A UNTIL X gt 10 4
  • b. MOVE 20 TO Y
  • PERFORM PARA-A UNTIL Y 12 4
  • c. MOVE 1 TO Z
  • PERFORM PARA-A UNTIL Z 5 infinite
  • d. MOVE 10 TO X
  • PERFORM PARA-A UNTIL X lt 20 0

4
  • What will be displayed from the following code?
  • MOVE 1 TO X
  • MOVE 0 TO SUM
  • PERFORM UNTIL X 8
  • ADD X TO SUM
  • ADD X TO X
  • END-PERFORM
  • DISPLAY SUM
  • What will be displayed from the following code?
  • MOVE 1 TO X
  • MOVE 1 TO Y
  • PERFORM PARA-A UNTIL X 5 X 5
  • DISPLAY Y Y24
  • STOP RUN.
  • PARA-A.
  • MULTIPLY Y BY X GIVING Y
  • ADD 1 T0 X

5
  • (True/False). Fields being compared in an IF
    statement must always be the same size.
  • (True/False). If a field is NOT ALPHABETIC, then
    it must be NUMERIC.
  • 3. Consider the following declarations
  • 05 A PIC S9 VALUE 9.
  • 05 B PIC S9 VALUE -5.
  • 05 C PIC S9 VALUE 4.
  • 05 D PIC X(3) VALUE 'RT'.
  • 05 E REDEFINES D PIC X(2).
  • Indicate whether a condition is true or false?
  • a. A gt B OR B lt C AND A lt C T
  • b. NOT A gt B AND NOT B C OR A gt C T
  • c. E IS ALPHABETIC T
  • d. NOT (A 5 OR C lt 3) T

6
  • Assume,
  • 01 A PIC 9 VALUE 4.
  • 01 B PIC 9 VALUE 7.
  • 01 C PIC 9 VALUE 5.
  • What is the truth value of each of the following
    relation conditions?
  • a. A IS GREATER THAN B F
  • b. C IS NOT LESS THAN 5 T
  • c. 6 IS EQUAL TO B F
  • d. A IS NOT GREATER THAN ZERO F

7
  • Consider the following code segment
  • IF A IS GREATER THAN B
  • IF C IS LESS THAN B
  • MOVE B TO D
  • ELSE
  • ADD 4 TO D
  • END-IF
  • ELSE
  • IF C IS EQUAL B
  • MOVE A TO D
  • ELSE
  • ADD 10 TO D
  • END-IF
  • END-IF
  • What will be the value of D after execution of
    the above code with
  • a. A 4, B 8, C 3, and D 0? 10
  • b. A 8, B 4, C 2, and D 0? 4
  • c. A 6, B 9, C 7, and D 0? 10

8
  • How many times the following code will display
    "WELCOME HOME"?
  • MOVE 0 TO COUNT
  • PERFORM UNTIL COUNT 6
  • DISPLAY "WELCOME HOME"
  • ADD 2 TO COUNT
  • END-PERFORM
  • 3

9
  • a. Write COBOL statements to increment a variable
    A-COUNT by one if the test score (TEST-SCORE) of
    a student is 90 or over.
  • IF TEST-SCORE gt 90
  • COMPUTE A-COUNT A-COUNT 1
  • END-IF
  • b. Write COBOL statements to increment a variable
    B-COUNT by one if the test score (TEST-SCORE) of
    a student is in the range of 80 to 89.
  • IF TEST-SCORE gt 90 AND lt 98
  • COMPUTE B-COUNT B-COUNT 1
  • END-IF
  • c. Write COBOL statements to perfom some
    paragraph PARA-2 five times
  • PERFORM PARA-2 VARYING X FROM 1 BY 1 UNTIL X gt 5

10
  • Write IF..ELSE....END-IF statements to calculate
    the sales commission of a salesperson as follows
  • sales commission 3 of the sales amount if
    sales amount is over 50000 or the commission
    code is 1 otherwise, sales commission 2 of
    the sales amount.
  • IF SALES gt 50000 OR CODE 1
  • COMMISSION SALES .03
  • ELSE
  • COMMISION SALES .02
  • END-IF

11
  • Write IF...ELSE... END-IF statements to calculate
    the tuition fee of a student as follows
  • Credit Hours Tuition Fee
  • Not over 15 hours 200 per credit hour
  • Over 15 hours 3000 plus 150 per credit hour
    for hours over 15
  • IF HOURS lt 15
  • FEE HOURS 200
  • ELSE
  • FEE 3000 ((HOURS 15) 150)
  • END-IF

12
  • Suppose in one state, residents are subject to
    the following tax
  • Income Amount of Tax
  • Not over 1000 1 of income
  • Over 1000 to 3000 10 plus 2 of amount over
    1000
  • Over 3000 to 7000 50 plus 3 of amount over
    3000
  • Over 7000 170 plus 4 of amount over 7000
  • IF INCOME lt 1000
  • TAX INCOME .01
  • ELSE
  • IF INCOME gt 1000 AND lt 3000
  • TAX10 ((INCOME-1000) .02)
  • ELSE
  • IF INCOME gt 3000 AND lt 7000
  • TAX50 ((INCOME-3000) .03)
  • ELSE
  • TAX170 ((INCOME-7000) .04)
  • ENDIF

13
  • Write the code to determine the largest and
    smallest population. Move the values to BIGGEST
    and SMALLEST and the names to BIG-STATE
    SMALL-STATE. Assume a variable SUBSCRIPT exists.
  • 01 POPULATION-TABLE.
  • 05 POPULATION-AND-NAME OCCURS 50 TIMES.
  • 10 POP PIC 9(8).
  • 10 STATE PIC X(15).
  • FIND-BIG-SMALL.
  • MOVE POPULATION (1) TO BIGGEST SMALLEST.
  • MOVE STATE-NAME (1) TO SMALL-STATE BIG-STATE.
  • PERFORM WITH TEST AFTER VARYING
  • POP-INDEX FROM 1 BY 1 UNTIL POP-INDEX 50
  • IF POPULATION (POP-INDEX) IS GREATER THAN
    BIGGEST
  • MOVE POPULATION(POP-INDEX) TO BIGGEST
  • MOVE POPULATIOIN(POP-INDEX) TO BIG-STATE
  • END-IF
  • IF POPULATION (POP-INDEX) IS LESS THAN SMALLEST
  • MOVE POPULATION(POP-INDEX) TO SMALLEST
  • MOVE POPULATION(POP-INDEX) TO SMALL-STATE
  • END-IF

14
  • (True/False) An group item my be defined by an
    OCCURS clause.
  • Consider the following
  • 01 DATA-VALUES.
  • 05 FILLER PIC 9V99 VALUE 2.95.
  • 05 FILLER PIC 9V99 VALUE 5.96.
  • 05 FILLER PIC 9V99 VALUE 3.40.
  • 01 RATE-TABLE REDEFINES DATA-VALUES.
  • 05 RATE PIC 9V99 OCCURS 3 TIMES.
  • What will be output from the following DISPLAY
    statement?
  • DISPLAY RATE(2) 5.96
  • What is wrong, if any, in the following
    statement? If nothing is wrong, then what will be
    output?
  • DISPLAY RATE(4) UNKNOWN OUTPUT

15
  • The SEARCH statement requires that table entries
    must be specified with the use of a(n)
  • ___INDEX______, rather than a subscript.
  • (True/False). A SEARCH statement automatically
    initializes the index at 1, that is, a SEARCH
    always begins with the first element of a table.
  • The SEARCH ALL statement is used to perform a
    _________________ (binary/serial) search.

16
  • (True/False) A SET statement is not necessary
    with the SEARCH ALL statement.
  • What, if anything, is wrong with the following
    SEARCH?
  • SET WS-SUB TO 1
  • SEARCH PRICE-TABLE
  • AT END DISPLAY "NO ENTRY FOUND"
  • WHEN ITEM-NO (WS-SUB) IN-ITEM-NO
  • PERFORM CALC-PRICE
  • END-SEARCH
  • CALC-PRICE
  • COMPUTE PRICE QUANTITY UNIT-PRICE (WS-SUB)

17
  • The SEARCH ALL statement requires that a(n)
    ASSENDING KEY clause be specified along with the
    OCCURS and INDEXED BY clauses of a table entry.
  • An input record consists of 10 group items, each
    with 3 digit PART-NO and associated 3-digit
    QUANTITY-ON-HAND.
  • Use an OCCURS clause to define the input.
  • 05 FR-TABLE OCCURS 10 TIMES.
  • 10 PART-NO PIC 999.
  • 10 QUANTITY-ON-HAND PIC 999
  • Write a routine to load the 10 input records into
    the WORKING-STORAGE entry for the table.
  • PERFORM VARYING X FROM 1 BY 1 UNTIL X gt 3
  • MOVE DATA TO PART-NO (X)
  • MOVE DATA TO QUANTITY-ON-HAND (X)
  • END-PERFORM
  • 3. Write a statement (statements) to print the
    quantity on hand for PART-NO 234. WRITE CODE TO
    SEARCH THEN PRINT
Write a Comment
User Comments (0)
About PowerShow.com