LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-26-2002, 04:38 PM   #1
lopoetve
Member
 
Registered: Aug 2001
Distribution: Too many.
Posts: 102

Rep: Reputation: 15
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...
 
Old 07-26-2002, 04:51 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
" 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.
 
Old 07-26-2002, 10:23 PM   #3
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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
> 
>
 
Old 07-31-2002, 11:11 AM   #4
lopoetve
Member
 
Registered: Aug 2001
Distribution: Too many.
Posts: 102

Original Poster
Rep: Reputation: 15
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration