< previous page page_733 next page >

Page 733
const int NUM_PRECINCTS = 4;
const int NUM_CANDIDATES = 4;

typedef char String10[11];        // Room for 10 characters plus \0
typedef int VoteTable[NUM_PRECINCTS][NUM_CANDIDATES];
                                  // 2-dimensional array type
                                  //   for votes
void GetNames( String10[] );
void OpenForInput( ifstream& );
void OpenForOutput( ofstream& );
void WritePerCandidate( const VoteTable, const String10[],
                        ofstream& );
void WritePerPrecinct( const VoteTable, ofstream& );
void WriteTable( const VoteTable, const String10[], ofstream& );
void ZeroVotes( VoteTable );

int main()
{
     VoteTable votes;         // Totals for precincts vs. candidates

     String10  name[NUM_CANDIDATES];  // Array of candidate names

     int       candidate;     // Candidate number input from voteFile
     int       precinct;      // Precinct number input from voteFile
     ifstream  voteFile;      // Input file of precincts, candidates
     ofstream  reportFile;    // Output file receiving summaries

     OpenForInput(voteFile);
     if ( !voteFile )
         return 1;
     OpenForOutput(reportFile);
     if ( !reportFile )
         return 1;

     GetNames(name);
     ZeroVotes(votes);

     // Read and tally votes

     voteFile >> precinct >> candidate;
     while (voteFile)
     {
             // Invariant (prior to test):
             //     For each pair (precinct, candidate) of input
             //     values prior to the current pair,
             //     votes[precinct-1][candidate-1] has been
             //     incremented by 1

 
< previous page page_733 next page >