% CSC148 summer 1997, assignment 1 % % The ElectionResults class maintains the results of an election. % It can rank the candidates in each riding (RidingReport), and % report the statistics for each (PartyReport). % %======================================================================= unit class ElectionResults % Only these subprograms can be used outside of this class. % Everything else defined in this class is hidden from the outside. % export Init, RegisterCandidate, AddResults, RidingReport, PartyReport % DEFINE THE DATA STRUCTURE AND LOCAL VARIABLES HERE % ----------------- private subprograms ---------------------------- % ( can only be used within this class ) % Print a line of information about a candidate % !!!! DO NOT CHANGE THIS SUBPROGRAM % proc PrintCandLine (name : string, party : string, votes : int, percentage : real) put name : 10, " (", party : 10, ") ", votes : 4, " ", percentage : 5 : 1, "%" end PrintCandLine % Print a line of information about a party % !!!! DO NOT CHANGE THIS SUBPROGRAM % proc PrintPartyLine (party : string, wins : int, popular : real) put party : 10, " ", wins : 4, " ", popular : 5 : 1, "%" end PrintPartyLine % IF YOU NEED MORE SUBPROGRAMS, PUT THEM HERE % ----------------- public subprograms ---------------------------- % ( these are exported (above), so any program can call them ) % Initialize the election results data % proc Init (total_ridings : int) % YOUR CODE HERE end Init % Add a new candidate to the specified riding % proc RegisterCandidate (riding_n : int, name : string, party : string) % YOUR CODE HERE end RegisterCandidate % Add new voting results for a specified candidate and riding % proc AddResults (riding_n : int, name : string, votes : int) % YOUR CODE HERE end AddResults % Display a report about a specified riding, sorted by % number of votes received % proc RidingReport (riding_n : int) % YOUR CODE HERE end RidingReport % Display a report about a party % proc PartyReport (party : string) % YOUR CODE HERE end PartyReport end ElectionResults