[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

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.
0
MexicanHeat
Asked:
MexicanHeat
  • 3
  • 2
  • 2
1 Solution
 
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
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now