hw7_fncts.cpp
//Filename: hw7_functions.cpp Class: CS 1570
//Description: Contains function definitions for the sorting timer program
#include<cstdlib>
#include "hw7.h"
void greeting()
{
cout<<"\nWelcome to your doom!"<<endl;
}
int randNum(const int min, const int max)
{
return rand()%(max - min + 1) + min;
}
void fillArray(int array[], const int size, const int min, const int max)
{
//So all arrays will be filled with the same data
srand(RAND_SEED);
for(int i = 0; i < size; ++i)
array[i] = randNum(min, max);
}
void sortArray(int array[], const int size, const int type)
{
switch(type)
{
case BUBBLE:
bubbleSort(array, size);
break;
case NICK:
insertionSort(array, size);
break;
case SELECTION:
selectionSort(array, size);
break;
}
}
string sortName(const int type)
{
string name;
switch(type)
{
case BUBBLE:
name = "Bubble Sort";
break;
case NICK:
name = "Nick's Sort";
break;
case SELECTION:
name = "Selection Sort";
break;
default:
name = "ERROR";
}
return name;
}
void output(const int array[], const int size)
{
for(int i = 0; i < size; i++)
cout<<array[i]<<(i == size - 1 ? "" : ", ");
cout<<endl;
}
void showResults(float minTime, float maxTime, float avgTime, int type)
{
cout<<"\n----- "<<sortName(type)<<" -----\n"
<<"\nShortest time was "<<minTime<<" seconds"
<<"\nLongest time was "<<maxTime<<" seconds"
<<"\nAverage time was "<<avgTime<<" seconds"
<<endl;
}
void signoff()
{
cout<<"\nHope you had fun."<<endl<<endl;
}