(*The PieChart object models the piechart functionality of grade scaling*) module PieChart; from GradeTable import all; from histogram import all; from class import all; export all; object GradeScale is components: piechart:PieChart, histogram:Histogram, gradetable:GradeTable; end GradeScale; object PieChart is components: piesector:PieSector*; end PieChart; object PieSector is components: Color, lettergrade:string, percentage:integer; end PieSector; object Color is components: Red:integer, Green:integer, Blue:integer; end Color; operation ModifyPieChart is inputs: gs:GradeScale, class:Class; outputs: gs':GradeScale; precondition: (*The PieChart should never be in a state where input has be checked. No precondition.*); postcondition: (*The new gradescale's data matches that of the modified piechart.*) (SumOfPercentageInSector(gs'.piechart, 1) = 100) and (forall (i:integer | i >= 1 and (i < #(gs'.piechart.piesector))) (gs'.piechart.piesector[i].lettergrade = gs'.histogram.histogramsector[i].lettergrade) and (gs'.piechart.piesector[i].percentage = (gs'.histogram.histogramsector[i].studentcount / #(class.studs) * 100)) and (gs'.piechart.piesector[i].lettergrade = gs'.gradetable.rga[i].lettergrade) and (gs'.piechart.piesector[i].percentage = gs'.gradetable.rga[i].percentage) ); description: (*Modifies the displayed piechart, histogram, gradetable and the gradescale given the modified piechart.*); end ModifyPieChart; operation SavePieChart is inputs: gs:GradeScale, class:Class; outputs: class':Class; description: (*Saves the modified gradescale given the modified piechart.*); precondition: (*The input of GradeScale 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 SavePieChart; operation CreatePieChart is inputs: gradescale:GradeScale; outputs: piechart':PieChart; description: (*Creates the piechart from gradescale when the gradescale functionality is first called*); precondition: (*The input of GradeScale should never be in a state where a check is needed. No precondition.*); postcondition: (*The created piechart is the piechart in gradescale*) piechart' = gradescale.piechart; end CreatePieChart; function SumOfPercentageInSector(piechart:PieChart, index:integer) -> integer = (if (piechart.piesector[index] != nil) then piechart.piesector[index].percentage + SumOfPercentageInSector(piechart, index + 1) else 0); end PieChart;