Midterm Examination CS 141 Thursday, November 13, 1997 This is a closed-book, closed-notes examination. There are five 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 most of the problems, you need to write a program or a function. You do not need to write comments, function prototypes, or include statements. 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 (20 points): Write a function called same_a, which takes two arrays of integers and an integer as input. Each array represents the scores of a person on each test of the semester in some course. The third argument is the number of test scores in each array. The function should return true if the two people got A on the same tests. (Note: A is 90 or above) Example 1 --------- Suppose the first array contains: 93 83 72 90 88 100 Suppose the second array contains: 99 42 75 100 42 94 Then the function returns true. Example 2 --------- Suppose the first array contains: 93 83 72 90 88 100 Suppose the second array contains: 80 42 75 100 42 94 Then the function returns false. Example 3 --------- Suppose the first array contains: 93 83 72 75 88 100 Suppose the second array contains: 80 42 75 100 42 94 Then the function returns false. ------------------------------------------------------------------------------ Problem 2 (20 points): Write a class called person with a data field for first name, a data field for last name, and a data field indicating if the person is married or not. Write a member function called get_married which takes another person as input. The function should give this other person the same last name as the person used to call the function, and change the marital status of both persons. As usual the class should contain the function prototype. ------------------------------------------------------------------------------ Problem 3 (20 points): Write a function called same_nums which takes two input streams as input. The function assumes that those input streams are each already associated to a file of integers. The function should return true if the files are the same (meaning that they contain the same integers in the same order). Otherwise, return false. ------------------------------------------------------------------------------ Problem 4 (20 points): Write a function called c_follows_b that takes a string as input and returns the number of times that b is immediately followed by c in the string. Example ------- Suppose the string is: abcbabbcabcbc Then the function will return 4. ------------------------------------------------------------------------------ Problem 5 (20 points): A. Write a program to print 100 random numbers between 40 and 50 (inclusive). B. What is the output of the following program: void main() { char s[20]; strcpy (s,"abcdefg"); s[strlen(s)/2] = '\0'; cout << s << "\n"; } ------------------------------------------------------------------------------