Final Exam CS 141 Tuesday, May 2, 2000 This is a closed-book, closed-notes examination. There are 4 problems. 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 problem you need to write a function or class. You do not need to write comments, #include statements, or meaningful variable names. Assume that the type bool exists. Function prototypes are not necessary, even for classes. When you define a class, you only need to give the private part. For each problem on this test, you can (and you need to) use the functions and classes defined in some of the previous questions. You are not allowed to use any friend functions or friend classes on this test. -------------------------------------------------------------------------- 1A. Write a function called some_A which has an array of integers (grades for a test) and an integer (the size of the array) as parameters. The function should return true if at least one person received an A (90 or above) on the test. Otherwise it returns false. 1B. Write a function called all_A which has the same parameters as some_A. This function should return true if everybody got an A on the test. Otherwise it returns false. 1C. Write a function called good_test with the same parameters as some_A and all_A. This function should return true if at least one person got an A on the test, but not everybody. Otherwise it returns false. 1D. Write a program which reads in 100 test grades and prints out whether it was a good test (somebody got an A but not everybody). -------------------------------------------------------------------------- 2A. Define a class called person, which has a first name, a last name, a salary, and how many feet and inches tall the person is as private data fields. (See note about defining classes in the instructions) 2B. Write a member function for person called get_salary, which returns the salary of that person. 2C. Define a class called department which has three private data fields: an array of persons and two integers. The array of persons contains all the people in the department. One integer is the number of persons currently in the array. The other integer is an index, representing the fact that the person at that position in the array is the boss of the department. 2D. Write a member function for department called highest_salary which returns the index position of the person in that department with the highest salary. (You may assume that everyone has a different salary) 2E. Write a member function for department called new_boss which makes the person in the department with the highest salary be the boss of the department. -------------------------------------------------------------------------- -------------------------------------------------------------------------- CS141 Final Exam - Page 2 -------------------------------------------------------------------------- 3A. Write a member function for person called read, which takes an input stream as parameter. The function reads first name, last name, salary, and height in feet and inches from the file associated with the input stream and stores it in the person. (Note: the person class is defined in problem 2) 3B. Write a member function for person called shorter. This takes a person as parameter. It returns true if the (implicit) person is shorter than the person given in the parameter. Otherwise it returns false. 3C. Write a nonmember function called find_index, which takes a person, an array of persons, and the number of persons in that array as parameters. The function returns the index position of the first person in the array who is at least as tall as the person given as parameter. If everybody is shorter, the function returns the size of the array. 3D. Write a nonmember function called place_person, which takes a person an array of persons, and the number of persons in that array as parameters. Assume that the array is ordered from shortest to tallest person. Also assume that the array is not full. The function should place the person given as parameter in the correct position in the array so that the array is still ordered from shortest to tallest. You may have to rearrange some of the persons currently in the array. The function should return the new size of the array. 3E. Write a function called read_persons, which takes an input stream, an array, and the size of the array as parameters. Assume the input stream is already associated with a file that has been opened. The file contains persons (in other words, each line in the file contains a first name, last name, salary, and height in feet and inches). The function should read the persons from the file into the array so that the array is ordered from shortest person to tallest. The function should return the number of persons it has read in. (Hint: Use place_person) -------------------------------------------------------------------------- 4A. Write a function called match, which takes two strings and an integer as parameters. The function should return true if the second string occurs inside the first string beginning at the index position given by the integer. Otherwise it returns false. For example, If the first string is the word "bother" and the second string is the word "the", and the integer is 2, then the function will return true, because "the" occurs inside the word "bother" at index position 2 in the word "bother". 4B. Write a function called find, which takes two strings as parameters. The function should return true if the second string occurs inside the first string. Otherwise it returns false. For example, "the" occurs inside the word "bother", but "the" does not occur inside the word "three". 4C. Write a function called count_the, which takes an input stream as parameter. The input stream is already associated with a file which has been opened. The function should return the number of words in the file which contain the word "the" inside them. --------------------------------------------------------------------------