Page 2 of 3

Re: How to Implement Bubble sort in Cobol ??

PostPosted: Thu Nov 25, 2010 2:06 am
by steve-myers
Perhaps the real requirement is to determine a median value, which often implies a sort.

Re: How to Implement Bubble sort in Cobol ??

PostPosted: Thu Nov 25, 2010 3:15 am
by dick scherrer
Hi Steve,

Possibly - we're kinda limited when so little usable info is posted. . . :(

d

Re: How to Implement Bubble sort in Cobol ??

PostPosted: Thu Nov 25, 2010 5:24 am
by steve-myers
Agreed. Until I saw the OP was "stuck" after he had gotten the average, so the next usable statistic - often the more meaningful statistic in many circumstances - is a median.

Re: How to Implement Bubble sort in Cobol ??

PostPosted: Thu Nov 25, 2010 7:15 am
by gauthamnagpur18
Sorry for not providing info .

Code to Find total :

 5000-TOTAL-RTN.                                   
                                                   
     MOVE 0 TO WS-I                                 
     MOVE ID-NO-IN TO ID-NO-OUT                     
     MOVE STUDENT-NAME-IN TO STUDENT-NAME-OUT       
     MOVE EXAM1 TO EXAM1-OUT                       
     MOVE EXAM2 TO EXAM2-OUT                       
     MOVE EXAM3 TO EXAM3-OUT                       
     ADD EXAM1 EXAM2 EXAM3 GIVING WS-AVERAGE(WS-I) 
     DIVIDE 3 INTO WS-AVERAGE(WS-I) ROUNDED         
     IF WS-AVERAGE(WS-I) IS GREATER THAN 060       
     PERFORM 5001-PASS-RTN                         
     ELSE                                           
     PERFORM 5002-FAIL-RTN                         
     ADD 1 TO WS-I                                 
     END-IF.                                       



Code to find Rank which i have tried :

 5003-RANK-CAL.                                         
                                                       
     PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I= 5     
     PERFORM VARYING WS-Y FROM WS-I BY 1 UNTIL WS-Y>5   
     IF WS-AVERAGE(WS-Y) < WS-AVERAGE(WS-I)             
     MOVE WS-AVERAGE(WS-I) TO WS-TEMP                   
     MOVE WS-AVERAGE(WS-Y) TO WS-AVERAGE(WS-I)         
     MOVE WS-TEMP TO WS-AVERAGE(WS-Y)                   
     END-IF                                             
     END-PERFORM                                       
     END-PERFORM.                                       


Working Storage Section :
                                                           
  01 WS-DETAIL-LINE.                                       
      05 FILLER                        PIC X(3) VALUE SPACES.
      05 ID-NO-OUT                  PIC X(5).             
      05 FILLER                        PIC X(5) VALUE SPACES.
      05 STUDENT-NAME-OUT    PIC X(20).             
      05 EXAM1-OUT                 PIC X(5).             
      05 FILLER                        PIC X(2) VALUE SPACES.
      05 EXAM2-OUT                 PIC X(5).             
      05 FILLER                        PIC X(3) VALUE SPACES.
      05 EXAM3-OUT                  IC X(5).             
      05 FILLER                     PIC X(3) VALUE SPACES.
      05 WS-AVER1                   PIC 9(3).             
      05                            PIC X(9) VALUE SPACES.
      05 STATUS-OUT                 PIC X.                 
                                                           
  01 WS-AVER.                                             
      10 WS-AVERAGE  OCCURS 5 TIMES INDEXED BY WS-I       
                      PIC 9(3).                           

Re: How to Implement Bubble sort in Cobol ??

PostPosted: Thu Nov 25, 2010 9:49 am
by dick scherrer
Hello,

It will help us help you if you post some sample "input" data and the result(s) you want when that sample data is processed by your code.

Re: How to Implement Bubble sort in Cobol ??

PostPosted: Thu Nov 25, 2010 10:47 pm
by gauthamnagpur18
Hi ,

Input :

Student-ID Student-Name Mark 1 Mark2 Mark3
00000001 HArris 58 52 90
00000002 Raam 100 99 60
00000003 Chris 67 100 70



O/p :

Student-ID Student-Name Mark 1 Mark2 Mark3 Average Rank
00000002 Raam 100 99 60 86 1
00000003 Chris 67 100 70 79 2
00000001 HArris 58 52 90 66 3


Based on average , Rank is alloted.

Thanks

Re: How to Implement Bubble sort in Cobol ??

PostPosted: Fri Nov 26, 2010 9:31 am
by dick scherrer
Hello,

Ok - i believe we are all on the same page now :)

Are you still stuck?

If you have all of the info in an array and have calculated the average (and put this into the array also), you are ready to implement the bubble sort to get the results into the desired sequence. Keep in mind that most of these sorts sort from low to high but you want to sort descending (high to low).

If the descending sort causes problems, suggest you sort ascendng and then process the array from the bottom afgter the sort.

Re: How to Implement Bubble sort in Cobol ??

PostPosted: Sat Nov 27, 2010 8:18 pm
by gauthamnagpur18
Ya i really got stuck. I have found out average for all student-ids but there is problem in finding the rank .Actually I don know how to use table concept and Implement bubble sort here .

Re: How to Implement Bubble sort in Cobol ??

PostPosted: Sat Nov 27, 2010 9:38 pm
by Akatsukami
gauthamnagpur18 wrote:Ya i really got stuck. I have found out average for all student-ids but there is problem in finding the rank .Actually I don know how to use table concept and Implement bubble sort here .

Deary, deary, me :P

Do you understand the concept of a working-storage variable? Do understand that you may define many such variables?

Then consider that a COBOL table (or any sort of array implementation in any language) is a number of working-storage variables, all of which have the same name, but which may be differentiated by the usage of an index or a subscript (different things in COBOL, although not in most other languages).

Thus, you might write:
01  WS-VARIABLE-1        PIC X(10).
01  WS-VARIABLE-2        PIC X(10).
        :
        :
01  WS-VARIABLE-100      PIC X(10).

But if you had some intelligence and education, you'd understand that you were much better off writing:
01  WS-TABLE OCCURS 100 TIMES INDEXED BY WS-TABLE-INDEX PIC X(10).

Since in the first case, you'd have to process the variables like:
MOVE WS-SOMETHING TO WS-VARIABLE-1.
MOVE WS-SOMETHING TO WS-VARIABLE-2.
        :
        :
MOVE WS-SOMETHING TO WS-VARIABLE-100.

Whereas in the second you could write:
PERFORM MOVE-TO-ELEMENT
    VARYING WS-TABLE-INDEX FROM 1 UNTIL WS-TABLE-INDEX > 100.
        :
        :
MOVE-TO-ELEMENT.
 
MOVE WS-SOMETHING TO WS-TABLE(WS-TABLE-INDEX).

Questions?

Re: How to Implement Bubble sort in Cobol ??

PostPosted: Mon Dec 06, 2010 7:14 pm
by gauthamnagpur18
Hi
I am still struggling to get output . Pls tell me what to do ??? Till average calculation , I have completed ! Next Rank Calculation is little bit tuff for me !!

Thanks
Gautham