Midterm Examination CS 141 Wednesday, October 15, 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 each 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): A. Write a function called birthday that takes an integer n as parameter, then prints "Happy Birthday" n times, each time on a different line. B. Using the function of part A, write a program that prints "Happy Birthday" 10 times. ------------------------------------------------------------------------------ Problem 2 (20 points): A. Write a function with one input parameter. This function should read in two numbers from the keyboard and put their sum into the variable that is the input parameter to the function. B. Using the function from part A, write a program to read in two numbers and print their sum. ------------------------------------------------------------------------------ Problem 3 (20 points): A. Write a function that has an integer as parameter. The function should return 'p' if that integer is positive, 'n' if the integer is negative, and 'z' if the integer is zero B. Using the function of part A, write a program that reads in an integer from the keyboard. Then prints a 'p' if that number is positive, 'n' if it is negative, and 'z' if it is zero. ------------------------------------------------------------------------------ Problem 4 (20 points): A. Write a function called even_minus_odd that reads in integers from the keyboard until -1 is read in. Then it returns the sum of the even numbers it read in minus the sum of the odd numbers (except for -1) that it read in. B. Using the function from part A, write a program that reads in integers from the keyboard until -1 is read in. Then it prints the sum of the even numbers it read in minus the sum of the odd numbers (except for -1) that it read in. ------------------------------------------------------------------------------ Problem 5 (20 points): A. Write a function called in_between that takes three integers as parameters. The function should return a 1 if the third number is bigger than the first and smaller than the second number. The function should return 0 if that is not true. However, if the first number is larger than or equal to the second, you should return -1, instead of 1 or 0. B. Using the function of part A, write a program that reads in two numbers, then prints whether or not 100 is bigger than the first number read in and smaller than the second. If the first number is larger than or equal to the second, it should print out an error message instead. ------------------------------------------------------------------------------