We help IT Professionals succeed at work.

class help

dukemarlon
dukemarlon asked
on
247 Views
Last Modified: 2010-04-02
ok, still trying at this program. lots of commented code, don't pay attention. I will post my error, followed by my code:

lab2main.o(.text+0xde): In function `main':
: undefined reference to `insertclass::funcsort1(double*, int&)'
collect2: ld returned 1 exit status
make: *** [lab2main] Error 1


#include <iostream>
#include "randnum.h" //this is for my random number generator
#include "insertionclass.h"
//#include "insertionsort.h" //this is for my first sort
//#include "funcsort1.cxx"
using namespace std;

//insertionclass::insertionsort(int& N, double myarray[]); //creates for
                                                        //my first sort
void randnum(int& N, double myarray[]); //prototype for my rand numbers
//insertionclass::funcsort1(double myarray[], int& N); //calls sort1
//double funcsort1(double myarray[], int& N);
//double insertionsort(int& N, double myarray[]);

int main()
{
        insertclass insert;

//Make sure to comment everything. Tar files.
//do not output every sort, only output statistics
//convert necessary functions to classes

        int N; //size of array
        cout<<"Enter size of array.  ";
        cin>>N;

        double myarray[N]; //array where rand nums will be stored

        //funcsort1(myarray, N);
        insert.funcsort1(myarray, N);

        return 0;
}



#ifndef INSERTIONCLASSH
#define INSERTIONCLASSH

#include <iostream>
#include "funcsort1.cxx"
#include "insertionclass.cxx"


class insertclass
{
        public:
                double insertionsort(int& N, double myarray[]);
                double funcsort1(double myarray[], int& N);
};
insertclass insert;

#endif



#include<iostream>

insertclass::insertionsort(int& N, double myarray[])
{
        int counter=0, counter2=0;//counter is counting comparisons
                         //counter2 is counting the number of loops
        do
        {
                for(int unsorted = 1; unsorted < N; ++unsorted)
                {
                        double nextitem = myarray[unsorted];
                        int loc = unsorted;
                        for(;(loc > 0) && (myarray[loc - 1] > nextitem);
--loc)
                        myarray[loc] = myarray[loc-1];
                        myarray[loc] = nextitem;
                        counter++;
                }
        cout<<counter<<endl;
        funcsort1(myarray, N);
        }while(counter2<=5);
 return myarray;
};




#include<iostream>
//#include"insertionsort.h"
//#include "insertionclass.h"
using namespace std;

//double insertionsort(int& N, double myarray[]);

insertclass::funcsort1(double myarray[], int& N)
{
        int temp3=0, i=0; //my two counters for the rand nums
        randnum(N, myarray);
        insertionsort(N, myarray);
        do //this loop will print out all the numbers in my rand num
           //generator
        {
                cout<<myarray[temp3]<<endl;
                temp3++;
                i++;
        }while(i<=(N-1)); //statement so I do not exceed size of array
        return myarray[N];
}


Comment
Watch Question

CERTIFIED EXPERT

Commented:
You still owe me a response in your quesion https://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20817987.html
You don't seem to maintain your questions, and I have a problem with investing time in something that you just drop.
If you want help, please treat the people who provide help with respect.

Author

Commented:
I'm sorry, I honestly thought I accepted an answer to that. I will fix that right away.
CERTIFIED EXPERT

Commented:
OK. Mistakes happen.

You seem to have the implementations of insertclass::funcsort1 and insertclass::insertionsort in two different files. This is usually not the way you implement a class. Put all the methods for one class into one .cpp file. You probably don't link in the object file for funcsort1. How many files do you have? Are you using a Makefile?
Senior Software Engineer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I will try both of these today, I will post the results tonight, I won't have access to my code until then. Thanks for the ideas in advance.
CERTIFIED EXPERT

Commented:
Axter is right (of course :-)

Author

Commented:
ok, sry for the delay. that error was fixed, but now I have a slurry of others to fix. heh, that's programming for ya
CERTIFIED EXPERT

Commented:
It's just strange that the compiler did not complain about insertinsort(), which is defined the same way.

Author

Commented:
it did, but that is a different error than what I asked for

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.