Question: Question 4 (20 pts) Question 1 (20 pts) Write a tail recursive factorial function. Write a function that asks the user to input a sentence,

Question 4 (20 pts) Question 1 (20 pts) Write a tail recursive factorial function. Write a function that asks the user to input a sentence, then it will ask the user to enter one letter. The function will then count the number of occurrences of this letter in the provided sentence. Don't forget that both uppercase and lowercase letters should be counted. Signature of the function: Signature of the function: void factorial( When running the factorial) function, the output should be similar to the following example: Please enter a number: 4 The factorial of 4 is 24 void countLetter) When running the CountLetter0 function, the output should be similar to the following example: Please enter a sentence: HELLO there, how are you? Please enter a letter: o Please note that you may need to write a helper function to be called by factorial to make your code easier Question 5 (20 pts) The letter o is repeated 3 times in your sentence Write an enhanced version of your recursive factorial function using an array that stores the calculated factorial of the first 6 factorials. This means that the values for the first 6 factorials (1, 2, 6, 24,120, 720) are already known and stored in an array so you don't need to recalculate them each time the function runs Signature of the function: void enhancedFactorial0 Question 2 (20 pts) According to wikipedia: The 26 code words in the NATO phonetic alphabet are assigned to the 26 letters of the English alphabet in alphabetical order as follows: Alfa, Bravo, Charlie, Delta, Echo, Foxtrot, Golf, Hotel, India, Juliett, Kilo, Lima, Mike, November, Oscar, Papa, Quebec, Romeo, Sierra, Tango, Uniform, Victor, Whiskey, X-ray, Yankee, Zulu When running the factorial) function, the output should be similar to the following example: Write a function that takes a word and translate each letter into its c alphabet. Signature of the function: phonetic Please enter a number: 4 The factorial of 4 is 24 Please note that you may need to write a helper function to be called by factorial to make your code easier When running the ConvertPhonetic function, the output should be similar to the following example: Please enter a word: Hello Hotel Echo Lima Lima Oscar Please use the following main) function for testing: int main) countLetter: convertPhoneticO: factorial0: enhancedFactorial); return 0 Question 3 (20 pts) Research tail recursivity and explain in your own words why it is better to design your recursive function this way Can any recursive function be designed to be tail recursive? Please develop your answer by providing clear explanation . . Write your answer inside a C++ comment block within your cpp file
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
