Lab 7
Lab 7
Lab 7
After answering each of the questions be sure to capture the output of one execution of your
program to a text file / word doc. Also, be sure to save a copy of your code, you may
need a functioning version to answer one of the subsequent questions.
NOTE for each question you may declare and define as many other
functions as you need to solve the question, but you must at least declare
and define the one specified in the question.
1) Write a function declared like int exp(int, int); that finds the result of the first
parameter raised to the power of the second parameter, recursively. (NOTE: if it helps
write this as a loop first)
3) Write a function declared like int indexOf(string&, char); that recursively finds
and returns the index of the first occurrence of the char parameter within the string
parameter, looking from left to right. If the char is NOT contained within the string, the
function must return -1. (TIP: remember how we can overload functions to create a
‘gateway’ function that can help with usability)
4) Write a function named sum that takes in an array of integers and returns the integer sum
of the elements of the array parameter using recursion. (TIP: remember that arrays do not
track their own size, so what should the prototype of this function look like?)
5) EXTRA CREDIT: Write a function called elfish that returns a bool and takes in a
string&.This function will be a recursive function. elfish will return true only if the
string& parameter contains each of the three chars ‘e’, ‘l’, and ‘f’ at least once and
in any order.