is there trulyanything else in the world more evil?
you code for hours to find out YES! it compiles then, like a ton of bricks it hits you........unresolved eternals....
ARRGHHHHHHH
ok now that thats out
here is my code. it is in 3 linked source files
here is the header followed by the class definition, then the actual
program itself. any help is greatly appreciated.
Code:#ifndef BUB_H #define BUB_H class sort { public: sort(); ~sort(); void bubble( int [], const int, bool (*)( int, int ) ); void swap(int * const, int * const); }; #endif // now the function list #include <iostream> using namespace std; #include "BUB.H" sort::sort() {} sort::~sort() {} void sort::bubble( int work[], const int size, bool (*compare)( int, int ) ) { void swap( int * const, int * const ); for ( int pass = 1; pass < size; pass++ ) for ( int count = 0; count < size - 1; count++ ) if ( (*compare)( work[ count ], work[ count + 1 ] ) ) swap( &work[ count ], &work[ count + 1 ] ); } void sort::swap(int * const element1Ptr, int * const element2Ptr ) { int temp; temp = *element1Ptr; *element1Ptr = *element2Ptr; *element2Ptr = temp; } bool ascending( int a, int b ) { return b < a; } bool descending( int a, int b ) { return b > a; } // and the actual running program #include <iostream> using namespace std; #include <iomanip> using std::setw; #include "BUB.H" bool ascending( int, int ); bool descending( int, int ); int main() { sort b; const int arraySize = 10; int order, counter, a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 }; cout << "Enter 1 to sort in ascending order,\n" << "Enter 2 to sort in descending order: "; cin >> order; cout << "\nData items in original order\n"; for ( counter = 0; counter < arraySize; counter++ ) cout << setw( 4 ) << a[ counter ]; if ( order == 1 ) { b.bubble( a, arraySize, ascending); cout << "\nData items in ascending order\n"; } else { b.bubble( a, arraySize, descending); cout << "\nData items in descending order\n"; } for ( counter = 0; counter < arraySize; counter++ ) cout << setw( 4 ) << a[ counter ]; cout << endl; return 0; }



LinkBack URL
About LinkBacks



