Possible Duplicate:
Operator overloading
"You are required to implement a class, called Duration, that represents a length of time, expressed in hours, minutes and seconds, for example the length of a track on a CD, or the time taken to run a marathon. The class should have an appropriate set of constructors (including error checking) and accessor methods. One of the constructors should permit the initialization of a Duration object using a single integer, representing the duration in seconds. The << and >> operators should be overloaded to allow the input and output of Duration objects via streams. A Duration object should be output in the format \h:mm:ss", for example \1:39:33", \0:09:07" and \1:00:08". Also the addition operator, +, should be overloaded so that two Duration objects can be added together to produce a new Duration object, and so that an integer number of seconds can be added to a Duration object. Lastly, the class should dene a type conversion from a Duration object to an integer representing the duration in seconds."
#include <iostream>
#include <stdlib.h>
using namespace std;
using std::cout;
using std::cin;
using std::ostream;
using std::istream;
class Duration
{
private:
int hours, minutes, seconds;
int theSeconds;
public:
Duration() //default constructor.
{}
Duration(int hr, int min, int sec) //ordinary constructor.
{
hours = hr;
minutes = min;
seconds = sec;
}
inline int getHours()
{
return hours;
}
inline int getMinutes()
{
return minutes;
}
inline int getSeconds()
{
return seconds;
}
};
Hopefully i have gone in the right direction with this task so far(new this week to c++). However i am struggling with how to implement the part i have highlighted in bold and everything after that...
Please advise and help me. Also please note, this is NOT coursework etc. I'm just trying to prepare myself with c++ for next year. Thank you.