Sep 27, 2009 at 3:26am Sep 27, 2009 at 3:26am UTC
This time class is driving me crazy...How can I get this program to calculate how long I have to wait in hours, mins and seconds for lunch and dinner using 'diff' ??????
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#include "time.h"
int main()
{
Time begin;
Time end;
Time check_in;
int h, m, s;
begin.set (12,0, 0);
end.set (18, 0, 0);
cout << " enter hour, min, sec\n " ;
cin >>h>>m>>s;
check_in.set (h, m, s);
cout << " the time you checked in " ;
check_in.print ();
if (check_in.Equal(begin))
cout << "You are right on time. Lets go to lunch !! " ;
if ( check_in.LessThan(begin))
cout << " Good Morning you are early. You have to wait for lunch !! " ;
if ( check_in.GreaterThan(begin))
cout << "Good Afternoon you are late. You have to wait for dinner !! " ;
return 0;
}
Last edited on Sep 28, 2009 at 8:12pm Sep 28, 2009 at 8:12pm UTC
Sep 27, 2009 at 5:52am Sep 27, 2009 at 5:52am UTC
What does the Time class look like?
Sep 27, 2009 at 5:57am Sep 27, 2009 at 5:57am UTC
Just noticed that you have also posted same question in a another forum.
Sep 27, 2009 at 2:31pm Sep 27, 2009 at 2:31pm UTC
Well here is the rest of the program that I previous omitted...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
#include <iostream> // Time.h
using namespace std;
class Time // DECLARATION
{
public :
void set(int h, int m, int s);
void print ();
void increment();
int get_hour();
int get_mins();
int get_secs();
bool Equal(Time t);
bool LessThan(Time t);
bool GreaterThan(Time t);
private : // The private variables hrs, mins, and secs can be accessed only by the member functions Set, Increment, Write, Equal, and LessThan, not by client code.
int hour;
int mins; // MEMBERS VARIABLES OF TIME
int secs;
};
#include "time.h"
void Time::set(int h, int m, int s)
{
hour = h;
mins = m;
secs = s;
}
void Time::increment()
{
secs ++;
if (secs == 60)
{ mins ++;
secs = 0;
if ( mins == 60)
{ hour ++;
mins = 0;
}
if ( hour == 24)
hour = 0;
}
}
void Time::print()
{
if (hour < 10) cout << '0' ;
cout << hour << ":" ;
if (mins < 10) cout << '0' ;
cout << mins << ":" ;
if (secs < 10) cout << '0' ;
cout << secs << endl;
}
int Time::get_hour()
{ return hour;
}
int Time::get_mins()
{ return mins;
}
int Time::get_secs()
{ return secs;
}
bool Time::Equal(Time t)
{
if ( hour == t.hour && mins == t.mins && secs == t.secs)
return true ;
else
return false ;
}
bool Time::LessThan(Time t)
{
if (hour < t.hour || hour == t.hour && mins < t.mins || hour == t.hour && mins == t.mins && secs < t.secs)
return true ;
else
return false ;
}
bool Time::GreaterThan(Time t)
{
if (hour > t.hour || hour == t.hour && mins > t.mins || hour == t.hour && mins == t.mins && secs > t.secs)
return true ;
else
return false ;
}
Last edited on Sep 28, 2009 at 8:13pm Sep 28, 2009 at 8:13pm UTC