C++ URGENT HELP

Status
Not open for further replies.
Need Halp,


In class doing a C++ midterm RIGHT NOW. I haven't shown up for the entire semester so i don't exactly know what's going on. I will be forever in this forum's debt if they do this for me. i will do anything. anything.


Write a class called Time. Time has the public functions addSeconds, addMinutes addHours, seconds, minutes, hours, show, and showAmPm. Time has the private member variables seconds, minutes and hours. Seconds, minutes and hours run on a 24-hour clock; which means after 24-hours the time goes back to zero. Time also overloads the operators +,- and <. At least one operator must be overloaded as a friend function. The class must have constructors that allow initialization with just seconds, or with seconds, minutes, and hours.


The functions do the following
1. addSeconds – accepts an integer and adds it to the seconds variable.
2. addMinutes – accepts an integer and adds it to the minutes variable.
3. addHours – accepts an integer and adds it to the hours variable.
4. seconds – accepts no parameters and returns seconds.
5. minutes – accepts no parameters and returns minutes.
6. hours – accepts no parameters and returns hours.
7. show – displays the seconds, minutes and hours variables in a format consistent with a 24-hour clock.
8. showAmPm – displays the seconds, minutes and hours variables in a format consistent with a 12-hour clock and whether the time is AM or PM
9. + accepts two Time objects and adds their seconds, minutes and hours variables and returns a Time object by overloading the + operator
10. - accepts two Time objects and subtracts their seconds, minutes and hours variables and returns a Time object by overloading the + operator
11. < compares two Time objects to determine which is earlier in a 24 hour day by overloading the < operator

Sorry but we don't do homework for people. If you have a specific question, we can help you, but we're not going to write an entire program for you. I'd say the part in bold from your quote is the problem... you dug yourself in a hole; time to dig yourself out.

Like I said, if you have a specific question, you can ask it and we'll help you with that.
 
ok, fair enough.

can you just explain to me what

template <class T> T mystery 2(T a, T b) {
return a>b ? a : b;
}

does?
 
I still wouldn't help him.. I just got out of a C++ mid term. If you had shown up you'd understand what's going on ;)
 
ok, fair enough.

can you just explain to me what

template <class T> T mystery 2(T a, T b) {
return a>b ? a : b;
}

does?

T is a generic type. Look into Templates for more info: Templates - C++ Documentation

"mystery" is the function that would be called, where T is the data type of the return, as well as the parameters "a" and "b". E.g., T could be an int, double, char, etc.

The "a > b ? a : b" part is shorthand for an if statement (really hate this notation... horribly unreadable). It can be expanded to:

Code:
if (a > b)
{
    return a;
}
else
{
    return b;
}
 
Status
Not open for further replies.
Back
Top Bottom