473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
2 1437
horace1
1,510 Expert 1GB
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
thanks a million for your help. :)
Nov 7 '06 #3

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

Similar topics

6
by: Frankie Montenegro | last post by:
Hi everyone, I need some help with the following C++ code. It is supposed to read input line by line, each line as one string; then split each string into its component words and store these...
7
by: Nalaka | last post by:
Hi, I created a sinple web service that returns a dataSet. Then I created a client program that uses this web service (that returns the Dataset). My question is, how did the client figure...
4
by: Protoman | last post by:
Can you please help me figure out what the error is here, in this rotor cipher simulator, which I wrote to amuse myself? The runtime error is that it isn't symmetrical --decrypting a piece of...
2
by: Steve K. | last post by:
I am in over my head I think, I've got my brain running in circles trying to figure this out. I'm using remoting with a client and a server. I need the server to raise events on the client and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.