function prototype, computer science homework help

Problem 1:

To access a subtring of a string str, you can use the function defined by the following function prototype:

string substr(size_t startIndex, size_t length);

However if startIndex > str.size(), this substr function will cause an out_of_range exception and terminate the program.

Write an StrExcept exception class that inherits from the base exception class out_of_range by defining its own constructor and a print() method outputtinga custom error message to the user.

Then, in the main method, write a program that asks the user to enter a string before asking him/her to enter the start index of the substring and its length.

This program should throw StrExcept if the start index is larger than the size of the string and handle this exception by surrounding it by try-catch block.

Note that out_of_range class would require you to include stdexcept library.

Problem2:

Write a recursive version of the binary search algorithm.

Function prototype: int bSearch(const int a[],int lo, int hi,int x)

Where lo and hi are the indexes of the first and last element of the binary search.

Note: You can assume that the items of the searched array to test in your main method are sorted/

"Is this question part of your assignment? We can help"

ORDER NOW