help me fix this code?

Mar 3, 2015 at 4:02am
solved :)
Last edited on Mar 5, 2015 at 4:17am
Mar 3, 2015 at 11:37am
Since you commented out line 48 (vtime.h) setHours(...) and the other set... functions don't make sense.

addSeconds is simply reduced to:
1
2
3
4
	void addSeconds(int a_seconds)
	{
		m_time += a_seconds;
	}
Mar 3, 2015 at 7:39pm
thank you i really appreciate that. is that the only thing you see wrong?
Mar 3, 2015 at 7:47pm
I think the setHours() etc. functions still make perfect sense. The point of this assignment is to change the data representation while still having the same interface.

You can do setHours() like this:
1
2
3
4
5
setHours(int a_hours) {
    int m = getMinutes();
    int s = getSeconds();
    m_time = a_hours*3600 + m*60 +s;
}

SetMinutes() and setSeconds() will be similar.

addSeconds is easy: just add the number of seconds to m_time;

operator+ can be coded so it works with either data representation:
1
2
3
4
5
6
time time::operator+(int a_seconds)
{
    time tmp(*this);
    tmp.addSeconds(a_seconds);
    return tmp;
}

Mar 4, 2015 at 10:33pm
dhayden: thank you so much for helping me.
Last edited on Mar 5, 2015 at 4:16am
Topic archived. No new replies allowed.