Exercise 1 Exercise 5 Write the following functions or procedures: 1. Calculates the square of a number. 1. Write a function that checks whether an array is 2. Find the maximum of two integers. in descending order instead of ascending order. 3. Checks whether a number is even or odd. 2. Modify the function to return 1 if sorted in as- 4. Checks if a positive integer is prime. cending order, -1 if sorted in descending order, and 0 if not sorted. Exercise 2 3. Write a function that takes an array and a num- 1. Write a function that takes a temperature in ber as input and returns the rst and last index Celsius as input and converts it to Fahrenheit. where that number appears. 2. Write a function that calculates the area of a circle given its radius. Exercise 6 Exercise 3 We want to implement a basic cryptography system to encode and decode text. The encryption method 1. Write a procedure to print "Hello, World!". is simple: shifting characters forward in the alphabet
(e.g., `A' `B', `B' `C', ..., `Z' `A' for uppercase 2. Write a void function that takes two integers letters, and similarly for lowercase letters). and prints their sum. 1. Write a function that takes a string and Exercise 4 shifts each letter forward by one place (e.g., "HELLO" becomes "IFMMP"). The transfor- 1. Write an algorithm in function or procedure mation should be applied directly to the vari- form that returns the number of vowels con- able storing the sentence. tained in a character string. Note that one sub- routine has every right to call another. 2. Modify the function to take a shift value as an 2. Write a function that purges a one-character argument. The user should enter a sentence string, both the string and the character being and a shift value (e.g., shift by 3: "HELLO" passed as an argument. If the specied charac- "KHOOR"). ter is not part of the string, the string must be returned intact. For example: 3. Write a function that replaces: Vowels with '*' Purge("Hello","e") will return "Hllo" Consonants with ' #' The function should mod- ify the string in-place.
J. P. Tremblay, P. G. Sorenson and D. M. Manegre - Instructor's Solutions Manual To Accompany An Introduction To Data Structures With Applications-McGraw Hill (1984)