% CSC148 summer 1997, assignment 1 % % This is a driver program for testing the ElectionResults class. % It creates an instance of the class called ER. % % It asks the user to input of a set of candidates, and % then the voting results, which are added to ER. % Finally it asks ER to output some of the results. % import ElectionResults in "election.tu" var num_ridings : int put "How many ridings?" get num_ridings %------------------------------------------------------------------ % Create and initialize the Election Results object (ER) % First we create a pointer to our object. NOTE: this doesn't create % the object yet, because the pointer doesn't point anywhere. [You % don't have to understand pointers, to see how classes and objects % are used in programs.] var ER : ^ElectionResults % The 'new' command is for creating objects. The following command % creates an instance of ElectionResults, and makes ER point to it. new ER % Now that we have our object, we can initialize it. % We use the '->' notation to access the object's subprograms. % This calls the Init subprogram of the ER object. ER -> Init (num_ridings) % initialize it %------------------------------------------------------------------ % Get candidate names put "Enter candidates , or -1 to finish." loop var riding : int var name, party : string get riding exit when riding < 0 get name, party ER -> RegisterCandidate (riding, name, party) end loop %------------------------------------------------------------------ % Get ballot results put "Now, add some returns: enter , or -1 to finish" loop var riding, nv : int var name : string get riding exit when riding = - 1 get name, nv ER -> AddResults (riding, name, nv) end loop %------------------------------------------------------------------ % Report results put "Enter a party name, or a riding number for results, or -1 to finish" loop var enter : string get enter exit when enter = "-1" if strintok (enter) then put "" put "Riding: ", enter ER -> RidingReport (strint (enter)) else put "" ER -> PartyReport (enter) end if end loop