Forum > General
If Else statement
maryg:
Hi Guys,
I'm working on a student progress analysis system and I'm trying to set it up in such a way that the scores per subject are linked to the school's grading statement i.e if the student scores 80% then the grade will show 'A' in the report.
The system is being used by a Secondary School, so the different subject clusters(Languages, Humanities, Sciences) have somewhat different grading systems.
Please any ideas on such a code?
Handoko:
I personally think the calculation should not be hard coded into the source. You can use a config file (or maybe database) to store what and how each items will affect the formula. Then you write a CalculateGrading function, which contains lots of if-then-else to calculate the result based on the data read from the file.
HeavyUser:
--- Quote from: maryg on October 17, 2018, 08:53:27 am ---Hi Guys,
I'm working on a student progress analysis system and I'm trying to set it up in such a way that the scores per subject are linked to the school's grading statement i.e if the student scores 80% then the grade will show 'A' in the report.
The system is being used by a Secondary School, so the different subject clusters(Languages, Humanities, Sciences) have somewhat different grading systems.
Please any ideas on such a code?
--- End quote ---
how many grades are they equally spread across the scale? if not what are the rules for each grade on the scale per department? for a 5 grade system equally spaced on the 100 scale for example you can do something along the lines of
--- Code: ---Type
TGrade = (E,D,C,B,A);
const
cStep = 100 / 5;
function Grade(const aScore:integer):TGrade;
begin
result := TGrade(floor(ascore / cstep));
end;
--- End code ---
treat it as a pseudo code it was typed directly on the browser and never been compiled or tested in any way.
maryg:
The grading system is on a 100% scale with intervals e.g 100-75 'A', 70-74 'A-', 65-69 'B+',... but this differs in the different departments.
madref:
Then make it a case-statement
--- Code: ---case score of
100..75: Grade := 'A';
74..70: Grade := 'A-';
...
...
else
Grade := 'You failed miserably !!';
end; // case;
--- End code ---
You can put this in different function with a name like
--- Code: --- function GradeForDepartmantX (Score: Integer) : String;
function GradeForDepartmantY (Score: Integer) : String;
function GradeForDepartmantZ (Score: Integer) : String;
--- End code ---
And then you can make another case with the different department like
--- Code: --- case Department of
'X' : Grade := GradeForDepartmantX;
'Y' : Grade := GradeForDepartmantY;
'Z' : Grade := GradeForDepartmantZ;
end; // case
--- End code ---
Navigation
[0] Message Index
[#] Next page