Need Help on the functions at the bottom and the comb sort ive never seen or used it before. I just need an example to see how to call one of each of the functions and I will finish the rest. Any help is appreciated thanks!
Assignment:
Design and implement a C++ program to read a type selection from the user (integer, float,
double, string, or quit) and for the numeric types, read a length from the user. For the numeric
types, generate length number of values stored in an array. The program should use overloaded
functions to generate the numeric values, determine the minimum, maximum, sort the data, and
display the results.
#include #include #include #include using namespace std; // **************************************************************** // Program specific constants. enum allowedTypes {INTEGER, FLOAT, DOUBLE, STRING, NONE}; #define MIN_LENGTH 10 #define MAX_LENGTH 250 #define NUMSPERLINE 5 #define MAXVALUE 1000 // **************************************************************** allowedTypes getOperation(); int getLength(); void generateList(int arr[], int n); void generateList(float arr[], int n); void generateList(double arr[], int n); int maximum(int list[],int size); float maximum(float list[], int size); double maximum(double list[], int size); string maximum(string list[], int size); int minimum(int list[],int size); float minimum(float list[], int size); double minimum(double list[], int size); string minimum(string list[], int size); void displayResults(int arr[], int max, int min, int n); void displayResults(float arr[], float max, float min, int n); void displayResults(double arr[], double max, double min, int n); void displayResults(string arr[], string max, string min, int n); void combSort(int arr[], int size); void combSort(float arr[], int size); void combSort(double arr[], int size); void combSort(string arr[], int size); // **************************************************************** int main() { // -------------------------------------------- // Data declarations // includes arrays for each of the various types. int iNums[MAX_LENGTH]; int imin, imax; float fNums[MAX_LENGTH]; float fmin, fmax; double dNums[MAX_LENGTH]; double dmin, dmax; string sWords[] = {"hat", "tree", "window", "Door", "house", "flower", "pencil", "desk", "cup", "coffee", "tea", "sugar", "salt", "pepper", "ring", "number", "computer", "day", "Year", "Day", "Month", "key", "dog", "Fred", "Air", "Coat", "shoe", "television", "candle", "rock", "Paper", "Lizard"}; string smin, smax; allowedTypes myType; int length; // -------------------------------------------- // Main processing loop // get type from user and // if needed, get length // if needed, generate data // get min and max // sort numbers // display data while (true) { myType = getOperation(); if ( myType == INTEGER || myType == FLOAT || myType == DOUBLE ) length = getLength(); if (myType == NONE) { cout << endl << "Game over." << endl << "Thanks for playing." << endl; break; } switch (myType) { case INTEGER: generateList(iNums, length); imax = maximum(iNums, length); imin = minimum(iNums, length); combSort(iNums, length); displayResults(iNums, imax, imin, length); break; case FLOAT: generateList(fNums, length); fmax = maximum(fNums, length); fmin = minimum(fNums, length); combSort(fNums, length); displayResults(fNums, fmax, fmin, length); break; case DOUBLE: generateList(dNums, length); dmax = maximum(dNums, length); dmin = minimum(dNums, length); combSort(dNums, length); displayResults(dNums, dmax, dmin, length); break; case STRING: smax = maximum(sWords, sizeof(sWords)/sizeof(sWords[0])); smin = minimum(sWords, sizeof(sWords)/sizeof(sWords[0])); combSort(sWords, sizeof(sWords)/sizeof(sWords[0])); displayResults(sWords, smax, smin, sizeof(sWords)/sizeof(sWords[0])); break; } } return EXIT_SUCCESS; } // **************************************************************** // Ask user for data type of the operation. // Must be integer, float, double, string, or quit allowedTypes getOperation() { char answer; allowedTypes myType; bool goodInput = false; while (!goodInput) { cout << "-------------------------------" << endl; cout << "Select data type for operations" << endl; cout << " Integers (I/i)" << endl; cout << " Floats (F/f)" << endl; cout << " Doubles (D/d)" << endl; cout << " Strings (S/s)" << endl; cout << " Exit (Q/q)" << endl; cout << "Selection (I/i/F/f/D/d/S/s/Q/q): "; cin.clear(); cin >> answer; switch (answer) { case 'I': case 'i': myType = INTEGER; goodInput = true; break; case 'F': case 'f': myType = FLOAT; goodInput = true; break; case 'D': case 'd': myType = DOUBLE; goodInput = true; break; case 'S': case 's': myType = STRING; goodInput = true; break; case 'Q': case 'q': myType = NONE; goodInput = true; break; default: cout << "Error, must be I/i/F/f/D/d/S/s/Q/q " << endl; cout << "Please re-enter." << endl; } } return myType; } // **************************************************************** // Read and verify length from user. // Must be bewteen MIN_LENGTH and MAX_LENGTH (inclusive). // Routine shoud be efficient (which includes not performing // repeated, un-necessary work). int getLength() { } // **************************************************************** // Generate a list of random values. // uses rand() function (NO seed) // limits size to MAXVALUE void generateList (int arr[], int n) { } void generateList (float arr[], int n) { } void generateList (double arr[], int n) { } // **************************************************************** // Determine maximum. // Note, routines do NOT require data to be sorted int maximum (int lst[], int size) { } float maximum (float lst[], int size) { } double maximum (double lst[], int size) { } string maximum (string lst[], int size) { } // **************************************************************** // Determine minimum. // Note, routines do NOT require data to be sorted int minimum (int lst[], int size) { } float minimum (float lst[], int size) { } double minimum (double lst[], int size) { } string minimum (string lst[], int size) { } // **************************************************************** // Display formatted results -> integer. // formatting as per assignment specifications // displays NUMSPERLINE items per line void displayResults (int lst[], int max, int min, int aSize) { } // **************************************************************** // Display formatted results -> float. // formatting as per assignment specifications // displays NUMSPERLINE items per line void displayResults (float lst[], float max, float min, int size) { } // **************************************************************** // Display formatted results -> double. // formatting as per assignment specifications // displays NUMSPERLINE items per line void displayResults (double lst[], double max, double min, int size) { } // **************************************************************** // Display formatted results -> string. // formatting as per assignment specifications // displays NUMSPERLINE items per line void displayResults (string lst[], string max, string min, int size) { } // **************************************************************** // Sort data using comb sort. void combSort(int arr[], int size) { } void combSort(float arr[], int size) { } void combSort(double arr[], int size) { } void combSort(string arr[], int size) { } Use the following comb
1
sort algorithm:
function combsort(inputArray)
gap := inputArray.size
// init gap size
loop until gap = 1 and swapped = false
// update the gap value for a next comb
gap := int(gap / 1.247330950103979)
if gap < 1
//minimum gap is 1
gap := 1
end if
i := 0
swapped := false
//a single "comb" over the input list
loop until i + gap >= inputArray.size
if input[i] > input[i+gap]
swap
(input[i], input[i+gap])
swapped := true
// Flag a swap has occurred, so
// list is not yet fully sorted
end if
i := i + 1
end loop
end loop
end function
Example Execution:
Below is an example program execution.
Select data type for operations
Integers (I/i)
Floats (F/f)
Doubles (D/d)
Strings (S/s)
Exit (Q/q)
Selection (I/i/F/f/D/d/S/s/Q/q): i
Enter Length: 14
----------------------------------------------
Integer Input Data (sorted):
27 59 335 362 383
386 421 492 649 690
777 793 886 915
The smallest integer value is 27.
The largest integer value is 915.
-------------------------------
Select data type for operations
Integers (I/i)
Floats (F/f)
Doubles (D/d)
Strings (S/s)
Exit (Q/q)
Selection (I/i/F/f/D/d/S/s/Q/q): I
Enter Length: 77
----------------------------------------------
Integer Input Data (sorted):
11 22 42 43 58
67 69 84 87 91
123 124 135 167 170
172 178 198 211 229
276 281 305 313 315
324 327 336 364 367
368 370 373 393 399
403 413 421 426 429
434 456 505 526 530
537 540 545 567 582
584 651 729 736 750
754 763 782 784 788
802 808 814 846 857
862 862 873 895 919
925 926 929 932 956
980 996
The smallest integer value is 11.
The largest integer value is 996.
-------------------------------
Select data type for operations
Integers (I/i)
Floats (F/f)
Doubles (D/d)
Strings (S/s)
Exit (Q/q)
Selection (I/i/F/f/D/d/S/s/Q/q): F
Enter Length: 17
----------------------------------------------
Float Input Data (sorted):
12.00 60.00 94.00 97.00 226.00
368.00 378.00 434.00 467.00 539.00
570.00 586.00 601.00 676.00 739.00
795.00 902.00
The smallest float value is 12.00.
The largest float value is 902.00.
-------------------------------