Sale!

Assignment 1: Exploring Functions and arrays

$30.00

COMP 322

Assignment 1: Exploring Functions and arrays.

1
In the following questions you will be asked to write multiple functions doing
each a specific task. The signature of each function will be provided as well as
a main() function that calls all the functions one by one and print their results
to the screen.
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:

Category:

Description

5/5 - (2 votes)

COMP 322

Assignment 1: Exploring Functions and arrays.

Before you start:
● Collaboration and research for similar problems on the internet are recommended.
However, your submission should reflect individual work and personal effort.
● Some of the topics may not be covered in class due to our limited time. You are
encouraged to find answers online. You can also reach to your instructor or TAs for
guidance.
● Please do submit your assignment before the due date to avoid penalties or worse
risking your assignment being rejected.
● Submit only one .cpp file to make it easier to grade. If some questions require you
to develop and explain, you can embed your text in a C++ comment style.
● Make sure your code is clear and readable. Readability of your code as well as the
quality of your comments will be graded.
● No submission by email. Submit your work to mycourse.
● If your code does not compile it will not be graded.
● Be happy when working on your assignment, because a happy software developer
has more inspiration than a sad one :).
1
In the following questions you will be asked to write multiple functions doing
each a specific task. The signature of each function will be provided as well as
a main() function that calls all the functions one by one and print their results
to the screen.
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