THE UNIVERSITY OF BRITISH COLUMBIA CPSC 110: MIDTERM 1 Part B May 26, Important notes about this examination

Similar documents
Full Name: CS Account:

THE UNIVERSITY OF BRITISH COLUMBIA CPSC 121: MIDTERM 2 Group March 12, 2014

MATH 253/101,102,103,105 Page 1 of 12 Student-No.:

THE UNIVERSITY OF BRITISH COLUMBIA CPSC 261: MIDTERM 1 February 14, 2017

Do a domain analysis by hand-drawing three or more pictures of what the world program will look like at different stages when it is running.

UNIVERSITY REGULATIONS

UNIVERSITY REGULATIONS

CPSC 311, 2010W1 Midterm Exam #2

CPSC 121 Sample Final Examination December 2013

CPSC 121 Midterm 1 Friday October 14th, Signature: Section (circle one): 11:00 15:30 17:00

Question Marks 1 /20 2 /16 3 /7 4 /10 5 /16 6 /7 7 /24 Total /100

CPSC 320 Midterm 2. July 13, 2007

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

The University of British Columbia Final Examination - December 02, 2014 Mathematics 308. Closed book examination. No calculators.

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012

CPSC 121 Some Sample Questions for the Final Exam Tuesday, April 15, 2014, 8:30AM

Question Marks 1 /16 2 /13 3 /12 4 /15 5 /8 6 /15 7 /8 8 /5 9 /8 Total /100

CPSC 121 Midterm 1 Friday February 5th, Signature: Section (circle one): Morning Afternoon

Question Marks 1 /12 2 /6 3 /14 4 /8 5 /5 6 /16 7 /34 8 /25 Total /120

Computer Science 304

CPSC 411, 2015W Term 2 Midterm Exam Date: February 25, 2016; Instructor: Ron Garcia

Expression Values Operators. (string-append a b c ) a, b, c string-append. (substring abcd 0 2) abcd, 0, 2 substring

;; ;; Section 1 ;; ;; ;; What is the value of: (+ 2 (* 3 5)) ;; What is the value of: (string-append "Roberto" " " "Luongo")

This examination has 11 pages. Check that you have a complete paper.

Question Marks 1 /11 2 /4 3 /13 4 /5 5 /11 6 /14 7 /32 8 /6 9 /11 10 /10 Total /117

The University of Oregon May 16, 2015 Oregon Invitational Mathematics Tournament:

EXAMINATION INSTRUCTIONS

UNIVERSITY REGULATIONS

CS 411 Midterm Feb 2008

EXAMINATION INSTRUCTIONS

The University of Oregon May 16, 2015 Oregon Invitational Mathematics Tournament:

CPSC 410 Advanced Software Engineering Mid-term Examination (Term I ): Solution Instructor: Gail Murphy

EXAMINATION INSTRUCTIONS

CS 1101 Exam 3 A-Term 2013

EXAMINATION INSTRUCTIONS

Instructions to Examination Invigilators

CPSC 410? Advanced Software Engineering Mid-term Examination (Term I ) SOLUTION Instructor: Gail Murphy

CMSC 131A, Midterm 1 (Practice) Fall 2017

Industry Competency Examination Proctor Guide

CS 2500 Exam 1 Fall 2012

Department of Electrical Engineering and Computer Sciences Fall 2000 Instructor: Dan Garcia CS 3 Final Exam

FUJAA GENERAL EXAMINATION REQUIREMENTS & PROCEDURE

The University of British Columbia Computer Science 304 Practice Final Examination

You must include a signature, purpose, check- expects and complete function definition.

CMSC 131A, Midterm 1 (Practice) SOLUTION. Fall 2017

EXAMINATION INSTRUCTIONS

CPSC 311, 2011W1 Midterm Exam #2 2011/11/09

York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

How to Create Greeting Cards using LibreOffice Draw

St Gregory the Great Catholic School

Midterm Examination COMP 304B 2004: Object-oriented Design

The University of British Columbia

Structure and Interpretation of Computer Programs

Project Risk Management Single Subject Certificate Level 2. Guide for candidates

Spring CS Homework 3 p. 1. CS Homework 3

ECE 250 Data Structures and Algorithms MID-TERM EXAMINATION B /13:30-14:50 MC-4021/RCH-211

GUIDELINES FOR EXAM CANDIDATES AT UNIVERSITY OF NORDLAND

2018/9 Guidelines for Electronic Exam Paper Submission

CPSC 126 SAMPLE FINAL EXAMINATION ANSWERS April, 2003

CPSC Fall L01 Final Exam

Model-View-Controller Architecture

Structure and Interpretation of Computer Programs

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

READ AND OBSERVE THE FOLLOWING RULES:

YOUR NAME PLEASE: *** SOLUTIONS ***

Module 5: Lists. Readings: HtDP, Sections 9, 10.

York University. AP/ITEC Section M INTRODUCTION TO DATA STRUCTURES Winter Midterm Test

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Final Examination 8:30 AM, Wednesday, April 18, 2012

SCHOOL COLLABORATION SITES Reference Guide

CS 2150 (fall 2010) Midterm 2

Autumn 2012 October 29 th, 2012 CS106X Midterm Examination Solution

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


: Intro Programming for Scientists and Engineers Final Exam

INVIGILATOR GUIDE Computer Based Exams

CSU211 Exam 2 Fall 2007

CPSC 311: Analysis of Algorithms (Honors) Exam 1 October 11, 2002

CSE 131 Introduction to Computer Science Fall Exam II

MIDTERM EXAMINATION Douglas Wilhelm Harder EIT 4018 x T09:30:00P1H20M Rooms: RCH-103 and RCH-302

If you become unwell contact an exam supervisor immediately and ask to speak to the lecturer (Angela Finlayson).

CIS 110 Introduction to Computer Programming Summer 2014 Midterm. Name:

CSE 341 : Programming Languages Midterm, Spring 2015

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2010

CSE341, Fall 2011, Midterm Examination October 31, 2011

CS 320 Midterm Exam. Fall 2018

Lampton School Exam Guide

5. PLEASE TAKE HOME the question bundle, but turn in 2 paper sheets: The scantron AND the paper where you wrote your programming question solution!

Animations involving numbers

Information and Rules for Candidates taking IFE Examinations in October 2018

COS 126 Midterm 2 Programming Exam Fall 2012

CIS 110 Introduction to Computer Programming Summer 2018 Midterm. Recitation ROOM :

Grade Point Scales Standard Honors AP/College A B C D F Sample file

Working with recursion. From definition to template. Readings: HtDP, sections 11, 12, 13 (Intermezzo 2).

Introduction to Dreamweaver CS3

CS 3114 Data Structures and Algorithms READ THIS NOW!

The exam. The exam. The exam 10. Sitting a City & Guilds online examination 11. Frequently asked questions 18. Exam content 20

Guide for the IRPM Member Examination

CS 61A, Fall, 2002, Midterm #2, L. Rowe. 1. (10 points, 1 point each part) Consider the following five box-and-arrow diagrams.

MIS Quick Guide. Admin User Interface Update Guide (v )

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

Transcription:

THE UNIVERSITY OF BRITISH COLUMBIA CPSC 110: MIDTERM 1 Part B May 26, 2014 Last Name: First Name: Signature: UBC Student #: Important notes about this examination 1. This exam has two separate parts. Your time to complete the first part is 50 minutes. After that time, Part A will be collected and Part B distributed. You will then have 45 minutes to complete Part B. 2. This exam will be graded largely on how well you follow the design recipes. You have been given a copy of the Recipe Exam Sheet. Use it! 3. Put away books, papers, laptops, cell phones everything but pens, pencils, erasers and this exam. 4. Good luck! Student Conduct during Examinations 1. Each examination candidate must be prepared to produce, upon the request of the invigilator or examiner, his or her UBCcard for identification. 2. No questions will be answered in this exam. If you see text you feel is ambiguous, make a reasonable assumption, write it down, and proceed to answer the question. 3. No examination candidate shall be permitted to enter the examination room after the expiration of one half hour from the scheduled starting time, or to leave during the first half hour of the examination. Should the examination run fortyfive (45) minutes or less, no examination candidate shall be permitted to enter the examination room once the examination has begun. 4. Examination candidates must conduct themselves honestly and in accordance with established rules for a given examination, which will be articulated by the examiner or invigilator prior to the examination commencing. Should dishonest behaviour be observed by the examiner(s) or invigilator(s), pleas of accident or forgetfulness shall not be received. 5. Examination candidates suspected of any of the following, or any other similar practices, may be immediately dismissed from the examination by the examiner/invigilator, and may be subject to disciplinary action: i. speaking or communicating with other examination candidates, unless ii. iii. iv. otherwise authorized; purposely exposing written papers to the view of other examination candidates or imaging devices; purposely viewing the written papers of other examination candidates; using or having visible at the place of writing any books, papers or other memory aid devices other than those authorized by the examiner(s); and, v. using or operating electronic devices including but not limited to telephones, calculators, computers, or similar devices other than those authorized by the examiner(s) (electronic devices other than those authorized by the examiner(s) must be completely powered down if present at the place of writing). 6. Examination candidates must not destroy or damage any examination material, must hand in all examination papers, and must not take any examination material from the examination room without permission of the examiner or invigilator. 7. Notwithstanding the above, for any mode of examination that does not fall into the traditional, paper based method, examination candidates shall adhere to any special rules for conduct as established and articulated by the examiner. 8. Examination candidates must follow any additional examination rules or directions communicated by the examiner(s) or invigilator(s). Please do not write in this space: Question 6: Question 9: Question 7: Question 8: 5 236339 344835

Below is the beginning of a running horses world program. It is more than just the solution to problem 5 from part A. It also includes constants, complete data definitions, a main function and wish list entries for the big-bang handlers. Study it carefully before proceeding. REMEMBER: Do not worry if our solution to problem 5 is different than yours! We are not grading for whether your answer is exactly the same as ours. We are grading for whether you are working with the design recipes properly. But from this point forth it is essential that you do all your work based on the start of the program we are providing you below, do not refer back to your answers from part A. (require 2htdp/image) (require 2htdp/universe) ;; Running horses ;; ================= ;; Constants: (define WIDTH 400) (define HEIGHT 400) (define SPEED 3) (define HORSE ) (define MTS )

Problem 6: On the two data definitions below you should do three things: - draw appropriate reference, self-reference, natural helper and natural recursion arrows - label each arrow with R, SR, NH or NR - number each arrow with a number like 1, 2, 3 etc. to show which arrows within the type comments correspond to which arrows within the templates ;; ================= ;; Data Definitions: (define-struct horse (x y)) ;; Horse is (make-horse Integer Integer) ;; interp. a horse at position (x,y) in pixels (define H1 (make-horse 56 100)) (define H2 (make-horse 82 14)) (define (fn-for-horse h) (... (horse-x h) (horse-y h))) ;; Template rules used: ;; - compound: 2 fields ;; ListOfHorse is one of: ;; - empty ;; - (cons Horse ListOfHorse) ;; interp. a list of horses (define LOH1 empty) (define LOH2 (cons H1 (cons H2 empty))) #; (define (fn-for-loh loh) (cond [(empty? loh) (...)] [else (... (fn-for-horse (first loh)) (fn-for-loh (rest loh)))])) ;; Template rules used: ;; - one of: 2 cases ;; - atomic distinct: empty ;; - compound: (cons Horse ListOfHorse) ;; - reference: (first loh) is Horse ;; - self-reference: (rest loh) is ListOfHorse

Problem 7 Complete the design of the next-horses function, based on the wish-list entry below. All you need to write is examples, where you got the template and a completed function definition. You do not need to repeat the signature and purpose. If you do this properly, you will end up wishing for one additional helper function. For that helper function, you should produce a complete wish list entry, but you do not need to complete the design beyond that point. ;; ================= ;; Functions: ;; ListOfHorse -> ListOfHorse ;; start the world with (main empty) ;; <no tests for main functions> (define (main loh) (big-bang loh ; ListOfHorse (on-tick next-horses) ; ListOfHorse -> ListOfHorse (to-draw render-horses) ; ListOfHorse -> Image (on-mouse handle-mouse))) ; ListOfHorse Integer Integer MouseEvent ; -> ListOfHorse ;; ListOfHorse -> Image ;; render all horses in loh on MTS (define (render-horses loh) MTS) ; stub ;; ListOfHorse Integer Integer MouseEvent -> ListOfHorse ;; add a new horse at (x,y) when the mouse button is pressed (define (handle-mouse loh x y me) loh) ; stub ;; ListOfHorse -> ListOfHorse ;; advances all horses by SPEED (define (next-horses loh) loh) ; stub

Problem 8 Here is our version of render-horses. As were were designing it we ended up wishing for a helper function called place-horse. Complete the design of the place-horse function, based on the wish-list entry below. All you need to write is examples, where you got the template and a completed function definition. You do not need to repeat the signature and purpose. ;; ListOfHorse -> Image ;; render all horses in loh on MTS (check-expect (render-horses empty) MTS) (check-expect (render-horses (cons (make-horse 10 20) (cons (make-horse 87 23) empty))) (place-image HORSE 10 20 (place-image HORSE 87 23 MTS))) ;(define (render-horses loh) MTS) ; Took template from ListOfHorse (define (render-horses loh) (cond [(empty? loh) MTS] [else (place-horse (first loh) (render-horses (rest loh)))])) ;; Horse Image -> Image ;; place horse on img at the horse's x-coord and y-coord (define (place-horse h img) img) ; stub

Problem 9 We thought we completed our design of handle-mouse, but the second check-expect is failing and when we run the program and click the mouse to add a new horse we get the below error. [Note, in this case the mouse was clicked at (225,142)] Make the minimal changes necessary to make this program work properly, make the function design consistent and respect style rules and conventions. Please make your changes by editing the code below. ;; ListOfHorse Integer Integer MouseEvent -> ListOfHorse ;; handle mouse event (check-expect (handle-mouse empty 20 43 "drag") empty) (check-expect (handle-mouse LOH2 77 29 "button-down") (cons (make-horse 77 29) LOH2)) ;(define (handle-mouse loh x y me) loh) ; Took template from MouseEvent (define (handle-mouse loh x y me) (cond [(mouse=? me "button-down") (make-horse x y)] [else loh]))