// For CS 350, Spring 2006 v. 2/15/06 // Illustrates: // 1. efficient runtime implementation // 2. order(1) memory implementation // 3. handling eof for several files #include #include using namespace std; int main( int argc, char *argv[] ) { int numFiles = argc-1; int matchCt[ numFiles ]; int mismatchCt[ numFiles ]; fstream infile[ numFiles ]; int eof[ numFiles ]; double nextVal, gold; // note that no more than 2 values from files are needed at a time int BadFileNameCt = 0; int sumEOFs; // Init vars, check for existence of input files for ( int i=0; i 0 ) { cerr << "program terminated." << endl; return 1; } // if } // for // Process data in all files while ( sumEOFs < numFiles ) { // Keep going until eof on all files infile[0] >> gold; if ( infile[0].fail() ) { eof[0] = 1; gold = -9999999999.99; // need a better solution! } // if for ( int i=1; i> nextVal; if ( !infile[i].fail() && !infile[0].fail() ) // successfully read values from gold & file i if ( fabs( nextVal-gold ) < 0.001 ) // precision decision should be function call matchCt[i]++; else { mismatchCt[i]++; // really need more code here to display mismatch values. // One way is to build an output string, add to it with // each comparison (add blanks for matches, mismatcheed number // for mismatches) and only print if there are mismatches. } // else if ( infile[0].fail() && !infile[i].fail() ) // gold is short mismatchCt[i]++; if ( !infile[0].fail() && infile[i].fail() ) // file i is short mismatchCt[i]++; if ( infile[i].fail() ) eof[i] = 1; } // for i // count the number of EOFs sumEOFs = 0; for ( int i=0; i