I am getting an error message when trying to run this program using a Visual C++ 6.0 compiler. The header and code is straight out of the book and I need to understand why I am getting this error message.....maybe I am not compiling correctly? Any help please.?
This is the header file correct?Code:// Fig. 6.18: time3.h // Declaration of class Time. // Member functions defined in time3.cpp // prevent multiple inclusions of header file #ifndef TIME3_H #define TIME3_H class Time { public: Time( int = 0, int = 0, int = 0 ); // default constructor // set functions void setTime( int, int, int ); // set hour, minute, second void setHour( int ); // set hour void setMinute( int ); // set minute void setSecond( int ); // set second // get functions int getHour(); // return hour int getMinute(); // return minute int getSecond(); // return second void printUniversal(); // output universal-time format void printStandard(); // output standard-time format private: int hour; // 0 - 23 (24-hour clock format) int minute; // 0 - 59 int second; // 0 - 59 }; // end clas Time #endif
This is the source code correct?Either way I get the same fatal error that #include “time3.h” is a problem. What am I doing wrong?Code:// Fig. 6.20: fig06_20.cpp // Demonstrating the Time class set and get functions #include <iostream> using std::cout; using std::endl; // include definition of class Time from time3.h #include "time3.h" void incrementMinutes( Time &, const int ); // prototype int main() { Time t; // create Time object // set time using individual set functions t.setHour( 17 ); // set hour to valid value t.setMinute( 34 ); // set minute to valid value t.setSecond( 25 ); // set second to valid value // use get functions to obtain hour, miunute and second cout << "Result of setting all valid values:\n" << " Hour: " << t.getHour() << " Minute: " << t.getMinute() << " Second: " << t.getSecond(); // set time using individual set functions t.setHour( 234 ); // invalid hour set to 0 t.setMinute( 43 ); // set minute to valid value t.setSecond( 6373 ); // invalid second set to 0 // display hour, minute and second after setting // invalid hour and second values cout << "\n\nResult of attempting to set invalid hour and" << " second:\n Hour: " << t.getHour() << " Minute: " << t.getMinute() << " Second: " << t.getSecond() << "\n\n"; t.setTime( 11, 58, 0 ); // set time incrementMinutes( t, 3 ); // increment t's minute by 3 return 0; } // end main // add specified number of minutes to a Time object void incrementMinutes( Time &tt, const int count ) { cout << "Incrementing minute " << count << " times:\nStart time: "; tt.printStandard(); for ( int i = 0; i < count; i++ ) { tt.setMinute( ( tt.getMinute() + 1 ) % 60 ); if ( tt.getMinute() == 0 ) tt.setHour( ( tt.getHour() + 1 ) % 24 ); cout << "\nminute + 1: "; tt.printStandard(); } // end for cout << endl; } // end function incrementMinutes



LinkBack URL
About LinkBacks


