Question
Need all parts to work In part one, you are going to implement the selection sort function that is capable of sorting vectors of int,
Need all parts to work
In part one, you are going to implement the selection sort function that is capable of sorting vectors of int, double or string. In part two you will be writing a try catch block to catch the out-of-range exception.
You are to write three functions and manipulate main() function for this lab all of which should be written in one main.cpp file:
Part one:
unsigned min_index(const vector
selection_sort(vector
Part two:
T getElement(vector
You are given a function that creates a vector of characters with random size. You just need to put the following piece of code in your main.cpp file as is:
vectorcreateVector(){ int vecSize = rand() % 26; char c = 'a'; vector vals; for(int i = 0; i < vecSize; i++) { vals.push_back(c); c++; } return vals; }
Here is the main function you can use. You should add try/catch block to this function so that if index is out of range in calling getElement function, it should output "out of range exception occured" followed by a new line. You should include
int main(){ //Part B srand(time(0)); vectorvals = createVector(); char curChar; int index; int numOfRuns = 10; while(--numOfRuns >= 0){ cout << "Enter a number: " << endl; cin >> index; curChar = getElement(vals,index); cout << "Element located at " << index << ": is " << curChar << endl; } return 0; }
You should come up with test harnesses to test your selection_sort function.
In this lab, you are going to write a template function that is capable of sorting vectors of characters, intgeres and strings.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started