I'm trying to create a program using nothing but classes as a homework assignment. (yes another help me on my homework post)
so far i've pulled this sample code off the web:
1 2 3 4 5 6 7 8
struct tm *ptr;
time_t ltime;
char str[80];
ltime = time(NULL); /* get current calendar time */
ptr = localtime(<ime); // return time in the form of tm structure
strftime(str,80,"It is now %H:%M %p.",ptr);
printf("%s\n",str);
class Time
{
int hour, minute;
public:
//Getters
int GetHour() {return hour;}
int GetMinute() {return minute;}
//Setters
void SetHour(int nhour)
{
// code i was working with previously... do loop N/A
hour = nhour;
do{
cout << "Hour is: ";
cin >> nhour;
}while(nhour > 12);
}
void SetMinute(int nminute)
{
// code i was working with previously... do loop N/A
minute = nminute;
do{
cout << "Minute is: ";
cin >> nminute;
}while(nminute > 59);
}
//Printers
void PrintTime();
};
int main()
{
Time timel;
return 0;
}
I'm stuck at the part where i would want to reference the time into variables held by my class. Or perhaps have the time struct in my class somewhere and use my CLASS to access the time.
eventually my goal here is to do hour++ and minute++ when I can successfully get the time extracted into the variables hour, minute