20-CS Programming Languages Fall Final Exam! Answer all questions Be sure to put your name on the paper in the space provided!
|
|
- Lee Page
- 5 years ago
- Views:
Transcription
1 20-CS Programming Languages Fall 2018 Final Exam! Answer all questions Be sure to put your name on the paper in the space provided! Name Signature The code below compiles and runs just fine (worse that good, right?) class A { public String tostring (Object obj) { return obj.tostring(); class B extends A { public String tostring (Object obj) { return ((Integer)obj).toString(); public class prob1 { public static void main (String args[]) { LinkedList ll = new LinkedList(); ll.add(new Integer(10)); ll.add("flibbertigibbet"); System.out.println((new A()).toString(ll.get(0))); System.out.println((new B()).toString(ll.get(0))); System.out.println((new B()).toString(ll.get(1))); 1. Add a line to the main method that causes a runtime failure with a ClassCastException. Write the line below and connect it to a place in main by drawing a curvy line beginning at the start of what you wrote and ending in an arrow head between two lines in main. System.out.println((new B()).toString(ll.get(1))); 2. This code is an ultra simple, stripped down version of something that is common in practice: a developer has created class A and put it in a library and a second developer wants to extend class A with class B which, of course, is trouble. What can the first developer do to prevent the second developer from doing this successfully? Full details are required. class A { public final String tostring (Object obj) { return obj.tostring();
2 Streams can be implemented using semaphores and threads. See the last page for a reminder of what this entails for the classic producer-consumer problem. Streams can also be implemented like this: class Stream { int first; boolean empty = true; Stream rest () { return null; with sample producer-consumer application like this: class Producer extends Stream { Producer (int f) { first = f; empty = false; Stream rest () { return new Producer(first+1); class Consumer { public void consume (long n) { Stream p = new Producer(1); for (int i=0 ; i < n ; i++) { System.out.print(p.first+" "); p = p.rest(); System.out.println(); public class prob2 { public static void main (String args[]) { (new Consumer()).consume(100); 3. Which of the two Stream implementations will be faster and why? The Stream solution above is much faster because the overhead of threads is gone. 4. Name an application where the Threaded version of Stream will get into serious trouble and say what that trouble is. Hamming s sequence problem is in trouble because new threads are generated as the sequence gets larger. Eventually the threads exhaust computer resources.
3 The following code includes a procedure arraytocollection which is intended to copy items of an array of arbitrary type into a Collection of arbitrary type. In this particular instance the array is of type String and the Collection is of type Vector <String>. import java.util.*; class A { public Collection <?> arraytocollection (Object [] a, Collection <?> b) { for (int i=0 ; i < a.length ; i++) b.add(a[i]); return b; public void doit () { String arr[] = new String[10]; for (int i=0 ; i < 10 ; i++) arr[i] = new String(String.valueOf(i+3)); Vector <String> v = new Vector <String> (); Collection <?> w = arraytocollection(arr, v); System.out.println(w.toString()); public class prob3a { public static void main (String args[]) { (new A()).doit(); 5. What about arraytocollection causes this to fail to compile? Consider b.add[a(i)]. Object a[i] is of type Object but the Collection needs to be of type String. It is not allowed to convert Object to String. 6. Fix arraytocollection so that the above code compiles and runs successfully. That is, write the fixed first line of arraytocollection (public followed by return value, followed by arraytocollection followed by argument list) below. import java.util.*; class A { public <T> Collection <T> arraytocollection (T [] a, Collection <T> b) { for (int i=0 ; i < a.length ; i++) b.add(a[i]); return b; public void doit () { String arr[] = new String[10]; for (int i=0 ; i < 10 ; i++) arr[i] = new String(String.valueOf(i+3)); Vector <String> v = new Vector <String> (); Collection <?> w = arraytocollection(arr, v); System.out.println(w.toString());
4 The following procedure seq is intended to produce an infinite list of increasing numbers. (define seq (lambda (n) (cons n (seq (+ n 1))))) 7. Why is this useless? The procedure does not terminate when it is called 8. The following procedure qes is a fix. (define qes (lambda (n) (cons n (lambda () (qes (+ n 1)))))) Fill in the missing lines below to complete a procedure called take that outputs the first n numbers in (qes 1). (define take (lambda (n) (letrec ((t (lambda (m s) (if (zero? m) () (cons (car s) (t (- m 1) ((cdr s)))))))) (t n (qes 1)))))
5 The following procedure is an example of currying: a feature of functional languages like Haskell and Scheme: (define f (lambda (op) (lambda (a) (lambda (b) (op a b))))) Thus, (f +) is a procedure which adds 2 arguments, and ((f +) 4) is a procedure which adds 4 to a single argument. We can use the curry feature to write anonymous functions, even recursive ones. A first attempt at this for implementing factorial might be the following: (define g (lambda (op) (lambda (n) (if (zero? n) 1 (* n (op (- n 1))))))) The idea is that op represents the factorial function and, since g is being designed to build the anonymous factorial function, we should be able to pass g to itself and use it like this: ((g g) 10) to get factorial Why won t this work? g is not a factorial function but rather a maker of a factorial function. 10. What is the simple fix that will make this work? Change to (* n (op (- n 1))) (* n ((op op) (- n 1))) Then to get, say, factorial 10 do this: ((g g) 10).
6 11. What is the difference between a and b in the following: (define a (car (hello world I am safe))) (define b ((lambda (x) (car x)) (hello world I am safe))) There is no difference 12. How can this difference be used in an alternative to your solution in question 10 that results in a factorial specification that looks like a factorial specification? It is better to just write your solution below (which is almost the same as g fixed as requested) than to explain in English but if you need to use English, go ahead. (define g (lambda (op) ((lambda (fact) (lambda (n) (if (zero? n) 1 (* n (fact (- n 1)))))) (lambda (x) ((op op) x))))) ;; this line become fact
7 13. The following two expressions have the same value which is [8,10,12,16]: map (*2) [4, 5, 6, 8] fmap (*2) [4, 5, 6, 8] So, what s the difference? A functor must implement fmap. It is not necessary to implement map (and I am not sure you could do so if you wanted to). 14. In Haskell underlying types such as Integer and [Char] are encased in types that are designed to have code operate safely in case of failure. The value of fmap (*2) [4] is [8]. Where or what is the encasing type and are there other such encasing types that you can remember (if so, name them)? This encasing type is []. Others would be Either, Maybe. In class we also considered State and Tree. 15. What is the type signature of fmap (*2)? You can do this but it might be a struggle. Use symbol f to represent the encasing type and f b to represent the encased underlying type. Use symbol -> to separate input from output, and use symbol => to separate typeclass information from argument and output types. All you need to do is figure out what type classes you need to specify (the left side of =>) and the correct arrangement of input and output types (the right side of =>). fmap (*2) :: (Num b, Functor f) => f b -> f b 16. Write a list comprehension that is equivalent to [1,2] >>= (\n -> [ a, b ] >>= (\ch -> return (n,ch))) I am asking because I am sure you understand list comprehensions so if you get this right it means you also understand the bind operator. [(n,ch) n <- [1,2], ch <- [ a, b ]]
8 17. Write an alternative but equivalent expression for return 4 >>= (\x -> (Just (*x))) >>= (\f -> (Just (f 3))) using applicative operators <$> and <*>. Again, I am just trying to determine whether you understand something about the bind operator. In case you have forgotten about the applicative operators: first, Monads must be applicative by definition, second these operators work almost like their underlying type counterparts. (*) <$> (Just 3) <*> (Just 4) 18. Why is return needed in the above? Wouldn t 4 >>=... suffice? Actually, return is not needed. The 4 needs to be lifted to encasement by a Maybe Monad in order for the bind operator (>>=) to be used correctly and this is done by return. But it could also be done as follows: Just 4 >>= (\x -> (Just (*x))) >>= (\f -> (Just (f 3))) 19. What is wrong with the following code? #include <stdio.h> #include <stdlib.h> int getauthorization (int p) { if (p < 1000) return 0; else return 1; int main (int argc, char **argv) { int n; unsigned short b; n = atoi(argv[1]); if (!getauthorization(n)) { printf("authorization disallowed\n"); exit(0); b = n; printf("authorization for slot %d allowed\n", b); In line b = n; conversion from int to unsigned short will produce a number b that is different from n. Crafting a particular n will result in a b that would have passed the getauthorization test. If n is large enough, it will pass the test but b will be the (illegal) slot granted to the user. 20. Provide a simple fix. int main (int argc, char **argv) { unsigned short b; b = atoi(argv[1]); if (!getauthorization(b)) { printf("authorization disallowed\n"); exit(0); printf("authorization for slot %d allowed\n", b);
9 import java.util.concurrent.semaphore; class Monitor { private int contents; private Semaphore tokenout = new Semaphore(0,true); private Semaphore tokenin = new Semaphore(1,true); public int get() throws InterruptedException { tokenout.acquire(); tokenin.release(); return contents; public void put(int value) throws InterruptedException { tokenin.acquire(); contents = value; tokenout.release(); class Producer extends Thread { private Monitor monitor; private int number; public Producer (Monitor c) { monitor = c; public void run() { for (int i = 1; ; i++) { try { monitor.put(i); catch (InterruptedException e) { class Consumer extends Thread { private Monitor monitor; private int number; private long iters; public Consumer (Monitor c, long n) { monitor = c; iters = n; public void run() { int value = 0; for (int i = 0 ; i < iters ; i++) { try { value = monitor.get(); catch (InterruptedException e) { System.out.print(value+" "); System.out.println(); System.exit(1); public class ref1 { public static void main (String args[]) { Monitor m = new Monitor(); Producer p = new Producer(m); Consumer c = new Consumer(m, 100); p.start(); c.start();
Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs. Lexical addressing
Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs Lexical addressing The difference between a interpreter and a compiler is really two points on a spectrum of possible
More informationAdding Machine Run 2
Calculator Run 1 Adding Machine Run 2 Simple Adder (define TOTAL 0) (define total-message (make-message (number->string TOTAL))) (define amount-text (make-text "Amount")) (define add-button (make-button
More informationCSE413 Midterm. Question Max Points Total 100
CSE413 Midterm 05 November 2007 Name Student ID Answer all questions; show your work. You may use: 1. The Scheme language definition. 2. One 8.5 * 11 piece of paper with handwritten notes Other items,
More informationECE264 Fall 2013 Exam 1, September 24, 2013
ECE264 Fall 2013 Exam 1, September 24, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.
More informationJVM ByteCode Interpreter
JVM ByteCode Interpreter written in Haskell (In under 1000 Lines of Code) By Louis Jenkins Presentation Schedule ( 15 Minutes) Discuss and Run the Virtual Machine first
More information20-CS Programming Languages Fall 2018
20-CS-4003-001 Programming Languages Fall 2018 Answer all questions Be sure to put your name on the paper in the space provided! Name Signature 1. It is claimed in https://docs.oracle.com/javase/tutorial/extra/generics/fineprint.html
More informationCS2141 Software Development using C/C++ C++ Basics
CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short
More information20-CS Programming Languages Fall 2016
20-CS-4003-001 Programming Languages Fall 2016 Answer questions 1-6 for exam score, question 7 for brownies Be sure to put your name on the paper in the space provided! Name Signature 1. Java, the language,
More informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 18: Functional Programming Zheng (Eddy) Zhang Rutgers University April 9, 2018 Review: Defining Scheme Functions (define ( lambda (
More informationBox-and-arrow Diagrams
Box-and-arrow Diagrams 1. Draw box-and-arrow diagrams for each of the following statements. What needs to be copied, and what can be referenced with a pointer? (define a ((squid octopus) jelly sandwich))
More informationFall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives
CS 6A Scheme Fall 208 Discussion 8: October 24, 208 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write
More informationName EID. (calc (parse '{+ {with {x {+ 5 5}} {with {y {- x 3}} {+ y y} } } z } ) )
CS 345 Spring 2010 Midterm Exam Name EID 1. [4 Points] Circle the binding instances in the following expression: (calc (parse '+ with x + 5 5 with y - x 3 + y y z ) ) 2. [7 Points] Using the following
More informationHaskell An Introduction
Haskell An Introduction What is Haskell? General purpose Purely functional No function can have side-effects IO is done using special types Lazy Strongly typed Polymorphic types Concise and elegant A First
More informationComputer Science II Fall 2009
Name: Computer Science II Fall 2009 Exam #2 Closed book and notes. This exam should have five problems and six pages. Problem 0: [1 point] On a scale of 0 5, where 5 is highest, I think I deserve a for
More informationSummer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define
CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationFunctional Programming. Pure Functional Programming
Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).
More informationModule Contact: Dr Anthony J. Bagnall, CMP Copyright of the University of East Anglia Version 2
UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2014/15 PROGRAMMING 2 CMP-5015Y Time allowed: 2 hours Answer four questions. All questions carry equal weight. Notes are
More informationUMBC CMSC 331 Final Exam
UMBC CMSC 331 Final Exam Name: UMBC Username: You have two hours to complete this closed book exam. We reserve the right to assign partial credit, and to deduct points for answers that are needlessly wordy
More informationCS 11 Haskell track: lecture 1
CS 11 Haskell track: lecture 1 This week: Introduction/motivation/pep talk Basics of Haskell Prerequisite Knowledge of basic functional programming e.g. Scheme, Ocaml, Erlang CS 1, CS 4 "permission of
More informationMacros & Streams Spring 2018 Discussion 9: April 11, Macros
CS 61A Macros & Streams Spring 2018 Discussion 9: April 11, 2018 1 Macros So far, we ve mostly explored similarities between the Python and Scheme languages. For example, the Scheme list data structure
More informationRecursion. What is Recursion? Simple Example. Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem
Recursion Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem What is Recursion? A problem is decomposed into smaller sub-problems, one or more of which are simpler versions of
More informationCS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.
CS 1331 Exam 1 Fall 2016 Name (print clearly): GT account (gpburdell1, msmith3, etc): Section (e.g., B1): Signature: Failure to properly fill in the information on this page will result in a deduction
More informationCSC Java Programming, Fall Java Data Types and Control Constructs
CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference
More informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
More informationCSC 1214: Object-Oriented Programming
CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:
More informationCS131 Typed Lambda Calculus Worksheet Due Thursday, April 19th
CS131 Typed Lambda Calculus Worksheet Due Thursday, April 19th Name: CAS ID (e.g., abc01234@pomona.edu): I encourage you to collaborate. collaborations below. Please record your Each question is worth
More informationDiscussion 4. Data Abstraction and Sequences
Discussion 4 Data Abstraction and Sequences Data Abstraction: The idea of data abstraction is to conceal the representation of some data and to instead reveal a standard interface that is more aligned
More informationSCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0))
SCHEME 0 COMPUTER SCIENCE 6A July 26, 206 0. Warm Up: Conditional Expressions. What does Scheme print? scm> (if (or #t (/ 0 (/ 0 scm> (if (> 4 3 (+ 2 3 4 (+ 3 4 (* 3 2 scm> ((if (< 4 3 + - 4 00 scm> (if
More informationTopic 7: Algebraic Data Types
Topic 7: Algebraic Data Types 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 5.5, 5.7, 5.8, 5.10, 5.11, 5.12, 5.14 14.4, 14.5, 14.6 14.9, 14.11,
More informationCSE 303: Concepts and Tools for Software Development
CSE 303: Concepts and Tools for Software Development Hal Perkins Winter 2009 Lecture 7 Introduction to C: The C-Level of Abstraction CSE 303 Winter 2009, Lecture 7 1 Welcome to C Compared to Java, in rough
More informationArray. Prepared By - Rifat Shahriyar
Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types
More informationCS 61A, Fall, 2002, Midterm #2, L. Rowe. 1. (10 points, 1 point each part) Consider the following five box-and-arrow diagrams.
CS 61A, Fall, 2002, Midterm #2, L. Rowe 1. (10 points, 1 point each part) Consider the following five box-and-arrow diagrams. a) d) 3 1 2 3 1 2 e) b) 3 c) 1 2 3 1 2 1 2 For each of the following Scheme
More informationSPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each
Your Name: Your Pitt (mail NOT peoplesoft) ID: Part Question/s Points available Rubric Your Score A 1-6 6 1 pt each B 7-12 6 1 pt each C 13-16 4 1 pt each D 17-19 5 1 or 2 pts each E 20-23 5 1 or 2 pts
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #29 Arrays in C
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #29 Arrays in C (Refer Slide Time: 00:08) This session will learn about arrays in C. Now, what is the word array
More informationCSE 143 SAMPLE MIDTERM
CSE 143 SAMPLE MIDTERM 1. (5 points) In some methods, you wrote code to check if a certain precondition was held. If the precondition did not hold, then you threw an exception. This leads to robust code
More informationAdvanced Java Concepts Unit 2: Linked Lists.
Advanced Java Concepts Unit 2: Linked Lists. The List interface defines the structure of a linear collection. Here are some of its methods. boolean add( E element ) Appends the element to the end of the
More informationTyped Racket: Racket with Static Types
Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type
More informationSCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017
SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationCSC 1351: Quiz 6: Sort and Search
CSC 1351: Quiz 6: Sort and Search Name: 0.1 You want to implement combat within a role playing game on a computer. Specifically, the game rules for damage inflicted by a hit are: In order to figure out
More informationINTRODUCTION TO HASKELL
INTRODUCTION TO HASKELL PRINCIPLES OF PROGRAMMING LANGUAGES Norbert Zeh Winter 2018 Dalhousie University 1/81 HASKELL: A PURELY FUNCTIONAL PROGRAMMING LANGUAGE Functions are first-class values: Can be
More informationSTREAMS 10. Basics of Streams. Practice with Streams COMPUTER SCIENCE 61AS. 1. What is a stream? 2. How does memoization work?
STREAMS 10 COMPUTER SCIENCE 61AS Basics of Streams 1. What is a stream? 2. How does memoization work? 3. Is a cons-stream a special form? Practice with Streams 1. Define a procedure (ones) that, when run
More informationMonad (3A) Young Won Lim 8/9/17
Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published
More informationCSC 1351: Final. The code compiles, but when it runs it throws a ArrayIndexOutOfBoundsException
VERSION A CSC 1351: Final Name: 1 Interfaces, Classes and Inheritance 2 Basic Data Types (arrays, lists, stacks, queues, trees,...) 2.1 Does the following code compile? If it does not, how can it be fixed?
More informationScheme: Strings Scheme: I/O
Scheme: Strings Scheme: I/O CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Wednesday, April 5, 2017 Glenn G. Chappell Department of Computer Science University of
More informationWrite a procedure powerset which takes as its only argument a set S and returns the powerset of S.
Answers to CS61 A Final of May 23, 1997 We repeat the questions; some have typos corrected with respect to the actual exam handed out. Question 1 (5 points): Let us represent a set S of unique expressions,
More informationPractice exam for CMSC131-04, Fall 2017
Practice exam for CMSC131-04, Fall 2017 Q1 makepalindrome - Relevant topics: arrays, loops Write a method makepalidrome that takes an int array, return a new int array that contains the values from the
More informationFull file at
Chapter 1 Primitive Java Weiss 4 th Edition Solutions to Exercises (US Version) 1.1 Key Concepts and How To Teach Them This chapter introduces primitive features of Java found in all languages such as
More informationCOP4020 Programming Languages. Functional Programming Prof. Robert van Engelen
COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts
More informationScheme Quick Reference
Scheme Quick Reference COSC 18 Fall 2003 This document is a quick reference guide to common features of the Scheme language. It is not intended to be a complete language reference, but it gives terse summaries
More informationCS 1331 Exam 1 ANSWER KEY
CS 1331 Exam 1 Fall 2016 ANSWER KEY Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score. Signing signifies you are aware of and in
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions and
More informationSelected Java Topics
Selected Java Topics Introduction Basic Types, Objects and Pointers Modifiers Abstract Classes and Interfaces Exceptions and Runtime Exceptions Static Variables and Static Methods Type Safe Constants Swings
More informationCS180 Review. Recitation Week 15
CS180 Review Recitation Week 15 Announcement Final exam will be held on Thursday(12/17) 8:00~10:00 AM The coverage is comprehensive Project 5 is graded. Check your score in Blackboard. Classes and Methods
More informationCSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8
Question 1. (12 points) For each of the following, what value is printed? (Assume that each group of statements is executed independently in a newly reset Scheme environment.) (a) (define x 1) (define
More informationPrinciples of Programming Languages
Principles of Programming Languages Lesson 14 Type Checking Collaboration and Management Dana Fisman www.cs.bgu.ac.il/~ppl172 1 Type Checking We return to the issue of type safety we discussed informally,
More informationCSE 8B Final Exam Fall 2015
Name: Tutor: Student ID: Signature: CSE 8B Final Exam Fall 2015 You can rip off the last page and use as scratch paper. Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 Page 12 0
More informationThis exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions.
CS 61A Final Exam May 16, 2008 Your name login: cs61a This exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions. This booklet contains 18 numbered pages including
More informationSolutions Manual. Data Structures and Algorithms in Java, 5th edition International Student Version. M. T. Goodrich and R.
Solutions Manual Data Structures and Algorithms in Java, 5th edition International Student Version M. T. Goodrich and R. Tamassia Chapter 1 Reinforcement Solution R-1.1 Since, after the clone, A[4] and
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationObject-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007
Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007 Java We will be programming in Java in this course. Partly because it is a reasonable language, and partly because you
More informationScheme Quick Reference
Scheme Quick Reference COSC 18 Winter 2003 February 10, 2003 1 Introduction This document is a quick reference guide to common features of the Scheme language. It is by no means intended to be a complete
More informationTutorial 11. Exercise 1: CSC111 Computer Programming I. A. Write a code snippet to define the following arrays:
College of Computer and Information Sciences CSC111 Computer Programming I Exercise 1: Tutorial 11 Arrays: A. Write a code snippet to define the following arrays: 1. An int array named nums of size 10.
More informationFunctional Programming
Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used
More informationCS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor
CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static
More informationHarvard School of Engineering and Applied Sciences CS 152: Programming Languages
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 18 Thursday, March 29, 2018 In abstract algebra, algebraic structures are defined by a set of elements and operations
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationExamination Questions Midterm 1
CS1102s Data Structures and Algorithms 10/2/2010 Examination Questions Midterm 1 This examination question booklet has 9 pages, including this cover page, and contains 15 questions. You have 40 minutes
More informationCS211 Spring 2005 Prelim 1 March 10, Solutions. Instructions
CS211 Spring 2005 Prelim 1 March 10, 2005 Solutions Instructions Write your name and Cornell netid above. There are 6 questions on 9 numbered pages. Check now that you have all the pages. Write your answers
More informationDRAWING ENVIRONMENT DIAGRAMS
DRAWING ENVIRONMENT DIAGRAMS COMPUTER SCIENCE 61A September 10, 2012 0.1 Background A frame is a location where variable bindings are stored A binding is a connection between a name and a value. The name
More informationCS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03
CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03 Topics: Threading, Synchronization 1 Threading Suppose we want to create an automated program that hacks into a server. Many encryption
More informationFORM 2 (Please put your name and form # on the scantron!!!!)
CS 161 Exam 2: FORM 2 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. Recursive algorithms tend to be less efficient than iterative algorithms. 2. A recursive function
More informationINSTRUCTIONS TO CANDIDATES
NATIONAL UNIVERSITY OF SINGAPORE SCHOOL OF COMPUTING MIDTERM ASSESSMENT FOR Semester 2 AY2017/2018 CS2030 Programming Methodology II March 2018 Time Allowed 90 Minutes INSTRUCTIONS TO CANDIDATES 1. This
More informationChapter 1: Introduction to Computers, Programs, and Java
Chapter 1: Introduction to Computers, Programs, and Java 1. Q: When you compile your program, you receive an error as follows: 2. 3. %javac Welcome.java 4. javac not found 5. 6. What is wrong? 7. A: Two
More informationLesson 3: Accepting User Input and Using Different Methods for Output
Lesson 3: Accepting User Input and Using Different Methods for Output Introduction So far, you have had an overview of the basics in Java. This document will discuss how to put some power in your program
More informationMIDTERM EXAMINATION - CS130 - Spring 2005
MIDTERM EAMINATION - CS130 - Spring 2005 Your full name: Your UCSD ID number: This exam is closed book and closed notes Total number of points in this exam: 231 + 25 extra credit This exam counts for 25%
More informationObject Oriented Programming Exception Handling
Object Oriented Programming Exception Handling Budditha Hettige Department of Computer Science Programming Errors Types Syntax Errors Logical Errors Runtime Errors Syntax Errors Error in the syntax of
More informationCSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige
CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors
More informationChapter 11: Collections and Maps
Chapter 11: Collections and Maps Implementing the equals(), hashcode() and compareto() methods A Programmer's Guide to Java Certification (Second Edition) Khalid A. Mughal and Rolf W. Rasmussen Addison-Wesley,
More informationCS 211: Methods, Memory, Equality
CS 211: Methods, Memory, Equality Chris Kauffman Week 2-1 So far... Comments Statements/Expressions Variable Types little types, what about Big types? Assignment Basic Output (Input?) Conditionals (if-else)
More informationcs Java: lecture #6
cs3101-003 Java: lecture #6 news: homework #5 due today little quiz today it s the last class! please return any textbooks you borrowed from me today s topics: interfaces recursion data structures threads
More informationPlease note that if you write the mid term in pencil, you will not be allowed to submit a remark request.
University of Toronto CSC148 Introduction to Computer Science Fall 2001 Mid Term Test Section L5101 Duration: 50 minutes Aids allowed: none Make sure that your examination booklet has 8 pages (including
More informationBackward Reasoning: Rule for Assignment. Backward Reasoning: Rule for Sequence. Simple Example. Hoare Logic, continued Reasoning About Loops
Backward Reasoning: Rule for Assignment Hoare Logic, continued Reasoning About Loops { wp( x=expression,q) x = expression; { Q Rule: the weakest precondition wp( x=expression,q) is Q with all occurrences
More informationUniversity of Massachusetts Lowell
University of Massachusetts Lowell 91.301: Organization of Programming Languages Fall 2002 Quiz 1 Solutions to Sample Problems 2 91.301 Problem 1 What will Scheme print in response to the following statements?
More informationSCHEME The Scheme Interpreter. 2 Primitives COMPUTER SCIENCE 61A. October 29th, 2012
SCHEME COMPUTER SCIENCE 6A October 29th, 202 In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs, we will eventually
More informationCS450 - Structure of Higher Level Languages
Spring 2018 Streams February 24, 2018 Introduction Streams are abstract sequences. They are potentially infinite we will see that their most interesting and powerful uses come in handling infinite sequences.
More informationUniversity of Palestine. Mid Exam Total Grade: 100
First Question No. of Branches (5) A) Choose the correct answer: 1. If we type: system.out.println( a ); in the main() method, what will be the result? int a=12; //in the global space... void f() { int
More informationCommon Misunderstandings from Exam 1 Material
Common Misunderstandings from Exam 1 Material Kyle Dewey Stack and Heap Allocation with Pointers char c = c ; char* p1 = malloc(sizeof(char)); char** p2 = &p1; Where is c allocated? Where is p1 itself
More informationRules and syntax for inheritance. The boring stuff
Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for
More informationStreams, Delayed Evaluation and a Normal Order Interpreter. CS 550 Programming Languages Jeremy Johnson
Streams, Delayed Evaluation and a Normal Order Interpreter CS 550 Programming Languages Jeremy Johnson 1 Theme This lecture discusses the stream model of computation and an efficient method of implementation
More informationMonad (1A) Young Won Lim 6/26/17
Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published
More informationLast Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch
More informationCS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016
Name: USC NetID (e.g., ttrojan): CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016 There are 5 problems on the exam, with 56 points total available. There are 10 pages to the exam (5 pages
More informationClass, Variable, Constructor, Object, Method Questions
Class, Variable, Constructor, Object, Method Questions http://www.wideskills.com/java-interview-questions/java-classes-andobjects-interview-questions https://www.careerride.com/java-objects-classes-methods.aspx
More informationSCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015
SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationScheme in Scheme: The Metacircular Evaluator Eval and Apply
Scheme in Scheme: The Metacircular Evaluator Eval and Apply CS21b: Structure and Interpretation of Computer Programs Brandeis University Spring Term, 2015 The metacircular evaluator is A rendition of Scheme,
More informationFunctions and Recursion. Dr. Philip Cannata 1
Functions and Recursion Dr. Philip Cannata 1 10 High Level Languages This Course Java (Object Oriented) Jython in Java Relation ASP RDF (Horn Clause Deduction, Semantic Web) Dr. Philip Cannata 2 let transformation,
More informationAn overview of Java, Data types and variables
An overview of Java, Data types and variables Lecture 2 from (UNIT IV) Prepared by Mrs. K.M. Sanghavi 1 2 Hello World // HelloWorld.java: Hello World program import java.lang.*; class HelloWorld { public
More informationProgramming Paradigms
PP 2017/18 Unit 12 Functions and Data Types in Haskell 1/45 Programming Paradigms Unit 12 Functions and Data Types in Haskell J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE
More information1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003
1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 7, 2003 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do not need to
More informationn n Try tutorial on front page to get started! n spring13/ n Stack Overflow!
Announcements n Rainbow grades: HW1-6, Quiz1-5, Exam1 n Still grading: HW7, Quiz6, Exam2 Intro to Haskell n HW8 due today n HW9, Haskell, out tonight, due Nov. 16 th n Individual assignment n Start early!
More information