I have a project that implements my own created header file and my own class. They are simple and just check whether time is correct on a 24 hour clock. the get methods should be inline and the rest are non inline. I am having problems with the get methods in my main file. I believe it should return the value entered but it does not. the set methods seem to be working correctly. they return a bool value if the given integers for minutes and hours are correct . I am just wondering if my get methods are correct or is there another error.
my header file.
CODE
class MyTime
{
int myMinute, myHour;
public:
int getHour()
{
return myHour;
}
int GetMinute()
{
return myMinute;
}
bool setHour(int);
bool setMinute(int);
bool setTime(int, int);
};
my implementation file
CODE
#include "MyTime.h"
#include <iostream>
using namespace std;
bool MyTime::setHour(int hr)
{
if((hr >= 0) && (hr<=24))
{
if(hr ==24)
myHour = 0;
hr = myHour;
return true;
}
else
{
myHour = 0;
return false;
}
}
bool MyTime::setMinute(int min)
{
if((min >=0) && (min <=59))
{
min = myMinute;
return true;
}
else
{
myMinute = 0;
return false;
}
}
bool MyTime::setTime(int min,int hr)
{
if(((min >=0) && (min <=59)) && ((hr >= 0) && (hr<=24)))
{
if(hr ==24)
myHour = 0;
min = myMinute;
hr = myHour;
return true;
}
else
{
myMinute = 0;
myHour = 0;
return false;
}
}
my main file
CODE
#include <iostream>
#include "MyTime.h"
using namespace std;
void main ()
{
bool mins, hrs, time;
int xm, xh;
MyTime T;
cout<<"Enter hour "<<endl;
cin>>xh;
cout<<endl<<"Enter minute "<<endl;
cin>>xm;
mins = T.setMinute(xm);
hrs = T.setHour(xh);
time =T.setTime(xm,xh);
cout<<endl<<" Hour "<< hrs << " Mins " << mins <<endl;
cout<<" Time " << time <<endl;
}
This post has been edited by ghettoMan: 4 Oct, 2008 - 09:09 AM