COMP 322 Assignment 1: Exploring Functions and arrays solved

$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 - (1 vote)

Question 1 (20 pts) Write a function that asks the user to input a password. The function will then: 1. Make sure that the password is at least 8 characters long. 2. Make sure that each character does not occur more than 2 times in the word (meaning that the same character may be repeated 2 times maximum but no more than that)

3. Make sure the password contains at least one number 4. Make sure the password contains at least one of the following special characters: *, # or $. If the password fulfills all of the above, a message will be printed out to the screen stating that the password has been accepted. If not you should display a message stating what exactly is wrong with the provided password. Note that the password is case sensitive. Signature of the function: void checkPassword();

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: 2 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-1 (15 pts) Write a function that will fill a 5×5 matrix by randomly generated numbers. You can use rand() and srand() functions provided by library to generate random numbers. The numbers should be positive integers ranging from 0 to 25. The signature of the function is: void fillMatrix(int matrix[rows][cols]); rows and cols are global constants defined as follow: const int rows = 5; const int cols = 5;

Question 3-2 (15 pts) Write a function that, given a 5×5 matrix as parameter, will print each row of the matrix to the screen line by line. The signature of the function is: void printMatrix(int matrix[rows][cols]); 3 You can test your function by feeding it a randomly generated matrix from question 3-1. The output should be similar to the following: 12 | 2 | 9 | 23 | 6 —————————— 5 | 12 | 19 | 3 | 16 —————————— 2 | 12 | 24 | 2 | 0 —————————— 14 | 2 | 17 | 24 | 7 —————————— 0 | 25 | 18 | 16 | 8 ——————————

Question 3-3 (30 pts) Write a recursive function that, given two 5×5 matrices as parameters, will return a third 5×5 matrix holding the result of the product of the 2 matrices. You can test your function by feeding it two randomly generated matrices from question 3-1. The signature of the function is: void multiplyMatrices(int matrix_left[rows][cols], int matrix_right[rows][cols], int matrix_result[rows][cols]); 4 Please use the following main() function for testing: int main() { checkPassword(); convertPhonetic(); int matrix[rows][cols]; int matrix2[rows][cols]; int matrix_result[rows][cols]; fillMatrix(matrix); fillMatrix(matrix2); printMatrix(matrix); multiplyMatrices(matrix, matrix2, matrix_result); printMatrix(matrix_result); return 0; } 5