QUIZ#2 STUDENT QUESTION STUDY GUIDE

 

 

TRUE/FALSE

 

*** Conditions surrounding the word AND are evaluated first. (T)

*** When there are several AND or OR connectors, the AND conditions are evaluated first, as they appear in the statement, from left to right.  Then the OR conditions are evaluated, also from left to right.  (T)

*** Fields being compared in an IF statement must always be the same size. (F)

*** The clause IF A IS NOT POSITIVE is the same as the clause IF A IS NEGATIVE.  (F)

*** In an IF-statement, the ELSE is required when using more than one IF-statement at once. (F)

*** ZERO is included in POSITIVE numbers and not NEGATIVE (F)

*** EBCDIC and ASCII Collating sequences have the same order of precedence from high to low (F)

*** Condition names are always in Area B (T)

*** The "END-IF" statement will terminate all IF-statements together at once (F)

*** A class test separates conditions from each other in memory (ie: numeric vs alphabetic) so they cannot be mixed up thinking one is the other. (F)

*** Indentation is important in the logic of a program. (F)

*** Collating sequence - "smith" is less than "saunders" in Unix. (T)

*** When a literal is stored in a numeric identifier, it is stored as letters. (F)

*** A control-break algorithm is a type of loop. (T)

*** AND and OR go between two conditions that do not evaluate to true or false. (F)

*** if a = b and c means a = b and b = c (F)

*** Since a condition should evaluate to true or false, a condition name should also evaluate to true or false(T)

*** Like all other level numbers, the condition name level number 88 also appears in the working-storage section of the data division. (T)

*** Conditions are not evaluated (F)

*** Nested IF statements are allowed (T)

*** An iteration will continue while the condition is false (F)

*** IF statements does not need an end-if at the end of the operations (F)

*** You can use the words AND NOT or OR in your if condition (T)

*** If the condition is false, the ELSE section of statements is executed, if it exists.  The ELSE is required. (F)

*** The first test in a condition must be a full test.  T

*** If a condition is false, the statements are executed.  F

*** OR and NOT are examples of relational operators.  F

*** THEN is a required word when using an if statement.  F

*** Precedence is used when evaluating conditions.  T

*** When evaluating a condition, COBOL does not use any form of precedence. The conditions are evaluated from left to right.  F

*** Perform-until are-there-more-records = “no” is correct COBOL syntax. T

*** An in-line perform never ends with an end-perform.  F

*** When implementing the single-control break algorithm, you must use a variable that can be changed to hold the value of the condition that is being checked.  T

*** The single-control break algorithm uses a nested perform.  T

*** “AbC” is great than “aBc” when using the unix collating sequence. (F)

*** “Yes” is equal to “yes” in the unix collating sequence. (F)

*** Conditions surrounding AND have the highest precedence. (T)

*** Parenthesis don’t change the order in precedence. (F)

*** Conditions can only be evaluated to TRUE or FALSE. (T)

*** Zero can be included as either a positive or a negative number when it comes to conditions. (F)

*** COBOL is a strongly typed language. (F)

*** One can just assume the order of the group in an input file when they are wanting to sort by means of a single control break. (F)

*** When using an “if” statement, there does not have to be an “else” statement to go along with it. (T)

*** Spaces have a lower precedence than 0-9 in the unix collating sequence. (T)

*** (F)  IF Statements can not be used with logical operators

*** (T)  When using a single control break algorithm the data must be sorted

*** (T)  Condition names must evaluate to True or False

*** (F)  Numeric literals can not be used when using an IF statement

*** (T)  An 88 level number must be used with an 01

*** (T) A perform statement will execute all instruction in a Paragraph

*** (T)  Perform statements can be told how many times to execute

*** (T)  Else clauses are optional

*** (F)  All IF statements MUST end with a period

*** (F)  Class tests are used while running COBOL debugger

*** (F)  IBM and Unix use the same collating sequence

*** (T)  Multiple Condition names can be used for the same 01

*** (T)  Comparisons are based on numeric fields

*** (T)  NOT (greater than or equal to) is equivalent to LESS THAN

*** (F)  COBOL does not require unique condition Names

*** (F)  Parentheses may be used to alter the hierarchy of operations

*** (T) Loops should follow instructions

*** (F) When using Perform Until it is already known how many times the loop will execute

*** The first test in a condition must be a “full test” meaning that it evaluates to true or false. (T)

*** Conditions should evaluate to true or false, but condition names do not have to evaluate to true or false. (F)

*** Condition names use level number 88 and appear in the working storage section. (T)

*** The identifiers Positive, Negative, and Zero are used in a CLASS test. (F)

 

 

SHORT ANSWER

 

*** Give an example of why collating sequences (EBCDIC, ASCII) are useful.

            -If you are trying to put something in alphabetical order.

 

*** Write a valid IF statement that contains two relational operators and one logical operator.

            -IF a is less than b and c is greater than b

                        perform 200-do-something.

 

*** What are the two rules for using a nested perform varying?

            - The innermost perform varying loop is executed first.

            - The next outer perform varying loop in the sequence is then executed.

 

*** What will happen if the condition you are using for the execution of your loop never changes value?

            -you will get an infinite loop

 

*** When are the statements in an IF statement executed?

            -when the condition is true

 

*** What is wrong with the following statement?

         If A equals B

                           Move 1 to A

         End-if

         Answer:  This should be: If A is equal to B

 

*** What is wrong with the following statement?

         If A = B

                           Move 0 to counter.

         Else

                           Move 100 to counter

         End-if

         Answer:  There should be no period after Move 0 to counter

 

*** Write an example of a nested conditional

         If condition-1

                           statement-1

         Else

                           If condition-2

                           statement-2

                           Else

                           statement-3

                           End-if

         End-if

 

*** What is wrong with the following statement?

         If A is equal to B or if B is equal to C

                  perform 500-routine

         End-if

         Answer:  With compound conditionals, the word If is only coded once.  The second if should be removed.

 

*** Write a single statement to perform 200-routine if the following conditions are all met; otherwise perform 300-routine:  A=B; C=D; E=F.

         Answer:

         If A=B and C=D and E=F

                           perform 200-routine

         Else

                           perform 300-routine

         End-if

 

*** Explain when a control break procedure is performed.

Answer:  When an input control field is not equal to the control field stored in the hold area.

 

*** Explain how the input data needs to be ordered for a control break to work properly.

Answer:  The input records must be ordered by the field you wish to use as the control field.

 

*** Explain the purpose of a compound conditional.

Answer:  A compound conditional allows the programmer to test for several conditions with one statement such as AND and OR in the same statement.

 

*** What is the sequences in conditions from high to low in EBCDIC?

0-9

A-Z

a-z

special characters

spaces

 

*** List the different types of PERFORM STATEMENTS.

Perform-Until

Perform # times

Perform Varying

 

*** What is the difference between IF-statements and EVALUATE-stateents?

The syntax is the only difference

If-Then                        Evaluate True

    Else                          When

    End-If                        When other

                                    End-evaluate

 

*** List the different conditions in order of Precedence (high to low) Cobol reads them

Numeric positive

Numeric zero

Numeric negative

Alphabetic-upper

Alphabetic-lower

special characters

spaces

 

*** What have we been using the control-break algorithm to do?
ANSWER: Sort output in groups or types.  And now to see who's been paying attention.
 
*** Explain how the COBOL perform statement can be used to do something a set number of times, like in a for loop in another language.
HARD ANSWER:     TO include the use of a counter that increments after each iteration, must also include that the counter's value controls perform statement's execution, EX: PERFORM UNTIL MyCounter = 76.
EASY ANSWER:     "PERFORM ... TIMES".
               
***Explain how COBOL if statements differ from if statements in a different Object Oriented language of your choice, such as Java, C++ or VB.
ANSWER: To include the ability of more modern languages to make multiple comparisons
               (Else if).  May also include syntactical differences, such as the use of parentheses.
 
*** What is the difference between a "normal" perform statement and an    "In Line Perform" in COBOL?
ANSWER: To include the fact that an in line perform does some statement until the condition is met, whereas a normal perform does a PARAGRAPGH until the condition is met.
 
*** Explain how a COBOL control break structure is different from a control break structure in another language like Java or C++.
ANSWER: It isn't, aside from syntax and the difficulty of getting it to work.

 

*** Name 3 types of perform statements.

Perform-until

Perform # of times

Perform varying

 

*** List the five relational operators.

£, ³, <, >, =

 

*** What is the order of precedence when it comes to “AND” and “OR”?

Conditions surrounding AND, Conditions surrounding OR, AND from left to right, OR from left to right.

 

*** The class test is used to evaluate what?

Numeric and alphabetic

 

*** The sign test is used to evaluate what?

Positive, negative, and zero

 

*** What is the name of the condition when you have the following: “if a = b and c”?

Implied

 

 

 

MULTIPLE CHOICE

 

*** Which if the following is a syntactically proper COBOL if statement?
a)             IF (AMT is less Than ZERO)
               THEN
                               ADD 1 TO Somevalue
               ELSE
                               ADD 7 to SomeOtherValue
               END IF
b)             IF (AMT is less Than ZERO)
               THEN (ADD 1 TO Somevalue)
               ELSE (ADD 7 to SomeOtherValue)
               END-IF
c)             IF AMT is less Than ZERO
               THEN
                               ADD 1 TO Somevalue
               ELSE IF AMT is EQUAL TO 4
                               ADD 7 to SomeOtherValue
               END-IF
d)             IF AMT is less Than ZERO
               THEN
                               ADD 1 TO Somevalue
               ELSE
                               ADD 7 to SomeOtherValue
               END-IF
 
ANSWER: D
 
*** How many comparisons can a single COBOL if statement make? 
               (A single comparison would be is MYVALUE > 7, for example)
a)             1
b)             2
c)             There is no limit
d)             COBOL if statements are not used to compare variable values
 
ANSWER: A
 
*** Which of the following errors are possible within a COBOL if statement?
a)             Infinite loop
b)             Logical Error
c)             Runtime Error
d)             All of the above
e)             None of the above
 
ANSWER: D 
 
*** The COBOL perform loop is the equivalent of which of the following structures found in other languages, such as Java or C++
a)             For loop
b)             Do-While loop
c)             Method
d)             None of the Above
 
ANSWER: B
 
*** If someone wanted a COBOL perform "loop" to execute once before the condition is checked, which of the following would they do?
a)             Use a standard perform statement
b)             Use an in line perform
c)             Skillful use of the COBOL reserved word "AFTER"
d)             This is not possible in COBOL
e)             Pray piously
 
ANSWER: C (Though "E" may be easier and more effective)

 

***A = 0,   B = 9…..

Perform until a > b

            Add 2 to a

End-perform

How many additions are performed?

A) 3.  B.) 4.  C.)  5.  D.)  6

Answer: C

 

*** If an IF statement is true, what’s the first thing it does?

A.)    Exits the statement

B.)    Executes the function

C.)    Exits the Program

D.)    Executes the If statement again

Answer: B

 

*** Not negative means…

A.) Equal to 0

B.) Greater than or equal to 1

C.)  Less than or equal to 0

D.)  Greater than or equal to 0

Answer: D

 

*** Which of the following is NOT a valid symbol to use in an IF condition

A.      =

B.      =<

C.      =>

D.      >

Answer: C

 

*** Which is the correct ASCII collating sequence?

A.      spaces, special characters, 0-9, A-Z, a-z

B.      spaces, a-z, A-Z, 0-9, special characters

C.      a-z, A-Z, 0-9, spaces, special characters

D.      0-9, special characters, spaces, a-z, A-Z

Answer: A

 

 

MATCHING

 

  1. Logical operators
  1. Alphabetic
  1. Perform-Until
  1. A Nested If Statement
  1. A condition
  1. Level 88
  1. Broken loop
  1. With test before

 

1. Evaluates to True or False (E)

2. Condition Names (F)

3. A class (B)

4. Default for Perform (H)

5. A Loop (C)

6. Evaluate True (D)

7. control break value does not equal temp value (G)

8. and & or (A)

 

 

PROGRAMMING PROBLEMS

 

*** You are working on staffing shifts at a hospital and are wondering how many employees are available for what shifts.  There are three shifts; mornings, afternoons, and nights.  Write a program using a single control break algorithm to total how many employees are available for each shift.  The shifts are abbreviated m for mornings, a for afternoons, and n for nights.
 
Input file description
FD h-file.
01 h-rec.
   05 emp-name pic x(10).
   05 av-shift pic x.
 
FD out-file.
01 out-total.
   05 pic x(12) value "Total Avail ".
   05 av-shift-out pic x.
   05 emp-out pic 99.
 
working storage variables
01 tot-emp pic 99 value 0.
01 cb-shift pic x.
77 eof pic x value "N".
 
Procedure Division
100-main-module
open input h-file.
open output out-file.
read h-file at end move "Y" to eof
end read
 
if eof = "N"
   move av-shift to cb-shift
end-if
 
perform 200-shift-routine
   until eof = "Y"
move av-shift to av-shift-out.
move tot-emp to emp-out.
write out-total.
close h-file.
close out-file
stop run.
 
200-shift-routine.
    if cb-shift not = av-shift
       move av-shift to av-shift-out
       move tot-emp to emp-out
       write out-total
       move 0 to tot-emp
    end-if
    add 1 to tot-emp
    read h-file
       at end move "Y" to eof.
 
 
*** You are grading exams and wish to find out the average of the exam, and how many students did better than the average of the exam.  Write a program to do this.
 
FD s-file.
01 s-rec.
   05 st-name pic x(10).
   05 st-grade pic 999.
 
FD out-file.
01 out-avg.
   05 pic x(9) value "Average: ".
   05 avg-out pic 999v99.
01 out-total.
   05 pic x(16) value "Students above: ".
   05 total-st pic 999.
 
working storage
01 tot-st pic 999 value 0.
01 tot-gr pic 9(5) value 0.
77 eof pic x value "N".
 
procedure division
100-main-module.
open input s-file.
open output out-file.
read s-file at end move "Y" to eof.
perform 200-read-data
   until eof = "Y".
Divide tot-gr by tot-st.
move tot-gr to avg-out.
write out-avg.
move 0 to ttot-st.
move "N" to eof.
close input s-file.
open input s-file.
read s-file at end move "Y" to eof
perform 250-read data 
    until eof = "Y".
move tot-st to total-st.
write out-total.
close input s-file.
close output out-file.
stop run.
 
200-read-data.
   compute tot-st = tot-st + 1
   compute tot-gr = tot-gr + st-grade
   read s-file
      at end move "Y" to eof.
 
250-read-data.
   if st-grade > tot-gr
      add 1 to tot-st
   end-if
   read s-file
      at end move "Y" to eof.

 

*** What is the output of the following code.

 

            working-storage section.

            77   credit-hours pic 999 value 108.

           

            procedure division.

           

                  If   credit-hours < 45

                            display “Freshmen”

                  End-if

                  If   credit-hours > =45 and < 90

                            displaySophmore

                  End-if

                  If   credit-hours <= 90 and > 135

                            display “Junior”

                 End-if

                 If   credit-hours > = 135

                           display “Senior”

                 End-if

                 accept omitted

                 stop run.

 

Answer:  Junior

 

***  The secretary in the business office needs to order lunch for the next staff meeting  She plans to order from a list of 5 types of sandwiches from the deli across the street.  In an input file she has written the name of each worker in the office and the type of sandwich that they will eat.  The file description and working storage variables are given below.  Add to the working storage section as necessary.

 

Input file:                                                                                   working storage variables:

FD   lunch-file.                                                               77  eof pic x value “N”.

01    lunch-rec.                                                              77  cbval-type pic x(15).

        05    employee-name-in     pic x(20).                                    77  num-cb-records  pic 99 value 0.

        05    sandwich-type-in       pic x(15).                                                                                                                                      

Output file:                                                                                   

FD   lunch-order.                                                           

01    print-rec  pic x(80).                                                      

 

Write a program to output the information in the input file grouped by the type of sandwich.  Also calculate the total number of people for each sandwich group. The output should follow the format below:

 

Sandwich: (sandwich name)

(blank)

Names of employees (one per line, no blank lines in between)

(blank)

Total order:  integer value

(blank)

à Repeat “Sandwich” section.

 

Answer:

 

working-storage section.

01  type-header.

      05  pic x(10) value “Sandwich: ”.                                                                                     

      05  sandwich-type-out   pic x(15).

01  total-label.

      05  pic x(13) value “Total order: ”.

      05  num-group-recs  pic 99.

01  ws-print-rec.

      05  employee-name-out   pic x(20).

     

procedure division.

100-main-module.

            open input lunch-file output lunch-order

            read lunch-file at end move “Y” to eof

            perform 150-type-header

            perform 200-cb-routine until eof = “Y”

            perform 250-calc-routine

            close lunch-file lunch-order

            stop run.

150-type-header.

            move sandwich-type-in to sandwich-type-out.

            write print-rec from type-header after advancing 2 lines.

            move spaces to print-rec

            write print-rec.

200-cb-routine.

            if cbval-type not = sandwich-type-in

                        perform 250-calc-routine

                        move sandwich-type-in to sandwich-type-out

                        perform 150-type-header

            end-if

            add 1 to num-cb-records

            move employee-name-in to employee-name-out

            write print-rec from ws-print-rec

            read lunch-file at end move “Y” to eof.

250-calc-routine.

            move num-cb-records to num-group-recs

            move 0 to num-cb-records

            write print-rec from total label after advancing 2 lines.