Link to home
Start Free TrialLog in
Avatar of dukemarlon
dukemarlon

asked on

class help

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];
}


Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

You still owe me a response in your quesion https://www.experts-exchange.com/questions/20817987/operator-overloading-question.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.
Avatar of dukemarlon
dukemarlon

ASKER

I'm sorry, I honestly thought I accepted an answer to that. I will fix that right away.
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?
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Axter is right (of course :-)
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
It's just strange that the compiler did not complain about insertinsort(), which is defined the same way.
it did, but that is a different error than what I asked for