Your name: A 1 A CS 3 (Clancy) Exam 1 October 5, 1992 Read and fill in this page now. Do NOT turn the page until you are told to do so. Your name: (please printÑlast name, first name) Your lab section day and time: Your lab t.a.: Name of the person sitting to your left: Name of the person sitting to your right: Problem 0 Total: /30 Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 This is an open-book test. You have approximately fifty minutes to complete it. You may consult any books, notes, or other inanimate objects available to you. To avoid confusion, read the problems carefully. If you find it hard to understand a problem, ask us to explain it. If you have a question during the test, please come to the front or the side of the room to ask it. This exam comprises 15% of the points on which your final grade will be based. Partial credit will be given for wrong answers. You are not to use setf within functions. Any other Lisp construct described in Touretzky chapters 1-6, in part I of the ÒDifference Between DatesÓ case study, or in ÒInteger Division and its UsesÓ is ok, though. Your exam should contain 6 problems (numbered 0 through 5) on 8 pages. Appendix A and Appendix B from part I of the ÒDifference Between DatesÓ case study appear on the last page of the exam. Please write your answers in the spaces provided in the test; in particular, we will not grade anything on the back of an exam page unless we are clearly told on the front of the page to look there. RelaxÑthis exam is not worth having heart failure about. Problem 0 (2 points; 1 minute) Put your name on each page. Also make sure you have provided the information requested on the first page. Problem 1 (4 points; 5 minutes) Given below is the definition for a function called pair-up1 and several possible calls to pair-up1. For each function call, determine if it will produce an error. For every error-free call, state the result of evaluation. For every call that will produce an error, describe the error message that results. (defun pair-up1 (L1 L2) (list (list (first L1) (second L2)) (list (first L2) (second L1)) ) ) okay? yes or no result if yes, or error message if no (pair-up1 (a b) (1 2)) (pair-up1 '(a b) (1 2)) (pair-up1 '(a b) '(1 2)) (pair-up1 '((a b) (1 2))) Problem 2 (3 points; 4 minutes) Given below is the definition for a function called pair-up2. Write an error-free sample call to pair-up2 and show what you expect evaluation of your sample call to return. (defun pair-up2 (x L) (list x (+ (first L) (second L))) ) Problem 3 (2 points; 5 minutes) Complete the function below, so that when given the index of a month in the Islamic calendar as inputÑan integer between 1 and 12Ñthe function returns the number of days in that month. (defun islam-days-in-month (month-num) (second (assoc month-num ) ) ) Problem 4 (9 points; 15 minutes) Write a function islam-date-after that takes a single input, a date in the Islamic calendar, and returns the date thatÕs one day later. Recall that the Islamic calendar has twelve months, alternately 30 and 29 days as follows: 30 29 30 29 30 29 30 29 30 29 30 29 The input to islam-date-after will be a legal date in the Islamic calendar, as was the input to your islam-day-of-year from homework assignment 2. Here are some examples of what islam-date-after should return. input value to return (1 1) (1 2) (11 15) (11 16) (3 30) (4 1) (12 29) (1 1) You may use the function islam-days-in-month from the previous problem without redefining it. Your solution may also include other auxiliary functions, whose definitions you must provide. Problem 5 (10 points; 20 minutes) Code for the ÒDifference Between DatesÓ case study programs appears at the end of this exam. Part a A programmer decides to compute the number of days between two dates by subtracting the number of days not between those dates from 365. This process is represented in the diagram below. # days between date1 and date2 = 365 Ð # days in the shaded area The programmer codes this computation as follows: (defun new-days-between (date1 date2) (- 365 (+ (days-between '(january 1) date1) (days-between date2 '(december 31)) ) ) ) Used with the program in Appendix B of the ÒDifference Between DatesÓ case study, this function produces the following results. first input date second input date result returned (january 1) (december 31) 363 (january 1) (january 1) -1 The bug can be fixed by changing the 365 in new-days-between to a different value. Make this fix by completing the following sentence. The 365 should be changed to in order to fix the bug. Part b Suppose that a version of new-days-between with the bug fixed is used with the program in Appendix A instead of the program in Appendix B. (Recall that the program in Appendix A is incomplete, since it is missing the function days-btwn-in-general.) Give a pair of dates for which new-days-between would return a value and days-between would not, and another pair of dates for which days-between would return a value and new-days-between would not. A pair of date inputs for which new-days-between returns a value and days-between does not (using the incomplete program in Appendix A) A pair of date inputs for which days-between returns a value and new- days-between does not (using the incomplete program in Appendix A) Part c Again assume that the version of new-days-between with the bug fixed is used with the incomplete program in Appendix A. Compare the number of pairs of date inputs for which new-days-between returns a value to the number of pairs for which days-between returns a value: does new-days-between return a result for more pairs of dates, fewer, or the same number of pairs of dates as days-between? Explain.