Read and fill in this page now. Your instructional login (e.g., cs3-ab): Your lab section days and time: Name of the person sitting to your left:

Similar documents
CS3 Fall 05 Midterm 1 Standards and Solutions

Read and fill in this page now. Your lab section day and time: Name of the person sitting to your left: Name of the person sitting to your right:

Read and fill in this page now

CS3 Midterm 2 Summer 2008

Remember, this question was mis-worded: you could also add quoted words and sentences in the blanks below. This allowed for a solution to [4] below.

CS3 Midterm 1 Fall 2007 Standards and solutions

CS 3L (Clancy) Solutions and grading standards for exam 1

CS3 Midterm 1 Fall 2006

Difference Between Dates Case Study 2002 M. J. Clancy and M. C. Linn

CSE 142, Autumn 2007 Midterm Exam, Friday, November 2, 2007

Solutions and grading standards

CS3 Midterm 2 Standards and Solutions

Example. Section: PS 709 Examples of Calculations of Reduced Hours of Work Last Revised: February 2017 Last Reviewed: February 2017 Next Review:

CS3: Introduction to Symbolic Programming. Lecture 8: Introduction to Higher Order Functions. Spring 2008 Nate Titterton

CS3: Introduction to Symbolic Programming. Lecture 14: Lists.

CS 3 Midterm 1 Review

Problem 1. Remove consecutive duplicates (6 points, 11 mintues)

Arrays. What if you have a 1000 line file? Arrays

Math in Focus Vocabulary. Kindergarten

CSE341 Spring 2017, Final Examination June 8, 2017

CSE331 Winter 2014, Midterm Examination February 12, 2014

CS Programming I: Branches

Programming Logic and Design Sixth Edition

Department of Electrical Engineering and Computer Sciences Spring 2001 Instructor: Dan Garcia CS 3 Midterm #2. Personal Information

Computer Grade 5. Unit: 1, 2 & 3 Total Periods 38 Lab 10 Months: April and May

CS Programming I: Branches

Do not turn to the next page until the start of the exam.

COMPUTER TRAINING CENTER

Highline Excel 2016 Class 09: Date Functions

Arrays. Arrays (8.1) Arrays. One variable that can store a group of values of the same type. Storing a number of related values.

/Internet Random Moment Sampling. STATE OF ALASKA Department of Health and Social Services Division of Public Assistance

CSE341 Spring 2017, Final Examination June 8, 2017

CSE 115. Introduction to Computer Science I

Note that there are questions printed on both sides of each page!

A Beginner s Guide to Programming Logic, Introductory. Chapter 6 Arrays

CONDITIONAL EXECUTION: PART 2

University of California, Berkeley College of Engineering

CSE331 Winter 2014, Midterm Examination February 12, 2014

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

2. You are required to enter a password of up to 100 characters. The characters must be lower ASCII, printing characters.

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

CSC-105 Exam #1 October 10, 2013

02157 Functional Programming. Michael R. Ha. Disjoint Unions and Higher-order list functions. Michael R. Hansen

Multi-part functionality in PINES

Exercises Software Development I. 02 Algorithm Testing & Language Description Manual inspection, test plan, grammar, metasyntax notations (BNF, EBNF)

RELEASE NOTES SHORETEL MS DYNAMICS CRM CLIENT VERSION 8

Baldwin-Wallace College. 6 th Annual High School Programming Contest. Do not open until instructed

CS 170 Algorithms Spring 2009 David Wagner MT2

Time Management for CPA Candidates

MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY

Final Exam. COMP Summer I June 26, points

MAP OF OUR REGION. About

CS Programming I: Arrays

INTENT TO FILE (ITF)

Sequential Search (Searching Supplement: 1-2)

CS3L Summer 2011 Exam 2 Time: up to 170 minutes (you may leave when finished; or, you must stop promptly at noon)

1 out of 3 points. 2 out of 3 points. 3 out of 8 points. 4 out of 6 points. 5 out of 5 points. 6 out of 6 points. Total. Birthday: Month: Day:

In addition to the correct answer, you MUST show all your work in order to receive full credit.

DATE OF BIRTH SORTING (DBSORT)

EACH MONTH CUTTING EDGE PEER REVIEW RESEARCH ARTICLES ARE PUBLISHED

MAP OF OUR REGION. About

1 Short Answer (5 Points Each)

Understanding Browsers

High Visibility Enforcement TN Grants Tip Sheets

CSE373 Fall 2013, Midterm Examination October 18, 2013

Midterm Exam Solutions March 7, 2001 CS162 Operating Systems

CS 61B, Midterm #3 and solutions, Spring 1996

AIMMS Function Reference - Date Time Related Identifiers

Midterm I - Solution CS164, Spring 2014

Lab 6B Coin Collection

Review of Engineering Fundamentals CIVL 4197

Marketing Opportunities

SPRINGBOARD UNIT 6 DATA ANALYSIS AND PROBABILITY

Lesson 1: Creating a Worksheet and a Chart Microsoft Excel 2016 IN THIS CHAPTER, YOU WILL LEARN HOW TO

Table of Contents EXCEL ADD-IN CHANGE LOG VERSION (APRIL 28, 2013)... 2 Changes... 2 VERSION (FEBRUARY 20, 2013)...

YOUR NAME PLEASE: *** SOLUTIONS ***

Solving Your Problem by Generalization

CALENDAR OF FILING DEADLINES AND SEC HOLIDAYS

Scheme Basics > (butfirst '(help!)) ()

Russell County Schools Grade 2 Math Pacing

CSE 142 Sample Midterm Exam #2

(f) d={ alchemist :( a, t ), shaman : ( s, n ), wizard : ( w, z )} d[ shaman ][1]

Table of Contents EXCEL ADD-IN CHANGE LOG VERSION (OCT )... 3 New Features... 3

CS61B (Clancy) Spring 1996 Exam 3, solutions, and grading standards. April 12, 1996 Exam 3

Mitel for Microsoft Dynamics CRM Client V5 Release Notes

CSE505, Fall 2012, Midterm Examination October 30, 2012

Simpson Elementary School Curriculum Prioritization and Mapping 2nd Grade Math - Revised 6/2014

Abe Mirza Test 1 Review & Practice Math 1. List all the elements for: 1. B C 2. B A 3. C B. Draw the Venn diagram and shade the proper region for,

Analysis/Intelligence: Data Model - Configuration

2010Fa CS10 Online Final Answers Section 1

Operations and Properties

CS 170, Spring 2000 Midterm #1 Professor M. Clancy

02157 Functional Programming. Michael R. Ha. Tagged values and Higher-order list functions. Michael R. Hansen

Indicate the option which most accurately completes the sentence.

CMSC351 - Fall 2014, Homework #4

CS61B, Fall 2011 Final Examination (corrected) P. N. Hilfinger

Undergraduate Admission File

Building Java Programs A Back to Basics Approach 4th Edition Reges TEST BANK Full download at:

Chapter 6. More Complex Conditionals. 6.1 Nested Conditionals

Maryland Corn: Historical Basis and Price Information Fact Sheet 495

Transcription:

CS3 Fall 05 Midterm 1 Read and fill in this page now Your name: Your instructional login (e.g., cs3-ab): Your lab section days and time: Your lab T.A.: Name of the person sitting to your left: Name of the person sitting to your right: Prob 0: Prob 1: Prob 2: Prob 3: Prob 4 (a/b/c): --- --- Prob 5 (a/b/c): Raw Total: /50 Scaled Total: /30 You have 70 minutes to finish this test, which should be reasonable; there will be approximately 10 additional minutes of leeway given. Your exam should contain 6 problems (numbered 0-5) on 10 total pages. It includes the code from the case study Difference Between Dates Part II in an appendix at the end. This is an open-book test. You may consult any books, notes, or other paper-based inanimate objects available to you. 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. Restrict yourself to Scheme constructs covered in chapters 3-6 and 11 of Simply Scheme, the Difference Between Dates case study, parts 1 and 2, and the Roman Numerals case study. You can always use helper procedures, and procedures from other questions you've answered. Please write your answers in the spaces provided in the test; if you need to use the back of a page make sure to clearly tell us so on the front of the page. We believe we have provided more than enough space for your answers, so please don t try to fill it all up. Partial credit will be awarded where we can, so do try to answer each question. Relax!

Problem (1 point, 1 minute) Put your login name on the top of each page. Also make sure you have provided the information requested on the first page. Problem (7 points, 11 minutes). Fill in the blanks. Each of the following parts has a blank that you need to fill in. For parts (1)-(5), the blank follows an ; fill in the result of evaluating the scheme expression that comes before the. If the scheme expression will result in an error, write ERROR in the blank. (word 'go (word 'cal (word 'for (word 'evah (word ""))))) (se 'go (se 'cal (se 'for (se 'evah (se ""))))) (word (sentence 'word 'is 'the 'word)) (sentence (word 'word 'is 'the 'word)) (+ 3 5 ) ERROR For parts (6)-(8), fill in the blank so that the resulting scheme expression evaluates to the result shown. Don't use any parentheses. If it is impossible to do so, write IMPOSSIBLE in the blank. (define (doit x) (cond ((equal? x 'a) 'hah) ((equal? x 'b) 'hab))) (doit ) ERROR (or 'joe 'bob) 'joe (and 'joe 'bob) 'joe (Page 2)

Problem (7 points, 10 minutes). Line-em up and add-em. Write a procedure add-em which takes a sentence as input, and returns a number. The result number should be the sum of the numbers in the input sentence, starting at the beginning and continuing until something other than a positive number is reached. You may use helper procedures. (add-em '(1 4 2 0 934-3 5)) 7 (add-em '(3 5 a 8 j 2)) 8 (add-em '(1 2 3 4)) 10 (add-em '(fred and sally sitting in a tree)) 0 (Page 3)

Problem (8 points, 12 minutes): Celebrity poker needs programmers like you. Write card-outranks? The procedure takes two cards and returns true if and only if the first card is bigger than second. Cards are represented by a two-character word, where the first character represents the rank (a, k, q, j, 0, 9, 8, 7, 6, 5, 4, 3, and 2), and the second character represents the suit (s, h, d, and c). For instance, 2h is the two of hearts, qc is queen of clubs, 0s is the 10 of spades, etc. For this problem, consider all spades to rank higher than hearts, which all rank higher than diamonds, which all rank higher than clubs. (card-outranks? 'ac '3d) #f (card-outranks? 'kh 'qh) #t (card-outranks? '4s '4s) #f Comment all your procedures. Assume you have a working version of outranks?, as you wrote in lab, to use. (Remember, outranks? takes two ranks and returns true if the first is higher than the second.) You need to use proper abstraction. In this case, you will need to define accessors, name them meaningfully, and include comments indicating their purpose. (Page 4)

Problem (3/3/12 points, 24 minutes): Can you span this? Part a (3 points). Write days-until-new-year, which takes a date and returns the number of days until the end of the year, inclusive. Remember that you have the procedures in the Difference between Dates case study at your disposal, including the day-span procedure. The answer should fit in the space below! (days-until-new-year '(january 3)) 363 (days-until-new-year '(december 31)) 1 Part b (3 points). Write hours-until-new-year, which takes a date and returns the number of hours until the end of the year. (Assume that you need to calculate from noon of the date given). (hours-until-new-year '(january 3)) 8700 (hours-until-new-year '(december 29)) 60 (hours-until-new-year '(december 31)) 12 (Page 5)

Part c (12 points). The following are buggy versions of the recursive procedure day-sum, defined in the cases study Difference between dates, part II. (The code for the case study is included as an appendix). The bugs result from small changes which are underlined. For each version, note whether the bug creates a problem in the conditional, the base case, making the problem smaller, calling the function recursively, or combining the recursive calls. Also briefly describe in English the effect of the bug on the operation of day-span as a whole (not just on day-sum) this should take between 1 and 2 sentences for each case. You might include an example call to day-span illustrating the problem, although this isn't necessary with a sufficient explanation (and, might be wrong!). Don't be too verbose! We may deduct points if our eyes start to bleed. (define (day-sum first-month last-month) (if (>= first-month last-month) 0 (+ (days-in-month (name-of first-month)) (day-sum (+ first-month 1) last-month)))) (define (day-sum first-month last-month) (if (> first-month last-month) 0 (+ (days-in-month (name-of first-month)) (day-sum first-month (+ last-month 1))))) (Page 6)

Part c continued. (define (day-sum first-month last-month) (if ( < first-month last-month) 0 (+ (days-in-month (name-of first-month)) (day-sum (+ first-month 1) last-month)))) (define (day-sum first-month last-month) (if (> first-month last-month) 1 (+ (days-in-month (name-of first-month)) (day-sum (+ first-month 1) last-month)))) (Page 7)

Problem (2/3/4 points, 12 minutes): Coins. For the following problems, you will be working with coins: Coin Coin name Value (in cents) p Penny 1 n Nickle 5 d Dime 10 q Quarter 25 Part a. Fill in the blanks to write valid-coin?, which takes a coin and returns #t if it is valid (i.e., in the table above) or #f otherwise: (define (valid-coin? coin) ( coin )) Part b. Write use-coin-to-pay, which takes a numeric amount that is owed and returns the smallest-valued coin that is enough to pay that amount. If there is no single coin that will cover the entire amount to pay, return "too-expensive". You can assume that amount will be a positive number. (define (use-coin-to-pay amount) Part c. Write test cases for your procedure use-coin-to-pay (you can abbreviate it). Make sure to include the expected return value. Include enough cases to thoroughly test your procedure. (Page 8)

Appendix A: Difference Between Dates, part II code (given in appendix C). (This is not a question!) ; Recursive computation of the difference between dates ; Return the number of days spanned by earlier-date and later-date. ; Earlier-date and later-date both represent dates in 2002, ; with earlier-date being the earlier of the two. (define (day-span earlier-date later-date) (cond ((same-month? earlier-date later-date) (same-month-span earlier-date later-date) ) ((consecutive-months? earlier-date later-date) (consec-months-span earlier-date later-date) ) (else (general-day-span earlier-date later-date) ) ) ) ; Access functions for the components of a date. (define (month-name date) (first date)) (define (date-in-month date) (first (butfirst date))) ; Return true if date1 and date2 are dates in the same month, and ; false otherwise. Date1 and date2 both represent dates in 2002. (define (same-month? date1 date2) (equal? (month-name date1) (month-name date2))) ; Return the number of the month with the given name. (define (month-number month-name) (cond ((equal? month-name 'january) 1) ((equal? month-name 'february) 2) ((equal? month-name 'march) 3) ((equal? month-name 'april) 4) ((equal? month-name 'may) 5) ((equal? month-name 'june) 6) ((equal? month-name 'july) 7) ((equal? month-name 'august) 8) ((equal? month-name 'september) 9) ((equal? month-name 'october) 10) ((equal? month-name 'november) 11) ((equal? month-name 'december) 12) ) ) ; Return true if date1 is in the month that immediately precedes the ; month date2 is in, and false otherwise. ; Date1 and date2 both represent dates in 2002. (define (consecutive-months? date1 date2) (= (month-number (month-name date2)) (+ 1 (month-number (month-name date1))) ) ) ; Return the difference in days between earlier-date and later-date, ; which both represent dates in the same month of 2002. (define (same-month-span earlier-date later-date) (+ 1 (- (date-in-month later-date) (date-in-month earlier-date)) ) )

; Return the number of days in the month named month-name. (define (days-in-month month-name) (cond ((equal? month-name 'january) 31) ((equal? month-name 'february) 28) ((equal? month-name 'march) 31) ((equal? month-name 'april) 30) ((equal? month-name 'may) 31) ((equal? month-name 'june) 30) ((equal? month-name 'july) 31) ((equal? month-name 'august) 31) ((equal? month-name 'september) 30) ((equal? month-name 'october) 31) ((equal? month-name 'november) 30) ((equal? month-name 'december) 31) ) ) ; Return the number of days remaining in the month of the given date, ; including the current day. Date represents a date in 2002. (define (days-remaining date) (+ 1 (- (days-in-month (month-name date)) (date-in-month date))) ) ; Return the difference in days between earlier-date and later-date, ; which represent dates in consecutive months of 2002. (define (consec-months-span earlier-date later-date) (+ (days-remaining earlier-date) (date-in-month later-date)) ) ; Return the name of the month with the given number. ; 1 means January, 2 means February, and so on. (define (name-of month-number) (item month-number '(january february march april may june july august september october november december) ) ) ; Return the sum of days in the months represented by the range ; first-month through last-month. ; first-month and last-month are integers; 1 represents January, ; 2 February, and so on. ; This procedure uses recursion. (define (day-sum first-month last-month) (if (> first-month last-month) 0 (+ (days-in-month (name-of first-month)) (day-sum (+ first-month 1) last-month)) ) ) ; Return the number of the month that immediately precedes the month ; of the given date. 1 represents January, 2 February, and so on. (define (prev-month-number date) (- (month-number (month-name date)) 1) ) ; Return the number of the month that immediately follows the month ; of the given date. 1 represents January, 2 February, and so on. (define (next-month-number date) (+ (month-number (month-name date)) 1) ) ; Return the difference in days between earlier-date and later-date, ; which represent dates neither in the same month nor in consecutive months. (define (general-day-span earlier-date later-date) (+ (days-remaining earlier-date) (day-sum (next-month-number earlier-date) (prev-month-number later-date) ) (date-in-month later-date) ) ) (Page 10)