Conversion Constructor

I was trying to create this class...and I am required to create constructors using conversion constructor. Am I on the right path? I am getting the results, but ai m not sure if this is the reight way to do it? any suggestions...

Thanks

=======================

//classTime.h

//#include "stdafx.h"
#include <iostream>

#ifndef CLASSTIME_H
#define CLASSTIME_H

using namespace std;

class classTime
{
public:
      //Print variables
      void print() const;
      
      //Default constructor: set all the instance variables to zero
      classTime();

      //Conversion constructor: assign the arguments to the instance variables
      //Use construction list operator
      classTime(int, int, int);

      //Conversion constructor: extract the hours minutes and seconds from
      //timeSeconds and assign them to the respective instance variables
      classTime(int timeSeconds);      // timeSeconds_ < seconds24Hours

      //Conversion constructor: parse the hours minutes and seconds from
      //“hh:mm:ss” and assign them to the respective instance variables.
      classTime(const char *time);      // literal string constant "hh:mm:ss"

private:
      int hr;
      int min;
      int sec;      
};

#endif

=======================

//classTime.cpp

//#include "stdafx.h"
#include <iostream>
#include "classTime.h"

using namespace std;
//Print Variables
void classTime::print() const
{
      cout << "Hr = " << hr << endl;
      cout << "Min = " << min << endl;
      cout << "Sec = " << sec << endl;
}

//Default constructor: set all the instance variables to zero
classTime::classTime()
{
      hr   = 0;
      min  = 0;
      sec  = 0;
}

//Conversion constructor: assign the arguments to the instance variables
//Use construction list operator
classTime::classTime(int hour, int minute, int second)
{
      hr  = hour;
      min = minute;
      sec = second;
}

//Conversion constructor: extract the hours minutes and seconds from
//timeSeconds and assign them to the respective instance variables
classTime::classTime(int timeSeconds)
{
      hr  = ((timeSeconds / 60) / 60);
      min = (timeSeconds / 60) - ((timeSeconds/60)/60) * 60;
      sec = timeSeconds - ((hr * 60 * 60) + (min * 60));
}

classTime::classTime(char *time)
{

}

=======================

TestDriver.cpp

// INCLUDES
//#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdlib>      
//#include "windows.h"

#include "classTime.h"

using namespace std;

// MACROS
#define skip1   cout << endl
#define skip2   cout << endl << endl
#define skip3   cout << endl << endl << endl

int main()
{
      cout << "\nBegin main()\n\n";
      
      //Testing the default constructor
      classTime one;
      one.print();
      skip2;

      //Testing the Conversion constructor
      classTime two(2,6,8);
      two.print();
      skip2;

      classTime three(559);
      three.print();
      skip2;

      cout << endl
         << "\nEnd - Normal Termination\n"
         << endl;
      return 0;
} // main

=======================
KalluMamaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jaime OlivaresSoftware ArchitectCommented:
Conversion constructors are constructors that use argument of a different data type. So, basically you are right.
There are typical C datatypes for file manipulations like time_t (well known as Unix time) and struct tm. So you can prepare constructors for these types.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
efnCommented:
I think you are on the right track.

Technically, the constructor with three parameters is not a conversion constructor.  A conversion constructor has only one parameter.

It would be a minor improvement to use initialization lists, e.g.:

classTime::classTime(int hour, int minute, int second)
: hr(hour), min(minute), sec(second)
{}

--efn
0
Jaime OlivaresSoftware ArchitectCommented:
In case mentioned by efn, you must use a structure containing all the arguments, this case is ideal to use 'struct tm' datatype.
Here is an explanation about it:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_asctime.2c_._wasctime.asp

So you can implement:
    classTime::classTime(struct tm)
0
AxterCommented:
FYI:
I recommend you avoid using macros as much as possible.
This is especially so, if you're just learning.  You don't want to pick bad habbits.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.