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
2 1437
you missed #endif at the end of the header file -
// 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 // *** missing
-
-
your error message indicated that you did not have a main() function, e.g. -
-
#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() // ** missing :
-
{
-
cout<< setfill( '0' ) << setw(2)<<getHour()<<":"<<setw(2)<<getMinute()<<":"<<setw(2)<<getSecond();
-
-
}
-
-
// ** added a main()
-
int main()
-
{
-
Time t=Time(9,30,25);
-
t.printUniversal();
-
return 0;
-
}
-
thanks a million for your help. :)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
| |