Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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

2 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 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 > 104 b. MOVE 20 TO Y PERFORM PARA-A UNTIL Y = 124 c. MOVE 1 TO Z PERFORM PARA-A UNTIL Z = 5infinite d. MOVE 10 TO X PERFORM PARA-A UNTIL X < 200

4 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 = 5X= 5 DISPLAY YY=24 STOP RUN. PARA-A. MULTIPLY Y BY X GIVING Y ADD 1 T0 X

5 5 1.(True/False). Fields being compared in an IF statement must always be the same size. 2.(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 CPIC 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 > B OR B < C AND A < CT b. NOT A >= B AND NOT B = C OR A > CT c. E IS ALPHABETICT d. NOT (A = 5 OR C < 3)T

6 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 BF b. C IS NOT LESS THAN 5T c. 6 IS EQUAL TO BF d. A IS NOT GREATER THAN ZEROF

7 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 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 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 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 >= 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 >= 90 AND <= 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 > 5

10 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 > 50000 OR CODE = 1 COMMISSION = SALES *.03 ELSE COMMISION = SALES *.02 END-IF

11 11 Write IF...ELSE... END-IF statements to calculate the tuition fee of a student as follows: Credit HoursTuition Fee Not over 15 hours $200 per credit hour Over 15 hours $3000 plus $150 per credit hour for hours over 15 IF HOURS <= 15 FEE = HOURS * 200 ELSE FEE = 3000 + ((HOURS – 15) * 150) END-IF

12 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 <= 1000 TAX = INCOME *.01 ELSE IF INCOME > 1000 AND <= 3000 TAX=10 + ((INCOME-1000) *.02) ELSE IF INCOME > 3000 AND <= 7000 TAX=50 + ((INCOME-3000) *.03) ELSE TAX=170 + ((INCOME-7000) *.04) ENDIF

13 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 POPPIC 9(8). 10 STATEPIC 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 END-PERFORM

14 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 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 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 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. 1.Use an OCCURS clause to define the input. 05 FR-TABLE OCCURS 10 TIMES. 10 PART-NO PIC 999. 10 QUANTITY-ON-HANDPIC 999 2.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 > 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…


Download ppt "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."

Similar presentations


Ads by Google