this is a beginning c++ course. deitel vsn. 4 it came with the visual c++ compilerOriginally Posted by nbk
this is a beginning c++ course. deitel vsn. 4 it came with the visual c++ compilerOriginally Posted by nbk
grr i know why :P
try including test.h and not time3.h
and nbk when you create a project with vc++ the directory you put it in is searched as well as the include directory
Woop?
Duh, that makes sense....its pointing to the file. Well bad news I got these 10 errors.Originally Posted by prog-bman
Linking...
test.obj : error LNK2001: unresolved external symbol "public: void __thiscall Time::setTime(int,int,int)" (?setTime@Time@@QAEXHHH@Z)
test.obj : error LNK2001: unresolved external symbol "public: int __thiscall Time::getHour(void)" (?getHour@Time@@QAEHXZ)
test.obj : error LNK2001: unresolved external symbol "public: int __thiscall Time::getMinute(void)" (?getMinute@Time@@QAEHXZ)
test.obj : error LNK2001: unresolved external symbol "public: int __thiscall Time::getSecond(void)" (?getSecond@Time@@QAEHXZ)
test.obj : error LNK2001: unresolved external symbol "public: void __thiscall Time::setSecond(int)" (?setSecond@Time@@QAEXH@Z)
test.obj : error LNK2001: unresolved external symbol "public: void __thiscall Time::setMinute(int)" (?setMinute@Time@@QAEXH@Z)
test.obj : error LNK2001: unresolved external symbol "public: void __thiscall Time::setHour(int)" (?setHour@Time@@QAEXH@Z)
test.obj : error LNK2001: unresolved external symbol "public: __thiscall Time::Time(int,int,int)" (??0Time@@QAE@HHH@Z)
test.obj : error LNK2001: unresolved external symbol "public: void __thiscall Time:rintStandard(void)" (?printStandard@Time@@QAEXXZ)
Debug/test.exe : fatal error LNK1120: 9 unresolved externals
Error executing link.exe.
test.exe - 10 error(s), 0 warning(s)
there are the errors i got basically that means you are calling a function that hasn't been defined yet
Woop?
ok I think I got it. thanks alotOriginally Posted by prog-bman
Ok I figured it out and got it to work. Now I have to change this code in the header to include a tick memeber function that increments the time stored in the time object by one second any suggestions? By what I am looking at.....it looks like it should do it already. but I think in my cpp part it is only changing it by minutes? Am I right?Originally Posted by daisy244Code: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
These are just prototypes can you show me the definitions?
Woop?
With the header file already stored in its directory: I put this in the cpp source file built it and it gave me the output I was searching for:Originally Posted by prog-bman
Code:// Fig. 6.19: time3.cpp // Member-function definitions for Time class. #include <iostream> using std::cout; #include <iomanip> using std::setfill; using std::setw; // include definition of class Time from time3.h #include "time3.h" // constructor function to initialize private data; // calls member function setTime to set variables; // default values are 0 (see class definition) Time::Time( int hr, int min, int sec ) { setTime( hr, min, sec ); } // end Time constructor // set hour, minute and second values void Time::setTime( int h, int m, int s ) { setHour( h ); setMinute( m ); setSecond( s ); } // end function setTime // set hour value void Time::setHour( int h ) { hour = ( h >= 0 && h < 24 ) ? h : 0; } // end function setHour // set minute value void Time::setMinute( int m ) { minute = ( m >= 0 && m < 60 ) ? m : 0; } // end function setMinute // set second value void Time::setSecond( int s ) { second = ( s >= 0 && s < 60 ) ? s : 0; } // end function setSecond // return hour value int Time::getHour() { return hour; } // end function getHour // return minute value int Time::getMinute() { return minute; } // end function getMinute // return second value int Time::getSecond() { return second; } // end function getSecond // print Time in universal format void Time::printUniversal() { cout << setfill( '0' ) << setw( 2 ) << hour << ":" << setw( 2 ) << minute << ":" << setw( 2 ) << second; } // end function printUniversal // print Time in standard format void Time::printStandard() { cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 ) << ":" << setfill( '0' ) << setw( 2 ) << minute << ":" << setw( 2 ) << second << ( hour < 12 ? " AM" : " PM" ); } // end function printStandard // 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
Yep i just kept seeing declarations and no definations that looks good to me
Woop?
what do you mean by definitions?Originally Posted by prog-bman
A definition is where you define the function(correct?)
e.g.
Code:int main() // Define main() { // Still... int var; // :o { // yay int main(); //declare main(which you never do :), unless the compiler requires it)
Last edited by nbk; 07-29-2004 at 09:50 PM.
Declarations and prototype are when you just have the functions name, return type, and parameters, but no code for the functions. It's like declaring a variable (int x) but not defining it yet (x = 5). Show the code to your functions.
edit: nbk is basically correct, but I wouldn't recommend looking at that code.
This program is referencing this header file:Originally Posted by sean_mackroryNotice that it says Member functions defined in time3.cppCode: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
Ive got to change time.h to increment with a tick command to make the output increment in seconds.
Are you through with helping me? Let me know?Originally Posted by daisy244