Stupid Question: Easy 20 Points

Okay, im a huge retard and in my incredible tiredness cannot figure out why this wont work....

#include <stdlib.h>
#include <iostream.h>

class Sorts
{

        public:

        void bubbleSort(int a[], int length)
        {
                int top, i, temp;

                for (top = 0; top < length - 1; top++)
                {
                        for (i = length - 1; i > top; i--)
                        {
                                if (a[i] < a[i-1])
                                {
                                        temp = a[i];
                                        a[i] = a[i-1];
                                        a[i-1] = temp;
                                }
                        }
                }
        }
};


#include <stdlib.h>
#include <iostream.h>
#include "Sorts.cpp"

main()
{
        int a[] = {1,9,3,5,2,8,6};

        for (int x = 0; x <= 6; x++)
        {
                cout << a[x];
        }

        bubbleSort (a , 7);
}

The problem is when i try to compile my driver. I get an error that says:
"Driver.cpp:14: implicit declaration of function `int bubbleSort(...)'"

Thanks for the help.
MexicanHeatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pb_indiaCommented:
Try rearranging:

#include <stdlib.h>
#include <iostream.h>


to

#include <iostream.h>
#include <stdlib.h>
0
pb_indiaCommented:
Also you need to use the functions in Class Sorts;

Try this way:

#include <iostream.h>
#include <stdlib.h>

main()
{
        int a[] = {1,9,3,5,2,8,6};

        for (int x = 0; x <= 6; x++)
        {
                cout << a[x];
        }
   Sorts s;

        s.bubbleSort (a , 7);
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fippy_DarkpawCommented:
You dont need to put bubbleSort in a class. Compile it this way:

#include <stdlib.h>
#include <iostream.h>

void bubbleSort(int a[], int length)
{
       int top, i, temp;

       for (top = 0; top < length - 1; top++)
       {
            for (i = length - 1; i > top; i--)
            {
                   if (a[i] < a[i-1])
                   {
                         temp = a[i];
                         a[i] = a[i-1];
                          a[i-1] = temp;
                    }
             }
       }
}


#include <stdlib.h>
#include <iostream.h>
#include "Sorts.cpp"

main()
{
        int a[] = {1,9,3,5,2,8,6};

        for (int x = 0; x <= 6; x++)
        {
                cout << a[x];
        }

        bubbleSort (a , 7);
}
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

MexicanHeatAuthor Commented:
Like i said....im stupid and im tired. Thanks pb. I appreciate it.
0
MexicanHeatAuthor Commented:
Yep, thanks for that flippy. Whats gonna end up happening is that im going to be testing all types of sorts and the code in my driver is going to get kind of long so i figured it would be easier to seperate the sorts. thanks for the help guys.
0
Fippy_DarkpawCommented:
I dont really see any point in putting bubble sort in a class (maybe you are used to Java?). Classes are for when you spawn multiple instances of a type of objects. Classes makes handling compex data types easy by automating some things, and encapsulating them nicely. Bubble sort is simply a function you perform on a list.
0
MexicanHeatAuthor Commented:
You hit it right on the head flippy. I've only ever done Java...and all of a sudden my class is requiring us to program in C++. I am completely lost in this language and am having a hell of a time figuring out how to do things. I do appreciate the help flippy.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.