Hi guys, I've been working on this for a few hours and I'm getting really exhausted and annoyed. My goal is have the user insert the time. I don't know how to manipulate the time.h functions yet so I'm having the time inserted manually. From there I have the time shown to the user then have it incremented by 1 hour. Then output another line with only 1 minute incremented.
From there I just set the timezone in my code and output that via a variable as you can see, then just tell the user the current time zone is +8. I also re-output the time.
I am having trouble accessing the private members of my Time class in my main function. As far as I know I've down everything the way it should be done but its just not working for me.
Any help would really be accepted. Also I know my coding is sloppy and most likely incorrent but I'm learning its its only my 4th week.
So any input on coding styles is a bonus ;)
thx
#include "stdafx.h"
#include <iostream></P> <P>using namespace std;</P> <P>class Time
{
private:
int hour;
int minute;
int zero;
public:
void setTime(int,int,int);
void returnZero();
int returnTime();
void printTime();
void incrementHour();
void incrementMinute();
};
class extTime: public Time
{
int time_zone;
public:
void setTimezone(int);
int getTimezone();
void printTimezone();
};
void Time::setTime(int hr, int min, int z)
{
hour = hr;
minute = min;
zero = z;
}
int Time::returnTime()
{
return hour;
return minute;
return zero;
}
void Time::printTime()
{
do
{
cout << "Hour: ";
cin >> hour;
}
while(hour > 12);
do
{
cout << "Minute: ";
cin >> minute;
}
while(minute > 59);
cout << hour << ":" << &Time::returnZero << minute << endl << endl;
}
void Time::incrementHour()
{
cout << "Incremented by 1 hour" << endl;
if(hour == 12)
{
hour = 0;
hour++;
cout << hour;
}
else
{
hour++;
cout << hour;
}
}
void Time::incrementMinute()
{
cout << "Incremented by 1 minute" << endl;
if(minute == 59 && hour == 12)
{
hour = 12;
minute = 00;
cout << hour << ":" << minute << endl << endl;
}
else
if(minute < 59)
{
minute++;
cout << minute;
}
}
void Time::returnZero()
{
if(minute > 10)
cout << "";
else
{
cout << 0;
}
}
void extTime::setTimezone(int ext)
{
time_zone = ext;
ext = 8;
}
int extTime::getTimezone()
{
return time_zone;
}
void extTime::printTimezone()
{
cout << "The time was stated as " << &Time::printTime << " and..." << endl;
cout << "The current time zone is +" << &extTime::getTimezone << "GMT" << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
system("Title Week 3 Lab");
Time time;
extTime time_zone;
cout << "Enter the time in HH:MM format **12H format**" << endl;
time.printTime();
cout << time.incrementHour << ":" << time.minute << endl << endl;
cout << time.hour << ":" << time.incrementMinute;
time_zone.printTimezone();
system("pause");
return 0;
}
Question
saiya
Hi guys, I've been working on this for a few hours and I'm getting really exhausted and annoyed. My goal is have the user insert the time. I don't know how to manipulate the time.h functions yet so I'm having the time inserted manually. From there I have the time shown to the user then have it incremented by 1 hour. Then output another line with only 1 minute incremented.
From there I just set the timezone in my code and output that via a variable as you can see, then just tell the user the current time zone is +8. I also re-output the time.
I am having trouble accessing the private members of my Time class in my main function. As far as I know I've down everything the way it should be done but its just not working for me.
Any help would really be accepted. Also I know my coding is sloppy and most likely incorrent but I'm learning its its only my 4th week.
So any input on coding styles is a bonus ;)
thx
#include "stdafx.h" #include <iostream></P> <P>using namespace std;</P> <P>class Time { private: int hour; int minute; int zero; public: void setTime(int,int,int); void returnZero(); int returnTime(); void printTime(); void incrementHour(); void incrementMinute(); }; class extTime: public Time { int time_zone; public: void setTimezone(int); int getTimezone(); void printTimezone(); }; void Time::setTime(int hr, int min, int z) { hour = hr; minute = min; zero = z; } int Time::returnTime() { return hour; return minute; return zero; } void Time::printTime() { do { cout << "Hour: "; cin >> hour; } while(hour > 12); do { cout << "Minute: "; cin >> minute; } while(minute > 59); cout << hour << ":" << &Time::returnZero << minute << endl << endl; } void Time::incrementHour() { cout << "Incremented by 1 hour" << endl; if(hour == 12) { hour = 0; hour++; cout << hour; } else { hour++; cout << hour; } } void Time::incrementMinute() { cout << "Incremented by 1 minute" << endl; if(minute == 59 && hour == 12) { hour = 12; minute = 00; cout << hour << ":" << minute << endl << endl; } else if(minute < 59) { minute++; cout << minute; } } void Time::returnZero() { if(minute > 10) cout << ""; else { cout << 0; } } void extTime::setTimezone(int ext) { time_zone = ext; ext = 8; } int extTime::getTimezone() { return time_zone; } void extTime::printTimezone() { cout << "The time was stated as " << &Time::printTime << " and..." << endl; cout << "The current time zone is +" << &extTime::getTimezone << "GMT" << endl; } int _tmain(int argc, _TCHAR* argv[]) { system("Title Week 3 Lab"); Time time; extTime time_zone; cout << "Enter the time in HH:MM format **12H format**" << endl; time.printTime(); cout << time.incrementHour << ":" << time.minute << endl << endl; cout << time.hour << ":" << time.incrementMinute; time_zone.printTimezone(); system("pause"); return 0; }Link to comment
Share on other sites
3 answers to this question
Recommended Posts