|
|
|
|
|
|
|
Write Totals Per Candidate (In: votes, name; Inout: reportFile) |
|
|
|
|
|
|
|
|
FOR each candidate
Set total = 0
// Compute column sum
FOR each precinct
Add votes[precinct][candidate] to total
Write Total votes for, name[candidate], total to reportFile |
|
|
|
|
|
|
|
|
|
Write Totals Per Precinct (In: votes; Inout: reportFile) |
|
|
|
|
|
|
|
|
|
FOR each precinct
Set total = 0
// Compute row sum
FOR each candidate
Add votes[precinct][candidate] to total
Write Total votes for precinct, precinct, :, total to reportFile |
|
|
|
|
|
|
|
|
|
|
The program for this algorithm follows. |
|
|
|
|
|
|
|
|
//******************************************************************
// Election program
// This program reads votes represented by precinct number and
// ballot position from a data file, calculates the sums per
// precinct and per candidate, and writes all totals to an
// output file
//******************************************************************
#include <iostream.h>
#include <iomanip.h> // For setw()
#include <fstream.h> // For file I/O
|
|
|
|
|
|