LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C++ Help (https://www.linuxquestions.org/questions/programming-9/c-help-26614/)

lopoetve 07-26-2002 04:38 PM

C++ Help
 
Ok. I've got this funky program that I'm suppoesd to modify for my c++ class. It's WAY beyond me... The class hasn't even begun to cover this shit!

Got 3 files:

dtime.h (header file with DigitalTime Class in it)

dtime.cpp (DigitalTime implementation file)

and

hw7-1.cpp (the program that runs this shit, supposedly).

Now dtime.cpp and dtime.h change the boolean operators << , >> , and == to some funny crap, and do all sorts of weird things. Now, I've got the basic original program running, but I have to add this function in, and I can't seem to find where in the program flow I can get the fucking data! IT'S JUST NOT THERE IN ANY NORMAL SENSE!...

Now I'm tempted to just hack part of the header out, change the variables, and throw it in the main function to get it to work, but that's cheating. And I'd have to make the required function return nothing...

The required function is in the implementation file and in the header, it's

void interval_since(const DigitalTime& a_previous_time, int& hours_in_interval, int& minutes_in_interval);

Any help?

Files: dtime.h (dtimeh.txt)

dtime.cpp (dtime.txt)

hw7-1.cpp (hw7-1.cpp)

I had to convert them to text for accursed yahoo...

PLEASE HELP!!! I have to have this in by midnight, and it DOESN'T WORK!!!

I have to find a way to get hours_in_interval and minutes_in_inverval...

acid_kewpie 07-26-2002 04:51 PM

" Now I'm tempted to just hack part of the header out, change the variables, and throw it in the main function to get it to work, but that's cheating."

...as is this. LinuxQuestions.org is NOT here to do your homework. please do not ask such questions in the future.

crabboy 07-26-2002 10:23 PM

Here is my solution to your problem. Since it is a school project, I trust you will use this information as a guide to completing your program and not to turn my solution in. If you intend to pass the class you really need to understand these c++ concepts. It is pretty basic stuff.
Since there is no mention of a date in your program all differences are reported as if they are in the same day.
I make no claims that my changes work correctly.
Code:

diff hwold/dtime.cpp hw/dtime.cpp
38a39,43
> int DigitalTime::convertToMinutes( void ) const
> {
>    return(  hour  * 60 + minute );
> }
>
130,133c135,150
< void DigitalTime::interval_since(const DigitalTime& a_previous_time int& hours_in_interval, int& minutes_in_interval)
< {
<
<  return("What the FUCK?");
---
> void DigitalTime::interval_since( const DigitalTime& a_previous_time,
>                                  int& hours_in_interval,
>                                  int& minutes_in_interval)
> {
>                     
>    int iMinutesDiff = a_previous_time.convertToMinutes() -
>                      this -> convertToMinutes();
>
>    int iNeg = iMinutesDiff / abs(iMinutesDiff);
>    DigitalTime CNewTime;
>    CNewTime.advance( abs(iMinutesDiff) );
>
>    hours_in_interval = CNewTime.getHour() * iNeg;
>    minutes_in_interval = CNewTime.getMinute() *
>                          ( hours_in_interval == 0 ? iNeg : 1);
>   
diff hwold/dtime.h hw/dtime.h
24a25,28
>  int convertToMinutes( void ) const;
>  int getHour( void  ) { return hour; };
>  int getMinute( void  ) { return minute; };
>
diff hwold/hw7-1.cpp hw/hw7-1.cpp
10a11
>
39a41,44
>  int iHour = 0, iMinute = 0;
>  clock.interval_since( old_clock, iHour, iMinute );
>
>  cout <<  iHour << ":" << iMinute << endl;
42a48,49
>
>


lopoetve 07-31-2002 11:11 AM

I got it. I forgot that the pass-by-reference in the interval_since would let me return both of those by passing two variables in, doing the calculations in the function, and the pass by ref would change the values globally.


All times are GMT -5. The time now is 01:28 PM.