module histogram; from PieChart import all; from GradeTable import all; from class import Class; export all; object Histogram is components: bin:Bin*, histogramsector:HistogramSector*; end Histogram; object Bin is components: percentage:integer, studentcount:integer; end Bin; object HistogramSector is components: lettergrade:string, studentcount:integer, startpercentage:integer, endpercentage:integer, Color; end HistogramSector; operation ModifyHistogram is inputs: gs:GradeScale, class:Class; outputs: gs':GradeScale; description: (*Modify the Histogram on display*); precondition: (*The histogram should never be in a state where an input needs to be checked. No precondition.*); postcondition: (*The data for the new gradescale matches that of the modified histogram.*) SumOfCountInBin(gs.histogram, 0) = #(class.studs) and (forall (i:integer | i >= 1 and (i < #(gs'.piechart.piesector))) (gs'.histogram.histogramsector[i].lettergrade = gs'.piechart.piesector[i].lettergrade) and ((gs'.histogram.histogramsector[i].studentcount / #(class.studs) * 100) = gs'.piechart.piesector[i].percentage) and (gs'.histogram.histogramsector[i].lettergrade = gs'.gradetable.rga[i].lettergrade) and ((gs'.histogram.histogramsector[i].studentcount / #(class.studs) * 100) = gs'.gradetable.rga[i].percentage)); end ModifyHistogram; operation CreateHistogram is inputs: gs:GradeScale; outputs: histogram':Histogram; description: (*Creates a new histogram when grade scale functionality is called*); precondition: (*The histogram should never be in a state where an input needs to be checked. No precondition.*); postcondition: (*The created histogram is the histogram in gradescale.*) histogram' = gs.histogram; end CreateHistogram; operation SaveHistogram is inputs: gs:GradeScale, class:Class; outputs: class':Class; description: (*Save changes made on the Histogram to the GradeScale*); precondition: (*The input for the histogram should never be in a state where a check is needed. No precondition.*); postcondition: (*The new class's gradescale is the inputted gradescale.*) class'.gradescale = gs; end SaveHistogram; function SumOfCountInBin(histogram:Histogram, index:integer) -> integer = if (histogram.bin[index] != nil) then histogram.bin[index].studentcount + SumOfCountInBin(histogram, index + 1) else 0; end histogram;