![]() |
|
#1
|
|||
|
|||
constructors/classesi've been working on designing and implementing a class that represents an amount of time in minutes and seconds. i'm supposed to use constructors that sets the time to a specified number of minutes and seconds. the default constructor should create an object for a time of zero mniutes and zero seconds. the class should provide observers that return the minutes and seconds separately, and an observer that returns the total time in seconds (minutes x 60 + seconds). boolean observers should be used too that test whether two times are equal, one is greater than the other or less than the other. transformers should be provided that add one time to another and subtract that time from another. no negative time is allowed. is my output correct? something just doesn't seem right about it. any advice would be appreciated. i want the code to look better than what it does right now.
CPP / C++ / C Code:
Last edited by LuciWiz : 19-Nov-2006 at 14:02.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#2
|
|||
|
|||
Re: constructors/classesQuote:
What if you let time9 be equal to 10 minutes and 20 seconds and let time10 be equal to 20 minutes and 20 seconds? What is time10 - time9? Doing it the hard way (in my poor, tired little old pea-brained head): time10 - time9 is equal to nine minutes and 50 seconds. What does your program say? What if some troublemaker (also known as "user") tried to initialize a time of 30 minutes and 200 seconds? What would be the result? Does your program output seem right? Regards, Dave |
|
#3
|
||||
|
||||
Re: constructors/classesQuote:
To make your code more c++ look a like Declaration: CPP / C++ / C Code:
CPP / C++ / C Code:
and change the control statement from CPP / C++ / C Code:
to CPP / C++ / C Code:
it makes more sense and gives the code more logic. Use the internal machanism off c++ which is the operator overloading. |
|
#4
|
|||
|
|||
Re: constructors/classesThanks for your help and advice. I went through my code and updated it like you said. I guess my question now is - when it brings up the output this is what it shows
Time1 min: 0 Time1 sec:0 Time2 min: 31 Time2 sec: 40 Time1 min: 0 Time1 secs: 0 Time2 min: 31 Time2 secs:40 Time1 total secs:0 Time2 total secs: 1900 The 2 time objects are not equal The 2 time objects are equal Time5 is not larger than TIME6 Time5 is less than TIME6 20 20 0 0 10 10 I know this is a stupid question, but is this what is supposed to happen based on what I wrote about the program assignment?? It just looks funny. |
Recent GIDBlog
First week of IA training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The