Note, there are many errors in your script. Rather than try to fix that script, let's use a method that does not require any script at all except maybe to perform a find and sort to automate setting up your reports.
Try using summary fields to compute totals, averages for all the records in a found set and for sub groups within them.
Define this field to compute the class average:
sClassAverage, define it as a field of type Summary that computes the Average Grade
If you perform a find for all records of a given classroom, sClassAverage will compute the average grade for that class. If you create a list view layout with a sub Summary part "when sorted by Class". You can put sClassAverage in this sub summary part to display all the class averages for all your classes in the same report.
See this tutorial on creating summary reports: