< previous page page_734 next page >

Page 734
         votes[precinct-1][candidate-1]++;
         voteFile >> precinct >> candidate;
     }

     // Write results to report file

     WriteTable(votes, name, reportFile);
     WritePerCandidate(votes, name, reportFile);
     WritePerPrecinct(votes, reportFile);

     return 0;
}

//******************************************************************

void OpenForInput( /* inout */ ifstream& someFile )    // File to be
                                                       // opened
// Prompts the user for the name of an input file
// and attempts to open the file

// Postcondition:
//     The user has been prompted for a file name
//  && IF the file could not be opened
//         An error message has been printed
// Note:
//     Upon return from this function, the caller must test
//     the stream state to see if the file was successfully opened

{
     char fileName[51];   // User-specified file name (max. 50 chars)

     cout << Input file name: ;
     cin.get(fileName, 51);
     cin.ignore(100, \n);

     someFile.open(fileName);
     if ( !someFile )
         cout << ** Can't open  << fileName <<  ** << endl;
}

//******************************************************************

void OpenForOutput( /* inout */ ofstream& someFile )   // File to be
                                                       // opened
// Prompts the user for the name of an output file
// and attempts to open the file

 
< previous page page_734 next page >