CS 1101 Exam 3 A-Term 2013

Similar documents
CS 1102, A05 Final Exam

CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees. CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1

CS115 INTRODUCTION TO COMPUTER SCIENCE 1. Additional Notes Module 5

CSU211 Exam 2 Fall 2007

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.

CS 2500 Exam 1 Fall 2012

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

CS 5010 Program Design Paradigms Lesson 6.1

How to Design Programs

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

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

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

The purpose of this lesson is to familiarize you with the basics of Racket (a dialect of Scheme). You will learn about

STREAMS 10. Basics of Streams. Practice with Streams COMPUTER SCIENCE 61AS. 1. What is a stream? 2. How does memoization work?

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

HIERARCHICAL DATA What is a Tree? How is it different from a Deep List? When would you use one over the other?

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

CS 314 Principles of Programming Languages. Lecture 16

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

CS115 - Module 10 - General Trees

cs61amt2_4 CS 61A Midterm #2 ver March 2, 1998 Exam version: A Your name login: cs61a- Discussion section number TA's name

Types of recursion. Structural vs. general recursion. Pure structural recursion. Readings: none. In this module: learn to use accumulative recursion

CS450 - Structure of Higher Level Languages

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

Informatics 1 Functional Programming Lecture 4. Lists and Recursion. Don Sannella University of Edinburgh

Functional Programming - 2. Higher Order Functions

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

The Design Recipe Fall 2017

ormap, andmap, and filter

Types of recursion. Readings: none. In this module: a glimpse of non-structural recursion. CS 135 Winter : Types of recursion 1

CSE341 Spring 2016, Final Examination June 6, 2016

cs173: Programming Languages

Rewriting your function using map and foldr

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

For this chapter, switch languages in DrRacket to Advanced Student Language.

CPSC 311, 2010W1 Midterm Exam #2

CS150: Exam 2 Due: Mon Apr 20th by 3:30pm (in class) or by 6:30pm (OLS 219) UVA ID: Directions

Outline. Data Definitions and Templates Syntax and Semantics Defensive Programming

CS 61A Midterm #2 ver March 2, 1998 Exam version: A. Your name. login: cs61a- Discussion section number. TA's name

CS Final Exam Review Suggestions - Spring 2014

CS1102: Macros and Recursion

CS 135 Fall 2018 Final Exam Review. CS 135 Fall 2018 Final Exam Review 1

CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local. CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local 1


Local defini1ons. Func1on mul1ples- of

STREAMS 10. Basics of Streams. Practice with Streams COMPUTER SCIENCE 61AS. 1. What is a stream?

(add1 3) 4 (check-expect (add1 3) 4)

Module 9: Binary trees

Graphs. Directed graphs. Readings: Section 28

Trees. Readings: HtDP, sections 14, 15, 16.

Trees. Binary arithmetic expressions. Visualizing binary arithmetic expressions. ((2 6) + (5 2))/(5 3) can be defined in terms of two smaller

CSE341 Spring 2017, Final Examination June 8, 2017

CS 101 Spring 2007 Midterm 2 Name: ID:

CS1102: Adding Error Checking to Macros

Graphs. Readings: Section 28. CS 135 Fall : Graphs 1

The Design Recipe Fall 2018

Racket Style Guide Fall 2017

CONCEPTS OF PROGRAMMING LANGUAGES Solutions for Mid-Term Examination

CS 314 Principles of Programming Languages

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

CS 275 Name Final Exam Solutions December 16, 2016

CS 61A Discussion 8: Scheme. March 23, 2017

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

Project 5 - The Meta-Circular Evaluator

Homework: More Abstraction, Trees, and Lists

(add1 3) 4 (check-expect (add1 3) 4)

Functions that return lists

CSU211 Exam 1 Fall 2007

Lists of Lists. CS 5010 Program Design Paradigms Bootcamp Lesson 5.3

Module 10: General trees

Exam 2. Name: UVa ID:

CS3 Midterm 2 Summer 2008

CSE 341 : Programming Languages Midterm, Spring 2015

CS2500 Exam 2 Fall 2011

YOUR NAME PLEASE: *** SOLUTIONS ***

Lists. Readings: HtDP, sections 9 and 10. Avoid 10.3 (uses draw.ss). CS 135 Winter : Lists 1

CS3L Summer 2011 Final Exam, Part 2 You may leave when finished; or, you must stop promptly at 12:20

CSE341 Spring 2017, Final Examination June 8, 2017

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

Style and Submission Guide

CS 314 Principles of Programming Languages

(Provisional) Lecture 08: List recursion and recursive diagrams 10:00 AM, Sep 22, 2017

Exam 1 - (20 points)

APCS Semester #1 Final Exam Practice Problems

Homework 1. Notes. What To Turn In. Unix Accounts. Reading. Handout 3 CSCI 334: Spring, 2017

CSE341 Autumn 2017, Final Examination December 12, 2017

Premium POS Pizza Order Entry Module. Introduction and Tutorial

CMSC 341 Lecture 7 Lists

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0))

CS61A, Fall/1999 Midterm #1 Professor Brian Harvey

CS 307 Midterm 2 Spring 2008

PROBLEM 1 : (Vocabulary: 8 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the context

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

More About Recursive Data Types

COMP 524 Spring 2018 Midterm Thursday, March 1

Generative and accumulative recursion. What is generative recursion? Example revisited: GCD. Readings: Sections 25, 26, 27, 30, 31

CS Exam 2 Study Suggestions

Transcription:

NAME: CS 1101 Exam 3 A-Term 2013 Question 1: (55) Question 2: (20) Question 3: (25) TOTAL: (100) You have 50 minutes to complete this exam. You do not need to show templates, but you may receive partial credit if you do. You also do not need to show test cases or examples of data definitions (unless a problem states otherwise), but you may develop them if they will help you write the programs. You should provide a signature/purpose for any helper function you define. Your programs may contain only the following DrRacket constructs: define define-struct cond if else local begin and the following primitive operators: empty? cons? cons first rest list append + - * / = < > <= >= string=? string-length symbol=? error format filter map and or not set! and the operators introduced by define-struct (including the set operators on structures). You may, of course, use whatever constants are necessary (empty, true, false, 0, etc.) 1

1. (55 points) The housing office at a university keeps track of information about each dorm room on campus with the following struct: ;; Dorm is a (make-dorm String Number Number Number) (define-struct dorm (building room sqft beds)) ;; interp: represents a dorm room where ;; building is the name of the building ;; room is the room number ;; sqft is the area of the room in square feet ;; beds is the number of beds in the room ;; ListOfDorm is one of ;; empty ;; (cons Dorm ListOfDorm) A variable called Rooms has been defined. Assume that the variable Rooms has been populated with information about each dorm room on campus: ;; Rooms: ListOfDorm ;; remembers information about each dorm room on campus (define Rooms (list (make-dorm...) (make-dorm...)...)) (a) (10 points) For each of the following operations, state whether a solution could be written using set!, set-structure!, or both (your answer to each part should be one of set!, set-structure!, or both. i. add a new dorm room to Rooms ii. add another bed to every room in the list that has at least 300 square feet (b) (5 points) Provide the signature for the mutator set-dorm-building!. 2

(c) (20 points) Write a function that satisfies the following signature and purpose: ;; add-bed-to-room: Number String ListOfDorm -> void ;; Adds 1 to the number of beds in the room with the given room number ;; in the given building. (You may assume that room numbers are ;; unique within a building.) ;; EFFECT: modifies one of the dorm rooms in the given list Use one of the set-structure! operators (don t use set! to solve this problem). 3

(d) (20 points) One of the buildings on campus is scheduled to be demolished, so all dorm rooms in that building are to be removed from the Rooms list. Write a function that satisfies the following signature and purpose: ;; remove-from-baxter: -> void ;; removes all rooms in the Baxter building from the list of dorm rooms ;; EFFECT: changes the Rooms variable Use set! (don t use a set-structure! operator to solve this problem). 4

2. (20 points) Here are the data definitions from Problem 1 again: ;; Dorm is a (make-dorm String Number Number Number) (define-struct dorm (building room sqft beds)) ;; interp: represents a dorm room where ;; building is the name of the building ;; room is the room number ;; sqft is the area of the room in square feet ;; beds is the number of beds in the room ;; ListOfDorm is one of ;; empty ;; (cons Dorm ListOfDorm) Using map and/or filter, as appropriate, write a program that satisfies the following contract and purpose: ;; large-rooms: ListOfDorm String -> ListOfNumber ;; consumes a list of dorm rooms and the name of a building and produces ;; a list of the room numbers in the given building that are more than ;; 300 square feet in area 5

3. (25 points) Here are the data definitions from Problem 1 again: ;; Dorm is a (make-dorm String Number Number Number) (define-struct dorm (building room sqft beds)) ;; interp: represents a dorm room where ;; building is the name of the building ;; room is the room number ;; sqft is the number of square feet in the room ;; beds is the number of beds in the room ;; ListOfDorm is one of ;; empty ;; (cons Dorm ListOfDorm) Re-write the program large-rooms from Problem 2, but this time, instead of using map and/or filter, use accumulator-style programming. Here s the signature and purpose for large-rooms again: ;; large-rooms: ListOfDorm String -> ListOfNumber ;; consumes a list of dorm rooms and the name of a building and produces ;; a list of the room numbers in the given building that are more than ;; 300 square feet in area (Hint: you need to write at least two functions.) You may continue your answer on the next page if you need more space. 6

(extra page if you need additional space for your answers) 7