//****************************************************************** // Temperatures program // This program inputs one month's temperature readings from a file, // deletes spurious readings of 200 degrees from a faulty sensor, // and outputs the values in sorted order //****************************************************************** #include // For file I/O #include "list.h" // For List class using namespace std; int main() { List temps; // List of temperature readings int oneTemp; // One temperature reading ifstream inData; // File of temperature readings int limit; // The number of readings ofstream outData; // Output file inData.open("temps.dat"); if ( !inData ) { outData << "Can't open file temps.dat" << endl; return 1; } outData.open("temps.ans"); // Get temperature readings from file inData >> oneTemp; while (inData && !temps.IsFull()) { temps.Insert(oneTemp); inData >> oneTemp; } // Output original list temps.Reset(); // Set up for an iteration limit = temps.Length(); // Get number of items outData << "No. of readings: " << limit << endl; outData << "Original list:" << endl; for (int count = 0; count < limit; count++) { oneTemp = temps.GetNextItem(); outData << oneTemp << endl; } // Discard spurious readings of 200 degrees while ( !temps.IsEmpty() && temps.IsPresent(200)) temps.Delete(200); temps.SelSort(); // Sort list // Output sorted list temps.Reset(); // Set up for an iteration limit = temps.Length(); // Get number of items outData << "No. of valid readings: " << limit << endl; outData << "Sorted list:" << endl; for (int count = 0; count < limit; count++) { oneTemp = temps.GetNextItem(); outData << oneTemp << endl; } inData.close(); outData.close(); return 0; }