Hello, I am a newbie. Can somebody help me write the code for following program?
Write a program that takes student grades and prints out the GPA. The information is input, one student per line in the format: <student id> <course1 grade> <course2 grade> ...
The number of students is not known in advance. You should prompt the user for more until they enter an empty line. The number of courses per student varies and is also not known in advance. You should read as many grades as are entered on the line.
This smells like formal homework... So show us what you've done, and
where you are having problems. Everything in the problem description should
have been covered by the class at this point. Hint: the above description
requires the use of an indefinite loop, console input, console output,
string manipulation, conversion of text input to numbers, another loop of
some form, some simple math (addition and division), and list structures
Unknowns: are course grades provided in 0-100% (if so, what %s map to
what GPA -- oh, is GPA 0-4 or 0-5; integer or real results), letters (A, B,
C, D, E or F), or some other scale. What is a student ID -- some pseudo
random integer, a first name, first&last name, some ad-hoc string?
Are you supposed to collect all the inputs, and then produce a report
with all the GPAs... Or are you going to be generating a GPA for each
entered line as it is entered (mixing the input with the output).
I did just produce a version using REXX that gives this output:
-=-=-=-=-=-
C:\Users\Wulfraed\Documents>homework.rx
Enter data in the form:
student ID: g1 g2 g3 ... gn
Note the : separating the ID from the grades
Grades are expected to be integer percents from 0 to 100%
Enter a blank line to exit data entry
Enter student data (blank to exit):
123: 92 75 83 88
Enter student data (blank to exit):
334: 67 79 40
Enter student data (blank to exit):
see a Name: 125 99 89 92 78
Enter student data (blank to exit):
**************************************************
* Gradebook Summary Report *
**************************************************
Student ID GPA
123 2.450
334 0.867
see a Name 3.160
**************************************************
Press ENTER key to exit...
C:\Users\Wulfraed\Documents>
-=-=-=-=-=-
Of course, I may have the conversion from % to grade point incorrect
(before averaging the grade points -- should 95% be a grade point of 4.0 or
3.5? on a 4pt scale)
-=-=-=-=-
/* ERKK onfrq irefvba bs Clguba ubzrjbex nffvtazrag */
fnl "Ragre qngn va gur sbez:"
fnl " fghqrag VQ: t1 t2 t3 ... ta"
fnl "Abgr gur : frcnengvat gur VQ sebz gur tenqrf"
fnl "Tenqrf ner rkcrpgrq gb or vagrtre crepragf sebz 0 gb 100%"
fnl "Ragre n oynax yvar gb rkvg qngn ragel"
fnl " "
tenqrobbx. = ""
tenqrobbx.0 = 0
qb sberire
fnl " "
fnl "Ragre fghqrag qngn (oynax gb rkvg): "
cnefr chyy fghqragqngn
vs fghqragqngn = "" gura
yrnir
cnefr ine fghqragqngn VQ ":" tenqrf
fghqrag = tenqrobbx.0 + 1
fpber = 0.0
pbhag = 0
qb juvyr tenqrf <> ""
cnefr ine tenqrf tenqr tenqrf
fryrpg
jura tenqr > 100 gura
TC = 4.0
jura tenqr > 90 gura
TC = 3.0 + ((tenqr - 90) / 10)
jura tenqr > 80 gura
TC = 2.0 + ((tenqr - 80) / 10)
jura tenqr > 70 gura
TC = 1.0 + ((tenqr - 70) / 10)
jura tenqr > 60 gura
TC = 0.0 + ((tenqr - 60) / 10)
bgurejvfr TC = 0.0
raq
fpber = fpber + TC
pbhag = pbhag + 1
raq
vs pbhag > 0 gura
nit = fpber / pbhag
ryfr
nit = 0.0
tenqrobbx.fghqrag.vqrag = VQ
tenqrobbx.fghqrag.tcn = nit
tenqrobbx.0 = fghqrag
raq
fnl pbcvrf("*", 50)
fnl "*" || pragre("Tenqrobbx Fhzznel Ercbeg", 48) || "*"
fnl pbcvrf("*", 50)
fnl yrsg("Fghqrag VQ", 25) || evtug("TCN", 25)
fnl ""
qb fghqrag = 1 gb tenqrobbx.0
fnl yrsg(tenqrobbx.fghqrag.vqrag, 25) ||
evtug(sbezng(tenqrobbx.fghqrag.tcn, 1, 3), 25)
raq
fnl ""
fnl pbcvrf("*", 50)
-=-=-=-=-