By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,419 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,419 IT Pros & Developers. It's quick & easy.

can some one figure out what is the error message is about in my code

P: 40
hi;

I have this code in my book and when I copied it into my compiler into two files, one is header and the other is .cpp. it gives me an error, I'm sure I copied it right but can't figure out the error.

here is my code:

Time.h
// declaration of class time.
// membar functions defined in Time.cpp

// prevent multiple inclusions of header file

#ifndef TIME_H
#define TIME_H

// Time abstract data type definition

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 ( after validation )
void setMinute ( int ); // set minute ( after validation )
void setSecond ( int ); // set second ( after validation )

// get functions
int getHour(); // return hour
int getMinute(); // return minute
int getSecond(); // return second

void printUniversal();// print time in universal time format


private:

int hour; // 0-23 ( 24 hour clock format )
int minute; // 0-59
int second; // 0-59
}; // end class Time


#endif

------------------------------------------------------------------------------------------------

Time.cpp
#include <iostream>
using std::cout;
#include <iomanip>
using std::setfill;
using std::setw;

#include "Time.h" // include definition from class Time from Time.h

Time::Time( int hr, int min, int sec )

{
setTime( hr, min, sec );

}

void Time::setTime( int h, int m , int s )

{
setHour (h);
setMinute (m);
setSecond (s);
}

void Time::setHour ( int h )
{
hour = ( h >= 0 && h < 24 ) ? h : 0;

}

void Time::setMinute ( int m )
{
minute = ( m >= 0 && m < 60 ) ? m : 0;

}

void Time::setSecond ( int s )
{
second = ( s >= 0 && s < 60 ) ? s : 0;

}

int Time::getHour()
{
return hour;
}

int Time::getMinute()
{
return minute;
}
int Time::getSecond()

{
return second;
}

void Time::printUniversal()

{
cout<< setfill( '0' ) << setw(2)<<getHour()<<":"<<setw(2)<<getMinute()<<":" <<setw(2)<<getSecond();

}

---------------------------------------------------------------------------------------------------------------

the error message:

------ Build started: Project: example2, Configuration: Debug Win32 ------
Linking...
LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\example2\Debug\example2.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\example2\example2\Debug\BuildLog.htm "
example2 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
--------------------------------------------------------------------------------------------------

your fast responce is highly appreciated. thanks in advance for your cooperation.

ayman723
Nov 6 '06 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,510
you missed #endif at the end of the header file
Expand|Select|Wrap|Line Numbers
  1. // declaration of class time.
  2. // membar functions defined in Time.cpp
  3.  
  4. // prevent multiple inclusions of header file
  5.  
  6. #ifndef TIME_H
  7. #define TIME_H
  8.  
  9. // Time abstract data type definition
  10.  
  11. class Time
  12.  
  13. {
  14. public:
  15. Time( int=0, int=0, int=0 ); //default constructor
  16.  
  17. // set functions
  18.  
  19. void setTime ( int,int,int); // set hour, minute, second
  20. void setHour ( int ); // set hour ( after validation )
  21. void setMinute ( int ); // set minute ( after validation )
  22. void setSecond ( int ); // set second ( after validation )
  23.  
  24. // get functions
  25. int getHour(); // return hour
  26. int getMinute(); // return minute
  27. int getSecond(); // return second
  28.  
  29. void printUniversal();// print time in universal time format
  30.  
  31.  
  32. private:
  33.  
  34. int hour; // 0-23 ( 24 hour clock format )
  35. int minute; // 0-59
  36. int second; // 0-59
  37. }; // end class Time
  38.  
  39. #endif   // *** missing  
  40.  
  41.  
your error message indicated that you did not have a main() function, e.g.
Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. using std::cout;
  4.  
  5. #include <iomanip>
  6. using std::setfill;
  7. using std::setw;
  8.  
  9. #include "Time.h" // include definition from class Time from Time.h
  10.  
  11. Time::Time( int hr, int min, int sec )
  12.  
  13. {
  14. setTime( hr, min, sec );
  15.  
  16. }
  17.  
  18. void Time::setTime( int h, int m , int s )
  19.  
  20. {
  21. setHour (h);
  22. setMinute (m);
  23. setSecond (s);
  24. }
  25.  
  26. void Time::setHour ( int h )
  27. {
  28. hour = ( h >= 0 && h < 24 ) ? h : 0;
  29.  
  30. }
  31.  
  32. void Time::setMinute ( int m )
  33. {
  34. minute = ( m >= 0 && m < 60 ) ? m : 0;
  35.  
  36. }
  37.  
  38. void Time::setSecond ( int s )
  39. {
  40. second = ( s >= 0 && s < 60 ) ? s : 0;
  41.  
  42. }
  43.  
  44. int Time::getHour()
  45. {
  46. return hour;
  47. }
  48.  
  49. int Time::getMinute()
  50. {
  51. return minute;
  52. }
  53. int Time::getSecond()
  54.  
  55. {
  56. return second;
  57. }
  58.  
  59. void Time::printUniversal()      // ** missing :
  60. {
  61. cout<< setfill( '0' ) << setw(2)<<getHour()<<":"<<setw(2)<<getMinute()<<":"<<setw(2)<<getSecond();
  62.  
  63. }
  64.  
  65. // ** added a main()
  66. int main()
  67. {
  68.     Time t=Time(9,30,25);
  69.     t.printUniversal();
  70.     return 0;
  71. }
  72.  
Nov 6 '06 #2

P: 40
thanks a million for your help. :)
Nov 7 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.