ECE 462 Fall 2011, Third Exam

Similar documents
ECE 461 Fall 2011, Final Exam

ECE Fall 20l2, Second Exam

ECE 462 Fall 2011, Second Exam

ECE Fall 2014, Final Exam

ECE462Exam3. 08:10-09:20AM, November 20, 2009

ECE Fall 2017, Third Exam

ECE Fall 2018, Test 3

ECE Fall 2015, First Exam

ECE 462 Midterm Exam 2. 10:30-11:20AM, October 19, 2007

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

ECE 462 Exam 3. 11:30AM-12:20PM, November 17, 2010

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

C++ Namespaces, Exceptions

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

CMSC 202 Midterm Exam 1 Fall 2015

ECE 462 Midterm Exam 1. 10:30-11:20AM, September 21, 2007

ECE Fall 2018, Test 1

Module 7 b. -Namespaces -Exceptions handling

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

ECE Fall 2018, Test 2

#include <iostream> #include <algorithm> #include <cmath> using namespace std; int f1(int x, int y) { return (double)(x/y); }

CPSC 427: Object-Oriented Programming

ECE 462 Exam 1. 6:30-7:30PM, September 22, 2010

a. a * c - 10 = b. a % b + (a * d) + 7 =

Exceptions, Case Study-Exception handling in C++.

CSCI 102 Fall 2010 Exam #1

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. C++ Kitchen Sink. Lecture 14.

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

C++ PROGRAMMING LANGUAGE: DYNAMIC MEMORY ALLOCATION AND EXCEPTION IN C++. CAAM 519, CHAPTER 15

G52CPP C++ Programming Lecture 16

University of Michigan EECS 183: Elem. Programming Concepts Fall 2011 Exam 1: Part 1: Form 1. Professors: ML Dorf, Elliot Soloway

ECE462Exam1. 08:10-09:20AM, October 02, 2009

Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

COM S 213 PRELIM EXAMINATION #2 April 26, 2001

CSCI 104 Exceptions. Mark Redekopp David Kempe

Exam duration: 3 hours Number of pages: 10

C++ Programming Fundamentals

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

Multiple Choice Questions (20 questions * 6 points per question = 120 points)

The University of Nottingham

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

Object Oriented Programming Exception Handling

Inheritance, and Polymorphism.

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Lab#5 Due Wednesday, February 25, at the start of class. Purpose: To develop familiarity with C++ pointer variables

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

21. Exceptions. Advanced Concepts: // exceptions #include <iostream> using namespace std;

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

C++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit.

C++_ MARKS 40 MIN

! Errors can be dealt with at place error occurs

CSCI 201L Written Exam #1 Fall % of course grade

a data type is Types

CS2141 Software Development using C/C++ C++ Basics

READ ALL INSTRUCTIONS

COMP 2355 Introduction to Systems Programming

C and C++ I. Spring 2014 Carola Wenk

CS102 Software Engineering Principles

Module Contact: Dr Anthony J. Bagnall, CMP Copyright of the University of East Anglia Version 2

A Tour of the C++ Programming Language

Exceptions. CS162: Introduction to Computer Science II. Exceptions. Exceptions. Exceptions. Exceptions. Exceptions

CMSC 331 Second Midterm Exam

1 Inheritance (8 minutes, 9 points)

Midterm Practice Exam

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

Physics 234: Computational Physics

Java. Massimo Dong. November 27, Massimo Dong Java November 27, / 26

CE221 Programming in C++ Part 1 Introduction

ECE 462 Object-Oriented Programming using C++ and Java Design Issues and Multiple Inheritance in C++

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

Friend Functions, Inheritance

CMSC131. Exceptions and Exception Handling. When things go "wrong" in a program, what should happen.

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

CS 103 Unit 14 - Streams

Introduction to C++ 2. A Simple C++ Program. A C++ program consists of: a set of data & function definitions, and the main function (or driver)

Homework 4. Any questions?

CS24 Week 3 Lecture 1

Structured bindings with polymorphic lambas

Exception with arguments

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

CS16 Midterm Exam 2 E02, 10W, Phill Conrad, UC Santa Barbara Tuesday, 03/02/2010

CS Operating system

CMSC 331 Second Midterm Exam

C++ And Threads.

A Tour of the C++ Programming Language

Exception Handling in Java. An Exception is a compile time / runtime error that breaks off the

The following program computes a Calculus value, the "trapezoidal approximation of

Extending Classes (contd.) (Chapter 15) Questions:

CSE 333 Final Exam June 6, 2017 Sample Solution

ECS 140A Midterm 2 November 19, Name (Last, First):, Sign your name:

G52CPP C++ Programming Lecture 15

CS102 C++ Exception Handling & Namespaces

Exceptions - Example. Exceptions - Example

Software 1 with Java. Initialization. Initialization. Initialization. Pass by Value. Initialization. Recitation No. 11 (Summary)

CPSC 427: Object-Oriented Programming

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Transcription:

ECE 462 Fall 2011, Third Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. You have until 9:20 to take this exam. Your exam should have 12 pages total (including this cover sheet). Please let Prof. Midkiff know immediately if it does not. This exam is open book, open notes, but no electronics. If you have a question, please ask for clarification. If the question is not resolved, state on the test whatever assumptions you need to make to answer the question, and answer it under those assumptions. Check the front board occasionally for corrections. Name: Student ID:

Q1 (7 pts): Circle the most true of the following. In Java, a function may throw at most one type of exception. In Java, an integer can be thrown as an exception In Java, exceptions are asynchronous, and classes for objects that are thrown must extend Thread or implement Runnable In Java, any object can be thrown as an exception In Java, classes for objects that are thrown by exceptions must extend Exception In Java exception must be caught by the immediately surrounding try-catch block, or by the immediate caller, otherwise the program terminates. Q2 (7 pts): Circle the most true of the following. C++, the code inside finally is executed only when an exception has not occurred. The same C++ function may throw different types of exceptions. In C++, the code inside a catch clause cannot throw any exception. In C++, each try has one and only one corresponding catch. In C++, a function called inside a try block must throw an exception.

Q3 (7 pts): What is printed by the following program: class Q3 { static void f(int j) throws Exception { System.out.println( j ); if (j > 0) throw new Exception(); f( ++j ); static void f1(int j) throws Exception { try { f(1); catch(exception e ) { System.out.println("Exception caught in f1"); finally { System.out.println("in Finally"); try { f1(0); catch(exception e ) { System.out.println("Exception caught in main");

Q4 (7 pts): Either say what is printed by the program below, or write bad program if it receives an error because the type of the thrown exception, and the type in the catch clause, are not the same. class Bad extends Exception { private int val; public Bad( ) {val = 0; public Bad(int v) { val = v; public void printerror( ) { System.out.println("Error code is: "+val); class Q4 { static void f(int j) throws Bad { System.out.println( j ); if (j > 0) throw new Bad(); f( ++j ); try { f(1); catch(exception e ) { System.out.println("Exception caught"); finally { System.out.println("in Finally");

Q5 (7 pts): What is printed by the program below? #include <iostream> #include <string> using namespace std; class ExceptionType1 { private: string et1_message; ExceptionType1(string m): et1_message(m) { string getmessage() const { return et1_message; ; class ExceptionType2 { private: int et2_value; ExceptionType2(int v) { et2_value = v; int getvalue() const { return et2_value; ; void f (int i) throw (ExceptionType1, ExceptionType2) { switch (i) { case 1: throw ExceptionType1("type 1"); break; case 2: throw ExceptionType2(2); break; default: cout << "no exception" << endl; int main() { try { f (1); catch (ExceptionType1 et1 ) { cout << et1.getmessage() << endl; catch (ExceptionType2 et2 ) { cout << et2.getvalue() << endl; return 0;

Q6 (7 pts): Is it ever possible for the if expression (f1!= f2) to be true? Why or why not? class T0 extends Thread { int f1; int f2; T0() { f1 = 1; f2 = 2; public void run( ) { System.out.println("starting a T0"); f1 = I.i; f2 = I.i; I.i++; if (f1!= f2) {System.out.println("what s going on???"); class I { public static int i; I(int a) {i = a; T0 t0 = new T0( ); T0 t1 = new T0( ); t0.run( ); t1.run( );

Q7 (7 pts): Is it ever possible for the if expression (f1!= f2) to be true? Why or why not? class T0 extends Thread { int f1; int f2; T0() { f1 = 1; f2 = 2; public synchronized void run( ) { System.out.println("starting a T0"); f1 = I.i; f2 = I.i; I.i++; if (f1!= f2) {System.out.println("what s going on???"); class T1 extends Thread { int f1; int f2; T1() { f1 = 1; f2 = 2; public synchronized void run( ) { System.out.println("starting a T1"); f1 = I.i; f2 = I.i; I.i++; if (f1!= f2) {System.out.println("what s going on???"); class I { public static int i; I(int a) {i = a; T0 t0 = new T0( ); T1 t1 = new T1( ); t0.run( ); t1.run( );

Q8 (7 pts): Is it ever possible for the if expression (f1!= f2) to be true? Why or why not? class T0 extends Thread { int f1; int f2; T0() { f1 = 1; f2 = 2; public void run( ) { System.out.println("starting a T0"); synchronized(i.s) { f1 = I.i; f2 = I.i; I.i++; if (f1!= f2) {System.out.println("what s going on???"); class T1 extends Thread { int f1; int f2; T1() { f1 = 1; f2 = 2; public void run( ) { System.out.println("starting a T1"); synchronized(i.s) { f1 = I.i; f2 = I.i; I.i++; if (f1!= f2) {System.out.println("what s going on???"); class I { public static int i; public static Object s = new Object( ); I(int a) {i = a; T0 t0 = new T0( ); T1 t1 = new T1( ); t0.run( ); t1.run( );

Q9 (7 pts): Circle the most correct statement about the program below. In main, the statements d->i = 4; and b->i = 4; are legal because i is declared public in B In main, the statement d->i = 4; is illegal because D inherits privately from B, and therefore the i field is private when accessed through the D object. The statement b->i = 4; is legal, however. In main, both the statements d->i = 4; and b->i = 4; are illegal because the private inheritance of B by D makes i private regardless of how it is accessed. In main, both the statements d->i = 4; and b->i = 4; are legal because the private inheritance of B by D makes i private only to accesses within the declaration and definition of D #include <string> #include <iostream> using namespace std; class B { int i; B( ) {i=0; ; class D : private B { int j; D( ) : B( ) {j=1; ; int main(int argc, char * argv[ ]) { D* d = new D( ); B* b = new B( ); b->i = 4; d->i = 4;

Q10 (7 pts): Circle the correct answer about the program below, given the protected inheritance of B by D1. The access of i in D2::foo The access of i in D2::foo The access of i in D2::foo The access of i in D2::foo is legal, and the access of i in main is legal is legal, and the access of i in main is illegal is illegal, and the access of i in main is legal is illegal, and the access of i in main is illegal #include <string> #include <iostream> using namespace std; class B { int i; B( ) {i=0; ; class D1 : protected B { int j; D1( ) : B( ) {j=1; ; class D2 : public D1 { D2( ) : D1( ) { void foo( ) {i = 20; ; int main(int argc, char * argv[ ]) { D2* d2 = new D2( ); d2->i = 4;

Q11 (7 pts): Which of the following is not a reason to do threading (circle the correct response.) Even on a single core threads allow the appearance of progress across different pieces of work Threads allow encapsulation of data Threads allow better performance when multiple cores are available Threads allow a convenient way for a program to handle asynchronous events like mouse clicks Q12 (7 pts): The declaration of foo in class D below gives an error.why? class B { public B( ) { final public int foo(int i) { return i++; class D extends B { public D( ) { final public int foo(int i) { return i--; D d = new D( ); d.foo(57); Q13 (7 pts): The declaration of foo in class D below does not give an error, unlike the declaration in Q12. Why is this? import java.io.*; class B { public B( ) { final public int foo(int i) { return i++; class D extends B { public D( ) { final public int foo(float i) { return (int) i-1; D d = new D( ); d.foo(57);

Q14 (1 pt): What is Prof. Midkiff s favorite color? Q15 (8 pts): What object oriented concepts do you still not understand? (this will not affect future test questions, and as long as you answer something it will not affect your grade. This is just to motivate you to let me know what isn t clear.