COMP 322 Assignment 1: Exploring Functions and arrays

$30.00

Category: Tags: , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

Question 1 (20 pts)
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:
void countLetter();
When running the CountLetter() function, the output should be similar to the following
example:
Please enter a sentence: HELLO there, how are you?
Please enter a letter: o
The letter o is repeated 3 times in your sentence
2
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.
https://en.wikipedia.org/wiki/NATO_phonetic_alphabet
Write a function that takes a word and translate each letter into its corresponding phonetic
alphabet.
Signature of the function:
void convertPhonetic();
When running the ConvertPhonetic() function, the output should be similar to the following
example:
Please enter a word: Hello
Hotel Echo Lima Lima Oscar
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.
3
Question 4 (20 pts)
Write a tail recursive factorial 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
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)
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 enhancedFactorial();
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
Please note that you may need to write a helper function to be called by factorial to make
your code easier.
4
Please use the following main() function for testing:
int main() {
countLetter();
convertPhonetic();
factorial();
enhancedFactorial();
return 0;
}
5