View previous topic :: View next topic
|
Author |
Message |
vin12pr Warnings : 1 New User
Joined: 14 Jun 2006 Posts: 56
|
|
|
|
I have around 10 quesions in a sequential file.Now i would like to write a cobol program which will read this file and produce 10 diffrent sets of question papers in which the question order should differ from one question paper to another.
Code: |
Note: Each question papers should contain all the 10 questions but the order must be different from one question paper to the other. |
|
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Load all 10 into a table.
Generate random numbers into another 10 element array.
Search this array for the random numbers from lowest to highest.
Each time you find the next sequential number, use the equivalent question.
When you have done all ten, go back to the generate and repeat.
No real guarantee, but all should be somewhat different. |
|
Back to top |
|
|
vin12pr Warnings : 1 New User
Joined: 14 Jun 2006 Posts: 56
|
|
|
|
thanks for the reply Williams...can you please expand your explanition some more as i am finding it difficult to understand |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
What part are you finding difficult to understand? |
|
Back to top |
|
|
vin12pr Warnings : 1 New User
Joined: 14 Jun 2006 Posts: 56
|
|
|
|
Generate random numbers into another 10 element array.it is this part. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
If you can't find a integrated way to produce random numbers, there are simple ways to get them that are good enough for this application. |
|
Back to top |
|
|
vin12pr Warnings : 1 New User
Joined: 14 Jun 2006 Posts: 56
|
|
|
|
Hi williams...Can you please help me by expanding the pseudocode what you have allready provided...i am finding it difficult to understand.THnx in advance..... |
|
Back to top |
|
|
Aji
New User
Joined: 03 Feb 2006 Posts: 53 Location: Mumbai
|
|
|
|
Please check the following logic.
working-storage section.
01 a.
02 b occurs 10 times.
05 c pic x.
01 i pic 99 value 1.
01 temp pic x.
procedure division.
p0.
move "ABCDEFGHIJ" to a.
perform p1 10 times.
stop run.
p1.
perform p2 10 times.
move c(1) to temp.
move 1 to i.
perform p3 9 times.
move temp to c(10).
move 1 to i.
p2.
display c(i).
add 1 to i.
p3.
move c( i + 1 ) to c(i).
add 1 to i.
Aji |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Hello vin12pr,
The problem you present, on the surface may seem a simple task, but in implementation is not quit so simple. What you want is a series of random numbers 1 through 10, that do not repeat themselves in any given sequence, and that the sequence itself does not repeat for the duration of the run.
Given this, most of the processing done is checking if there is a repeat.
The code below is most of the way to where you need to be. The logic to ensure that the sequence itself does not repeat itself I leave up to you. It just wouldn?t be fun if someone gave you the whole logic.
Code: |
WORKING-STORAGE SECTION.
01 WS-D-NUMBER PIC S9(11) COMP-3
VALUE +0.
01 WS-R-NUMBER PIC S9(3) COMP-3
VALUE +0.
01 SUB PIC S9(3) COMP-3
VALUE +0.
01 WS-TABLES.
05 WS-QUESTIONS.
10 FILLER PIC X(100) VALUE 'QUESTION 01'.
10 FILLER PIC X(100) VALUE 'QUESTION 02'.
10 FILLER PIC X(100) VALUE 'QUESTION 03'.
10 FILLER PIC X(100) VALUE 'QUESTION 04'.
10 FILLER PIC X(100) VALUE 'QUESTION 05'.
10 FILLER PIC X(100) VALUE 'QUESTION 06'.
10 FILLER PIC X(100) VALUE 'QUESTION 07'.
10 FILLER PIC X(100) VALUE 'QUESTION 08'.
10 FILLER PIC X(100) VALUE 'QUESTION 09'.
10 FILLER PIC X(100) VALUE 'QUESTION 10'.
05 TBL-QUESTIONS REDEFINES WS-QUESTIONS
PIC X(100) OCCURS 10 TIMES.
05 TBL-RAND-ORDER PIC S9(3) COMP-3
OCCURS 10 TIMES.
05 TBL-Q-NUMBER PIC S9(3) COMP-3
OCCURS 10 TIMES.
PROCEDURE DIVISION.
PROGRAM-START.
* LOAD THE QUESTION TABLE WITH QUESTIONS FROM FILE
PERFORM
10 TIMES
PERFORM P2000-POPULATE-TBL-RAND-ORDER
THRU P2000-EXIT
PERFORM P3000-PRINT-RAND-QUESTIONS
THRU P3000-EXIT
END-PERFORM.
GOBACK.
P2000-POPULATE-TBL-RAND-ORDER.
PERFORM
VARYING SUB FROM 1 BY 1
UNTIL SUB > 10
MOVE 0 TO TBL-RAND-ORDER (SUB)
TBL-Q-NUMBER (SUB)
END-PERFORM.
PERFORM
VARYING SUB FROM 1 BY 1
UNTIL SUB > 10
PERFORM
WITH TEST AFTER
UNTIL TBL-Q-NUMBER ( WS-R-NUMBER ) = 0
COMPUTE WS-D-NUMBER
= FUNCTION RANDOM * 100000000000
DIVIDE WS-D-NUMBER BY 10 GIVING WS-D-NUMBER
REMAINDER WS-R-NUMBER
ADD 1 TO WS-R-NUMBER
END-PERFORM
MOVE WS-R-NUMBER TO TBL-RAND-ORDER (SUB)
TBL-Q-NUMBER (WS-R-NUMBER)
END-PERFORM.
P2000-EXIT.
EXIT.
P3000-PRINT-RAND-QUESTIONS.
DISPLAY ' '
PERFORM
VARYING SUB FROM 1 BY 1
UNTIL SUB > 10
MOVE TBL-RAND-ORDER (SUB) TO WS-R-NUMBER
DISPLAY TBL-QUESTIONS (WS-R-NUMBER)
END-PERFORM.
P3000-EXIT.
EXIT.
|
Dave |
|
Back to top |
|
|
vin12pr Warnings : 1 New User
Joined: 14 Jun 2006 Posts: 56
|
|
|
|
Thanks David...Can you please explain that RANDOM function which u have used..I am not understanding as to how it works...Thanks in advance. |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
Back to top |
|
|
vin12pr Warnings : 1 New User
Joined: 14 Jun 2006 Posts: 56
|
|
|
|
When I use the Function Random statement in the program,its throwing the error as ""FUNCTION" was not defined as a data-name".
Can anybody please advise as to why it is happening like this.
Can anybody place the proper syntax for using the cobol functions in an application program. |
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
Hi !
That depends on your installed cobol-version in your company.
Not all commands are allowed under standard IBm COBOL-II.
Depends on version & level of installation.
Other solution, if DB2 is installed:
Write those ten questions into a dataset, prefixed with a timestamp.
Then you can sort them in several ways to printer. Ten minutes work.
Regards & happy new year
UmeySan |
|
Back to top |
|
|
|