For Programmers: Free Programming Magazines  


Home > Archive > Cobol > February 2007 > Creating a College Grading system using COBOL









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Creating a College Grading system using COBOL
selworthy

2007-02-06, 6:55 pm

Does anyone know how to create a program in COBOL using the following
promts (as it would be written in MS Excel)?

=IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F"))))


Thanks,
Kris

Howard Brazee

2007-02-06, 6:55 pm

On 6 Feb 2007 11:49:21 -0800, "selworthy"
<kristopher.crockett@charter.net> wrote:

>Does anyone know how to create a program in COBOL using the following
>promts (as it would be written in MS Excel)?
>
>=IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F"))))


Yes. Any CoBOL programmer should be able to do this, are you
hiring?
HeyBub

2007-02-06, 6:55 pm

selworthy wrote:
> Does anyone know how to create a program in COBOL using the following
> promts (as it would be written in MS Excel)?
>
> =IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F"))))
>
>


(Waves hand) I do! I do!


LX-i

2007-02-06, 6:55 pm

selworthy wrote:
> Does anyone know how to create a program in COBOL using the following
> promts (as it would be written in MS Excel)?
>
> =IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F"))))


I have an idea how I'd do it - what have you tried?

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ daniel@thebelowdomain ~
~ _____ / \ | ~ http://www.djs-consulting.com ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ GEEKCODE 3.12 GCS/IT d s-:+ a C++ L++ E--- W++ N++ o? K- w$ ~
~ !O M-- V PS+ PE++ Y? !PGP t+ 5? X+ R* tv b+ DI++ D+ G- e ~
~ h---- r+++ z++++ ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~

"Who is more irrational? A man who believes in a God he doesn't see, or
a man who's offended by a God he doesn't believe in?" - Brad Stine
LX-i

2007-02-06, 9:55 pm

LX-i wrote:
> selworthy wrote:
>
> I have an idea how I'd do it - what have you tried?


Here's what I tried...

identification division.
program-id. GradeMachine.

data division.
working-storage section.

77 inputGrade pic 9(03).
77 outputGrade pic X(01).

procedure division.

display "Please enter the grade"
accept inputGrade

call "AssignGradeLetter"
using inputGrade, outputGrade
end-call

display "The grade is " outputGrade

stop run
epc8@juno.com

2007-02-08, 3:55 am

On Feb 6, 10:30 pm, LX-i <lxi0...@netscape.net> wrote:
> LX-i wrote:
>
>
>
> Here's what I tried...
>
> identification division.
> program-id. GradeMachine.
>
> data division.
> working-storage section.
>
> 77 inputGrade pic 9(03).
> 77 outputGrade pic X(01).
>
> procedure division.
>
> display "Please enter the grade"
> accept inputGrade
>
> call "AssignGradeLetter"
> using inputGrade, outputGrade
> end-call
>
> display "The grade is " outputGrade
>
> stop run
> .
>
> identification division.
> program-id. AssignGradeLetter.
>
> data division.
> working-storage section.
>
> 01 grades.
> 12 pic X value "F".

[snip look up table]
> 12 pic X value "A".
> 01 gradeTable redefines grades.
> 12 letterGrade occurs 100 times
> indexed by letterGradeIdx
> pic X(01).
>
> linkage section.
> 77 inputGrade pic 9(03).
> 77 outputGrade pic X(01).
>
> procedure division
> using inputGrade outputGrade.
>
> evaluate inputGrade when 1 thru 100
> set letterGradeIdx to inputGrade
> move letterGrade (letterGradeIdx) to outputGrade
> when other
> move "?" to outputGrade
> end-evaluate
> .
> end program AssignGradeLetter.
>
> end program GradeMachine.


Looking at the equal widths of most of the class intervals, why not
use linear interpolation instead?

<rhetorical question>

identification division.
program-id. grade.
environment division.
configuration section.
source-computer. ibm-pc.
object-computer. ibm-pc.
data division.
working-storage section.
01 in-num pic 9(3).
01 out-grade pic x.
01 grade-idx pic s9.
01 grades.
05 filler pic x(5) value 'FDCBA'.
01 grade-table redefines grades.
05 letter-grade pic x occurs 5 times.
procedure division.
main.
display 'enter numeric grade'
accept in-num
perform num-to-grade
display 'grade is ' out-grade
stop run
Albert

2007-02-08, 6:55 pm


"selworthy" <kristopher.crockett@charter.net> schreef in bericht
news:1170791361.599169.251290@j27g2000cwj.googlegroups.com...
> Does anyone know how to create a program in COBOL using the following
> promts (as it would be written in MS Excel)?
>
> =IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F"))))
>
>
> Thanks,
> Kris
>

Evaluate true
when A2 > 89
Move 'A' to {field}
when A2 > 79
Move 'B' to {field}
when A2 > 69
Move 'C' to {field}
when A2 > 59
Move 'D' to {field}
when other
Move 'F' to {field}
end-evaluate.

Persume A2 is a numeric field.
And {field} is an alfanumeric field.




Pete Dashwood

2007-02-08, 6:55 pm


"selworthy" <kristopher.crockett@charter.net> wrote in message
news:1170791361.599169.251290@j27g2000cwj.googlegroups.com...
> Does anyone know how to create a program in COBOL using the following
> promts (as it would be written in MS Excel)?
>
> =IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F"))))
>
>
> Thanks,
> Kris
>

Perfect text book example of a decision tree, and can be implemented nicely
with a single COBOL nested IF.

if A2 > 59
if A2 > 69
if A2 > 79
if A2 > 89
move "A" to grade
else
move "B" to grade
end-if
else
move "C" to grade
end-if
else
move "D" to grade
end-if
else
move "F" to grade
end-if

This approach can be easily amended if the "intervals" or grades change,
doesn't use a contrived EVALUATE TRUE (which serves no purpose other than to
document the ranges), and is efficient at execution time. (If this is
actually a consideration, you can make it REALLY efficient, by reorganising
it so that the most likely conditions are tested first, but that means
introducing NOT and makes the whole thng much less elegant. Simple is
good...:-))

Of course, it is banned on most sites because ...

a. People misuse it (mainly by nesting further conditions into the false
branches, which adulterates the purity and simplicity of the construct)

b. COBOL "programmers" are not expected to understand "logic" and it is
therefore too complex for them.

c. Managers should be able to read COBOL programs and this sort of thing
smacks of "tech" and doesn't look like English, so it must therefore be
stamped out at once.

(Yes, I'm cynical... having worked as a programmer on one or two COBOL
sites, for one or two years, in one or two countries, and seen the power of
COBOL dragged down to the lowest common denominator by people who have no
idea what computer programming is about... :-))

I can't take credit for this (not that I suspect any will be forthcoming
anyway... :-)). I learned it in 1968 (and modified it slightly to
accommodate scope delimiters when they became available) from a book ("COBOL
logic and Programming", ly, long since out of print) published by the
University of Louisiana, and written by Doctor Fritz D. MacCameron (whom I
suspect is also now "out of print"... pity... As a very young, keen, COBOL
programmer I devoured his book avidly and I still think it was one of the
best books ever written about COBOL.

Pete.


Richard

2007-02-08, 9:55 pm

On Feb 7, 8:49 am, "selworthy" <kristopher.crock...@charter.net>
wrote:
> Does anyone know how to create a program in COBOL using the following
> promts (as it would be written in MS Excel)?
>
> =IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F"))))


I much prefer table driven code rather than programmer driven code.
With this code the table can be changed to give different grades
without changing the program logic. It can even add additional grades
(such as 'E') with changing the logic of the code.

I would actually have the program read the scores and grades from a
configuration file or a SQL table and then it could be changed by the
users without having to change the code at all or even recompile.

In fact one could have as a run parameter the name of the set of
scores and grades to be used, or have this as an item in a file of
results that need grading such that the program will select the
appropriate set itself.

Just make sure that each set ends with a 999 entry.

01 Score PIC 9(3).
01 Grade PIC X.

01 Grade -Table.
03 FILLER PIC X(4) VALUE "000F".
03 FILLER PIC X(4) VALUE "060D".
03 FILLER PIC X(4) VALUE "070C".
03 FILLER PIC X(4) VALUE "080B".
03 FILLER PIC X(4) VALUE "090A".
03 FILLER PIC X(4) VALUE "999-".
01 Grade-Items REDEFINES Grade-Table.
03 Grade-Item OCCURS 6.
05 Grade-Score PIC 999.
05 Grade-Result PIC X.

DISPLAY "Enter Score:"
ACCEPT Scrore

PERFORM VARYING I FROM 1 BY 1
UNTIL Grade-Result(I) > 100

IF ( Score >= Grade-Score(I) )
MOVE Grade-Result(I) TO Grade
END-IF
END-PERFORM

DISPLAY "Grade: " Grade


epc8@juno.com

2007-02-09, 3:55 am

On Feb 8, 6:34 pm, "Pete Dashwood"
<dashw...@removethis.enternet.co.nz> wrote:
> "selworthy" <kristopher.crock...@charter.net> wrote in message
>
> news:1170791361.599169.251290@j27g2000cwj.googlegroups.com...> Does anyone know how to create a program in COBOL using the following
>
>
>
> Perfect text book example of a decision tree, and can be implemented nicely
> with a single COBOL nested IF.
>
> if A2 > 59
> if A2 > 69
> if A2 > 79
> if A2 > 89
> move "A" to grade
> else
> move "B" to grade
> end-if
> else
> move "C" to grade
> end-if
> else
> move "D" to grade
> end-if
> else
> move "F" to grade
> end-if
>
> This approach can be easily amended if the "intervals" or grades change,
> doesn't use a contrived EVALUATE TRUE (which serves no purpose other than to
> document the ranges), and is efficient at execution time. (If this is
> actually a consideration, you can make it REALLY efficient, by reorganising
> it so that the most likely conditions are tested first, but that means
> introducing NOT and makes the whole thng much less elegant. Simple is
> good...:-))
>


Or, if you like Pascal you can structure the nested IF as

if A2 > 100
move "?" to grade
else
if A2 > 89
move "A" to grade
else
if A2 > 79
move "B" to grade
else
if A2 > 69
move "C" to grade
else
if A2 > 59
move "D" to grade
else
move "F" to grade
end-if
end-if
end-if
end-if
end-if

but why not let the compiler do the work and use

evaluate A2
when 0 through 59
move "F" to grade
when 60 through 69
move "D" to grade
when 70 through 79
move "C" to grade
when 80 through 89
move "B" to grade
when 90 through 100
move "A" to grade
when other
move "?" to grade
end-evaluate

instead?

-- Elliot

aside: My code example using interpolation was meant as a joke.



Pete Dashwood

2007-02-09, 7:55 am


<epc8@juno.com> wrote in message
news:1170993613.309660.258500@j27g2000cwj.googlegroups.com...
> On Feb 8, 6:34 pm, "Pete Dashwood"
> <dashw...@removethis.enternet.co.nz> wrote:
>
> Or, if you like Pascal you can structure the nested IF as


You COULD, but then it wouldn't be a COBOL textbook example...

Such an example does not have actions following each IF. The tree requires
the conditions ONLY to be nested in the TRUE branch; actions are nested ONLY
in the FALSE branches. Although the language supports deviation from this,
any such deviation invalidates the purity of the structure as a "decision
tree" (Conditions nested in the FALSE branches are considered to be actions,
and are acceptable as "twigs".)

<snipped Pascal example>
> but why not let the compiler do the work and use
>

The compiler is going to do the work whatever way you code it :-)

> evaluate A2
> when 0 through 59
> move "F" to grade
> when 60 through 69
> move "D" to grade
> when 70 through 79
> move "C" to grade
> when 80 through 89
> move "B" to grade
> when 90 through 100
> move "A" to grade
> when other
> move "?" to grade
> end-evaluate
>
> instead?


This is definitely better than EVALUATE TRUE and is the solution that most
shops would prefer. Each range is clearly documented and easily maintained.

However, the nested IF decision tree predates the availablility of EVALUATE
in COBOL...

Pete.


Howard Brazee

2007-02-09, 6:55 pm

On Fri, 9 Feb 2007 12:34:04 +1300, "Pete Dashwood"
<dashwood@removethis.enternet.co.nz> wrote:

>Of course, it is banned on most sites because ...


But not in any sites I have worked at.
Ron

2007-02-09, 6:55 pm

"Richard" <riplin@Azonic.co.nz> wrote:
> 03 Grade-Item OCCURS 6.
> 05 Grade-Score PIC 999.
> 05 Grade-Result PIC X.

--snip--
> PERFORM VARYING I FROM 1 BY 1
> UNTIL Grade-Result(I) > 100


Huh? You're comparing a single character alphameric field
to a numeric 100 and expecting it to exceed?

--
Ron
(user ron
in domain spamblocked.com)
HeyBub

2007-02-09, 6:55 pm

selworthy wrote:
> Does anyone know how to create a program in COBOL using the following
> promts (as it would be written in MS Excel)?
>
> =IF(A2>89,"A",IF(A2>79,"B", IF(A2>69,"C",IF(A2>59,"D","F"))))
>
>
> Thanks,
> Kris


If the school is Harvard,

PROCEDURE DIVISION.
ACCEPT SCORE.
DISPLAY "Grade is A"
STOP RUN.


Richard

2007-02-09, 6:55 pm

On Feb 10, 8:19 am, Ron <r...@address.below> wrote:
> "Richard" <rip...@Azonic.co.nz> wrote:
> --snip--
>
> Huh? You're comparing a single character alphameric field
> to a numeric 100 and expecting it to exceed?


Well spotted.
[color=darkred]


Howard Brazee

2007-02-09, 6:55 pm

On Fri, 09 Feb 2007 14:19:54 -0500, Ron <ron@address.below> wrote:

>--snip--
>
>Huh? You're comparing a single character alphameric field
>to a numeric 100 and expecting it to exceed?


Exceed what? 100?
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com