// // Program name: timesheets // // Author: I.N. Late // // Purpose: Compute hours worked from timesheets // // Input: // name of input file containing timesheet data -- each line // contains an employee SSN (string), and starting and // stopping times, in military time // name of output file // (names obtained from user) // Output: // output file containing, for each line in the input file, // the employee's SSN, plus hours, minutes, and seconds worked // #include #include // has ifstream, ofstream #include // has setw() const int MaxFileNameLength = 1000; // maximum length of filename // ******** function prototypes ******** // I think there's something missing here! // -- G.H. Now // // function to read in a time // // precondition: // inStr has been successfully opened // postcondition: // if it is possible to read from inStr a time, in the format // HH:MM:SS, return value is true, and hh, mm, ss contain // HH, MM, and SS respectively // otherwise return value is false // bool readTime(ifstream& inStr, int& hh, int& mm, int& ss); // // function to read in an integer and check its value // // precondition: // inStr has been successfully opened // postcondition: // if it is possible to read from inStr an integer, and the // integer is >= min and <= max, return value is true, // and result contains the integer // otherwise return value is false // bool readIntInRange(ifstream& inStr, int& result, const int min, const int max); // ******** main program ******** int main() { ifstream inStream; ofstream outStream; const int MAXNAMELENGTH = 100; char employeeSSN[MAXNAMELENGTH]; int beginH, beginM, beginS; int endH, endM, endS; int resultH, resultM, resultS; int beginTime, endTime, secondsOfWork; // I think there's something missing here! // -- G.H. Now while (readName(inStream, employeeSSN, MAXNAMELENGTH) && readTime(inStream, beginH, beginM, beginS) && readTime(inStream, endH, endM, endS)) { beginTime = timeToSeconds(beginH, beginM, beginS); endTime = timeToSeconds(endH, endM, endS); secondsOfWork = endTime - beginTime; secondsToTime(secondsOfWork, resultH, resultM, resultS); printResults(outStream, employeeSSN, resultH, resultM, resultS); } // I think there's something missing here! // -- G.H. Now return 0; } // ******** function definitions ******** bool readTime(ifstream& inStr, int& hh, int& mm, int& ss) { char tempC; if (!readIntInRange(inStr, hh, 0, 23)) return false; else if (!(inStr >> tempC) || tempC != ':') return false; else if (!readIntInRange(inStr, mm, 0, 59)) return false; else if (!(inStr >> tempC) || tempC != ':') return false; else if (!readIntInRange(inStr, ss, 0, 59)) return false; else return true; } bool readIntInRange(ifstream& inStr, int& result, const int min, const int max) { // ">> dec" is needed because some systems otherwise think // that an integer starting with 0 is octal return ((inStr >> dec >> result) && result >= min && result <= max); } // I think there's something missing here! // -- G.H. Now