// FILE: qtest1.cxx // An interactive test program for the simple quicksort function. #include // Provides toupper #include // Provides setw #include // Provides cout and cin #include // Provides EXIT_SUCCESS and size_t #include "quick1.h" // Provides prototype for quicksort( ) int get_number(const char message[ ]); // Postcondition: The user has been prompted to enter an integer. The // number has been read and returned by the function. int main( ) { int *array; // An dynamic array entered by the user, which we'll sort size_t i; // An index for the array size_t size; // The size of the dynamic array // Get the array size and allocate memory for the dynamic array. cout << "This program will sort an array of integers that you provide.\n"; cout << "How big is the array? "; cin >> size; array = new int[size]; // Get the entries for the array for (i = 0; i < size; i++) { cout << "[" << i << "]"; if (i < 10) cout << " "; array[i] = get_number(" Please type the next int in the array: "); } // Print the array, sort it, and print the array again cout << endl << "The array before and after sorting: " << endl; cout << "Before: "; for (i = 0; i < size; i++) cout << " " << setw(2) << array[i]; cout << endl; quicksort(array, size); cout << "After: "; for (i = 0; i < size; i++) cout << " " << setw(2) << array[i]; cout << endl; cout << endl << "Good-bye" << endl; return EXIT_SUCCESS; } int get_number(const char message[ ]) // Library facilities used: iostream.h { int result; cout << message; cin >> result; return result; }