Final Examination CS 141 Fall 1996 This is a closed-book, closed-notes examination. There are six problems, each worth 16 points. Do not spend too much time on any problem. Read them all through first and solve them in the order that allows you to make the most progress. For each of the problems, you need to write a program or a function. You do not need to write comments. Your program doesn't have to be fancy or user-friendly. You should make it as simple as possible, as long as it does what is required. Problem 1 --------- A. Write a function which takes a character and a character string, and returns the index of the last occurence of the character in the character string. The function should return a -1 if the character is not in the string. B. Using the function from part A, write a program which reads in a word from the terminal and prints out the letter immediately following the final 'p' in the word. If 'p' is the last letter in the word the program should indicate that. If 'p' is not in the word the program should indicate that. Example 1 ---------- Give me a word: apple The final p in apple is followed by l Example 2 --------- Give me a word: orange The word orange has no p Example 3 --------- Give me a word: plop p is the last letter in plop Problem 3 --------- A. Define a class called "employee" which has a first name, a last name, and a salary. B. Write a member function for employee, called "max_salary", that takes an integer as input parameter. The function should return the input integer if it is larger than the salary of the employee. Otherwise, the function should return the salary of the employee. Problem 5 --------- A. Write a program which reads ten integers from the terminal and prints them in reverse order. Example Output -------------- Print ten numbers 10 90 400 23 52 76 200 4 99 60 Here they are in reverse order: 60 99 4 200 76 52 23 400 90 10 Problem 6 --------- A. What is the output of the following program? #include #include void main() { char word[10]; strcpy(word,"success"); int i; for (i = 0; word[i] != '\0'; i++) if (word[i] == 's') cout << "a"; else cout << "b"; } B. What is the output of the following program? #include #include void main() { char word[10]; strcpy(word,"success"); int i; for (i = 0; word[i] != '\0'; i++) if (word[i] == 's') cout << "a"; cout << "b"; }