Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 28th, 2005, 3:19 PM   #1
dayrinni
Newbie
 
Join Date: Apr 2005
Posts: 17
Rep Power: 0 dayrinni is on a distinguished road
Using a program in another program

Hi,

Really easy question. Lets say I have, for example these two programs:
quicksort.cpp
and
numbers.cpp

quicksort.cpp is obviously a quicksort program.

numbers.cpp will take an input of say, X numbers, and then sort them. I do not want to use the STL quicksort, and I do not want to retype what I typed in quicksort.cpp. So how would I use the code in quicksort.cpp so I don't have to 1.) use STL. 2.) Copy and paste my code in quicksort.cpp into numbers.cpp to utilize what I have already done.

Thank you.

PS: I apolygize for any mistakes I have made in the above posting.
dayrinni is offline   Reply With Quote
Old Oct 28th, 2005, 3:49 PM   #2
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
Quote:
Originally Posted by dayrinni
Hi,

Really easy question. Lets say I have, for example these two programs:
quicksort.cpp
and
numbers.cpp

quicksort.cpp is obviously a quicksort program.

numbers.cpp will take an input of say, X numbers, and then sort them. I do not want to use the STL quicksort, and I do not want to retype what I typed in quicksort.cpp. So how would I use the code in quicksort.cpp so I don't have to 1.) use STL. 2.) Copy and paste my code in quicksort.cpp into numbers.cpp to utilize what I have already done.

Thank you.

PS: I apolygize for any mistakes I have made in the above posting.
I assume, since you call them both programs, that they both have a main(), which means you are going to have to do some rearrangin'. If you coded quicksort procedurally, you can move the quicksort() function declaration to quicksort.h and leave the function definition in quicksort.cpp. Make sure and remove main() from quicksort.cpp. Then include the quicksort.h in your numbers proggy so you can call the quicksort() function. Depending on your IDE/Compiler you will have to make sure that the quicksort object file is created and linked.

I personally find programming things like quicksort strictly OO a little tricky. I usually have to think about it for a few minutes to get my brain to bend it into shape. (or is it my brain that get's bent?)

Post your code, so we can have a gander, but make sure to use the code tags to retain indentation and spacing ( [C O D E][/ C O D E] -but without spaces!)
__________________
-Steven
"Is this a piece of your brain?" - Basil Fawlty
stevengs is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:43 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC