COBOL Online Quiz


Advertisements

Following quiz provides Multiple Choice Questions (MCQs) related to COBOL Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - Which of the following file opening mode is invalid in COBOL?

A - APPEND

B - INPUT

C - OUTPUT

D - EXTEND

Answer : A

Explanation

Valid file opening modes in COBOL are INPUT, OUTPUT, I-O, and EXTEND. APPEND file mode is not available in COBOL.

Q 2 - Where can we specify OCCURS clause?

A - Elementary Item

B - Group Item

C - Both A & B

D - None of these

Answer : C

Explanation

In array declaration, we can specify occurs clause on Elementary item as well as on Group item also.

Answer : B

Explanation

Input-Output section comes under Environment division which provides information about the files to be used in the program.

Q 4 - Moving a Numeric field to Alphabetic is legal?

A - Yes

B - No

Answer : B

Explanation

Moving a numeric field to alphabetic field is illegal in COBOL. It will throw error.

Q 5 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

PROCEDURE DIVISION.
   A-PARA.
   PERFORM DISPLAY 'A'
   END-PERFORM.
   PERFORM C-PARA THRU E-PARA.
   
   B-PARA.
   DISPLAY 'B'.
   STOP RUN.
   
   C-PARA.
   DISPLAY 'C'.
   
   D-PARA.
   DISPLAY 'D'.
   
   E-PARA.
   DISPLAY 'E'.

A - ACDEB

B - ADCEB

C - DEBAC

D - DACEB

Answer : A

Explanation

This is to show how control goes from one Perform statement to other. Go step by step you will understand the flow.

You can try same code using Try it option available below:

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

PROCEDURE DIVISION.
   A-PARA.
   PERFORM DISPLAY 'A'
   END-PERFORM.
   PERFORM C-PARA THRU E-PARA.
   
   B-PARA.
   DISPLAY 'B'.
   STOP RUN.
   
   C-PARA.
   DISPLAY 'C'.
   
   D-PARA.
   DISPLAY 'D'.
   
   E-PARA.
   DISPLAY 'E'.

Q 6 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-CNT PIC 9(2) VALUE 0.
   01 WS-STRING PIC X(15) VALUE 'AABCDACDAAEAAAF'.
   
PROCEDURE DIVISION.
   INSPECT WS-STRING TALLYING WS-CNT FOR ALL 'A'.
   DISPLAY WS-CNT
   
STOP RUN.

A - 09

B - 06

C - 08

D - 10

Answer : C

Explanation

Inspect statement will count the number of 'A' in the string and will put the value in WS-CNT.

You can try same code using Try it option available below:

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-CNT PIC 9(2) VALUE 0.
   01 WS-STRING PIC X(15) VALUE 'AABCDACDAAEAAAF'.
   
PROCEDURE DIVISION.
   INSPECT WS-STRING TALLYING WS-CNT FOR ALL 'A'.
   DISPLAY WS-CNT
   
STOP RUN.

Q 7 - How records are stored & accessed in relative file organization?

A - Relative address

B - Sequentially

C - Directly

D - Both B & C

Answer : A

Explanation

A relative file consists of records ordered by their relative address.

Q 8 - Value clause is an optional clause which is used to initialize the data items. The values can be numeric literal, alphanumeric literal, or figurative constant. State whether true or false?

A - False

B - True

Answer : B

Explanation

This statement is correct.

Q 9 - What is the output of following program?

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-STRING PIC A(30) VALUE 'WELCOME TO TUTORIALSPOINT'.
   01 WS-STR1 PIC A(7).
   01 WS-STR2 PIC A(2).
   01 WS-STR3 PIC A(15).
   01 WS-COUNT PIC 99 VALUE 1.

PROCEDURE DIVISION.
   UNSTRING WS-STRING DELIMITED BY SPACE
      INTO WS-STR1, WS-STR2, WS-STR3
   END-UNSTRING.
   
   DISPLAY WS-STR2.
   
STOP RUN.

A - WelcomeTo

B - To

C - Tutorialspoint

D - point

Answer : B

Explanation

Unstring verb is used to split one string into multiple sub-strings.

You can try same code using Try it option available below:

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-STRING PIC A(30) VALUE 'WELCOME TO TUTORIALSPOINT'.
   01 WS-STR1 PIC A(7).
   01 WS-STR2 PIC A(2).
   01 WS-STR3 PIC A(15).
   01 WS-COUNT PIC 99 VALUE 1.

PROCEDURE DIVISION.
   UNSTRING WS-STRING DELIMITED BY SPACE
      INTO WS-STR1, WS-STR2, WS-STR3
   END-UNSTRING.
   
   DISPLAY WS-STR2.
   
STOP RUN.

Q 10 - Sign condition is used to check the sign of a numeric operand. It determines whether a given numeric value is greater than, less than, or equal to ZERO. State whether true or false?

A - False

B - True

Answer : B

Explanation

This statement is correct.

cobol_questions_answers.htm
Advertisements