1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall 2011 - Final Exam



Similar documents
Math 135 Circles and Completing the Square Examples

Experiment 6: Friction

LINEAR TRANSFORMATIONS AND THEIR REPRESENTING MATRICES

Use Geometry Expressions to create a more complex locus of points. Find evidence for equivalence using Geometry Expressions.

Graphs on Logarithmic and Semilogarithmic Paper

Operations with Polynomials

PROF. BOYAN KOSTADINOV NEW YORK CITY COLLEGE OF TECHNOLOGY, CUNY

Homework 3 Solutions

Quick Reference Guide: One-time Account Update

Polynomial Functions. Polynomial functions in one variable can be written in expanded form as ( )

4.11 Inner Product Spaces

Quick Reference Guide: Reset Password

Integration by Substitution

Engineer-to-Engineer Note

Virtual Machine. Part II: Program Control. Building a Modern Computer From First Principles.

MODULE 3. 0, y = 0 for all y

APPLICATION NOTE Revision 3.0 MTD/PS-0534 August 13, 2008 KODAK IMAGE SENDORS COLOR CORRECTION FOR IMAGE SENSORS

Vendor Rating for Service Desk Selection

Regular Sets and Expressions

Protocol Analysis / Analysis of Software Artifacts Kevin Bierhoff

DlNBVRGH + Sickness Absence Monitoring Report. Executive of the Council. Purpose of report

5 a LAN 6 a gateway 7 a modem

Example 27.1 Draw a Venn diagram to show the relationship between counting numbers, whole numbers, integers, and rational numbers.

SPECIAL PRODUCTS AND FACTORIZATION

Treatment Spring Late Summer Fall Mean = 1.33 Mean = 4.88 Mean = 3.

Lecture 3 Gaussian Probability Distribution

and thus, they are similar. If k = 3 then the Jordan form of both matrices is

Engineer-to-Engineer Note

Warm-up for Differential Calculus

Small Business Cloud Services

Small Business Networking

Object Semantics Lecture 2

MATH 150 HOMEWORK 4 SOLUTIONS

Mathematics. Vectors. hsn.uk.net. Higher. Contents. Vectors 128 HSN23100

JaERM Software-as-a-Solution Package

Reasoning to Solve Equations and Inequalities

AntiSpyware Enterprise Module 8.5

Welch Allyn CardioPerfect Workstation Installation Guide

The Velocity Factor of an Insulated Two-Wire Transmission Line

9 CONTINUOUS DISTRIBUTIONS

Lecture 5. Inner Product

Small Business Networking

Factoring Polynomials

Section 7-4 Translation of Axes

Small Business Networking

P.3 Polynomials and Factoring. P.3 an 1. Polynomial STUDY TIP. Example 1 Writing Polynomials in Standard Form. What you should learn

How To Network A Smll Business

Bayesian Updating with Continuous Priors Class 13, 18.05, Spring 2014 Jeremy Orloff and Jonathan Bloom

Small Business Networking

One Minute To Learn Programming: Finite Automata

Java CUP. Java CUP Specifications. User Code Additions You may define Java code to be included within the generated parser:

Start Here. IMPORTANT: To ensure that the software is installed correctly, do not connect the USB cable until step 17. Remove tape and cardboard

Novel Methods of Generating Self-Invertible Matrix for Hill Cipher Algorithm

6.2 Volumes of Revolution: The Disk Method

Algebra Review. How well do you remember your algebra?

Section 5.2, Commands for Configuring ISDN Protocols. Section 5.3, Configuring ISDN Signaling. Section 5.4, Configuring ISDN LAPD and Call Control

UNIVERSITY OF OSLO FACULTY OF MATHEMATICS AND NATURAL SCIENCES

Basic Analysis of Autarky and Free Trade Models

CS99S Laboratory 2 Preparation Copyright W. J. Dally 2001 October 1, 2001

Vectors Recap of vectors

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 16 th May Time: 14:00 16:00

Pentominoes. Pentominoes. Bruce Baguley Cascade Math Systems, LLC. The pentominoes are a simple-looking set of objects through which some powerful

2 DIODE CLIPPING and CLAMPING CIRCUITS

Section 5-4 Trigonometric Functions

How To Set Up A Network For Your Business

Example A rectangular box without lid is to be made from a square cardboard of sides 18 cm by cutting equal squares from each corner and then folding

Helicopter Theme and Variations

License Manager Installation and Setup

Module Summary Sheets. C3, Methods for Advanced Mathematics (Version B reference to new book) Topic 2: Natural Logarithms and Exponentials

Project 6 Aircraft static stability and control

Physics 43 Homework Set 9 Chapter 40 Key

Recognition Scheme Forensic Science Content Within Educational Programmes

body.allow-sidebar OR.no-sidebar.home-page (if this is the home page).has-custom-banner OR.nocustom-banner .IR OR.no-IR

VoIP for the Small Business

All pay auctions with certain and uncertain prizes a comment

e.g. f(x) = x domain x 0 (cannot find the square root of negative values)

Lectures 8 and 9 1 Rectangular waveguides

Appendix D: Completing the Square and the Quadratic Formula. In Appendix A, two special cases of expanding brackets were considered:

ClearPeaks Customer Care Guide. Business as Usual (BaU) Services Peace of mind for your BI Investment

FAULT TREES AND RELIABILITY BLOCK DIAGRAMS. Harry G. Kwatny. Department of Mechanical Engineering & Mechanics Drexel University

Network Configuration Independence Mechanism

New Internet Radio Feature

AAPT UNITED STATES PHYSICS TEAM AIP 2010

Review guide for the final exam in Math 233

5.6 POSITIVE INTEGRAL EXPONENTS

Week 7 - Perfect Competition and Monopoly

5.2. LINE INTEGRALS 265. Let us quickly review the kind of integrals we have studied so far before we introduce a new one.

Data replication in mobile computing

9.3. The Scalar Product. Introduction. Prerequisites. Learning Outcomes

Application Bundles & Data Plans

Binary Representation of Numbers Autar Kaw

Repeated multiplication is represented using exponential notation, for example:

How fast can we sort? Sorting. Decision-tree model. Decision-tree for insertion sort Sort a 1, a 2, a 3. CS Spring 2009

According to Webster s, the

Area. GABLES 411: Gables Citywalk/Waterford Square a

PHY 222 Lab 8 MOTION OF ELECTRONS IN ELECTRIC AND MAGNETIC FIELDS

Rotating DC Motors Part II

Techniques for Requirements Gathering and Definition. Kristian Persson Principal Product Specialist

Your duty, however, does not require disclosure of matter:

Transcription:

1./1.1 Introduction to Computers nd Engineering Problem Solving Fll 211 - Finl Exm Nme: MIT Emil: TA: Section: You hve 3 hours to complete this exm. In ll questions, you should ssume tht ll necessry pckges hve lredy been imported. For coding questions, you do not need to include comments. You my only dd code inside the boxes. The code written outside the boxes my not be ltered in ny wy. Good luck! Question 1 / 1 Question 2 / 2 Question 3 / 2 Question 4 / 3 Question 5 / 2 Totl / 1 1./1.1 - Fll 211 - Finl Exm 1 / 15

This pge is intentionlly left blnk. 1./1.1 - Fll 211 - Finl Exm 2 / 15

Question 1 True/Flse Questions (1 points) Plese circle your nswer to the following questions. 1). A single strem cn be used s both n input strem nd n output strem t the sme time. True Flse 2). There cn be severl ctch blocks in single try/ctch structure. True Flse 3). A method cn throw more thn one type of Exception. True Flse 4). In Jv, clss cn extend ny number of bstrct clsses nd n bstrct clss cn hve ny number of subclsses. True Flse 5). Protected dt members cnnot be ccessed by other clsses in the sme pckge. True Flse 6). A finl method cnnot be overridden. True Flse 7). An event listener cn be registered with more thn one event source to receive notifictions bout specific types of events. True Flse 8). Strings re immutble (implicitly finl) in Jv. True Flse 9). When writing objects to file using ObjectOutputStrem, the objects cnnot hve methods. True Flse 1). A vrible declred inside for loop cn be referenced outside the loop. True Flse 1./1.1 - Fll 211 - Finl Exm 3 / 15

Question 2 Dt Structures (2 points) 2. Drw links (lines with rrows) to illustrte the process of inserting node into linked list between node i nd node i+1. Use cross (X) to denote removing link. A step is line of code. Initilly New Node Node i Node i+1 After Step 1: New Node Node i Node i+1 After Step 2: New Node Node i Node i+1 2.b Which dt structure d is used in the following two opertions (dd() nd remove())? Plese circle your nswer: Stck Queue Arry ArryList 1 2 d.dd(3) 1 2 3 d.remove() 2 3 1./1.1 - Fll 211 - Finl Exm 4 / 15

2.c Drw the contents of the stck fter the following opertions re performed. (Show only the contents tht cn be referenced.) push( s ) push( e ) pop() push( e ) pop() pop() push( y ) push( ) pop() 2.d In the following SLinkedList clss, implement method public boolen clerrest(), which removes ll the nodes in the linked list beyond the first one. The method should return true if nodes were removed, nd flse if no nodes were removed. Mke sure first, lst nd length re set correctly. The linked list my be empty. public clss SLinkedList { privte int length = ; privte Node first = null; privte Node lst = null; //the first Node in the list //the lst Node in the list privte sttic clss Node { Object ; Node ; Node( Object o, Node n ) { = o; = n; // Other existing methods here... public boolen clerrest() { 1./1.1 - Fll 211 - Finl Exm 5 / 15

Question 3 Mtrices (2 points) Recll clss Mtrix, s presented in lecture: public clss Mtrix { privte double[][] dt; public Mtrix(int m, int n) { dt = new double[m][n]; public int getnumrows() { return dt.length; public int getnumcols() { return dt[].length; public double getelement(int i, int j) { return dt[i][j]; // And mny other methods // End of Mtrix clss 1./1.1 - Fll 211 - Finl Exm 6 / 15

3. Tridigonl mtrix. A tridigonl mtrix hs nonzero elements only in the min digonl, the first digonl below it, nd the first digonl bove it: 1 1 11 21 12 22 32 23 33 n 1, n 2 n 2, n 1 n 1, n 1 Write method in clss Mtrix to check if the mtrix is tridigonl. All elements in the min digonl nd those immeditely bove nd below it must be nonzero. All other elements must be zero. Use tolernce of 1-15 to check if n element is zero or not. Assume the mtrix is squre; you do not hve to check. public boolen istridigonl() { 1./1.1 - Fll 211 - Finl Exm 7 / 15

3.b Grph. A grph refers to collection of nodes nd collection of edges tht connect pirs of nodes. Grphs re used to model mny engineering problems, including communiction nd trnsporttion networks. Simple grphs cn be described by specil type of mtrix clled n djcency mtrix. An exmple grph is shown below. It contins 3 nodes, represented by circles with their index numbers in them. The network lso hs 3 edges between nodes; the edges llow flow in both directions. The mtrix on the right is the node-to-node djcency mtrix for the grph. Every entry ij refers to the edge between node i nd j, where ij = ji = 1 if the edge exists nd if it does not. 1 2 1 1 1 2 A = 1 1 1 2 1 Imge by MIT OpenCourseWre. The node-to-node djcency mtrix of simple grph is squre nd symmetric. Ech edge is represented twice, once from i to j nd once from j to i. Node hs self loop in this exmple. The Grph clss is shown below; it is identicl to clss Mtrix except tht it holds ints, not doubles. public clss Grph { privte int[][] dt; public Grph(int n) { dt = new int[n][n]; public int getnumrows() { return dt.length; public int getnumcols() { return dt[].length; public int getelement(int i, int j) { return dt[i][j]; // And mny other methods, with ints rther thn doubles // End of Grph clss 1./1.1 - Fll 211 - Finl Exm 8 / 15

Write method getnumedges(int j) for the Grph clss tht returns the totl number of edges connected to node j. For exmple, getnumedges(1) returns 2 for the grph bove. Your method should print n error messge nd return -1 if rgument j is invlid (out of rnge). public int getnumedges(int j) { 1./1.1 - Fll 211 - Finl Exm 9 / 15

Question 4 Strems (3 points) You re given text file (registrtion.txt) tht contins lines of pirs of student IDs nd course nmes. 2381, 1.1 1812, 8.1T 1812, 1. 2381, 18.6 991, 1.24 123, 1.264 9279, 8.1T Ech line represents seprte instnce of student registrtion for prticulr course. The course is String; the student ID is n int. The delimiter is comm. You do not know the length of the file before you red ll of it. You re to write progrm tht: 1. reds the file, 2. counts the number of students registered in ech course, nd 3. prints list of ll courses with their enrollment to the console. In ddition: 1. Your progrm must hndle ny potentil exceptions. 2. Your progrm must use n pproprite dt structure to keep trck of the course registrtions, such s n rry list, hsh mp or tree mp. 3. You my write ll or most of your progrm in min() method in your clss, if you wish. You my use second clss, if necessry. Give your clss(es) descriptive nme(s). 4. You do not need to keep trck of the courses tht ech student tkes. You only need to compute nd output the number of students (enrollment) in ech course. 1./1.1 - Fll 211 - Finl Exm 1 / 15

1./1.1 - Fll 211 - Finl Exm 11 / 15

1./1.1 - Fll 211 - Finl Exm 12 / 15

Question 5 Phidgets nd Trffic Control (2 points) As prt of reserch project, you will use Phidgets to implement vrious trffic signl control policies t 77 Msschusetts Ave. Currently, there re two signl phses: 1. Phse A: Green signl for trffic flowing on Msschusetts Ave. nd red light for pedestrin crossing 2. Phse B: Red signl for trffic flowing on Msschusetts Ave. nd green light for pedestrin crossing. For simplicity we mke the following ssumptions. 1. You do not need to consider the yellow light phse. 2. Signl phses A nd B lternte, with totl cycle time of 9 seconds nd cycle split of 2/3 for phse A nd 1/3 for phse B. Tht is, phse A is on for 6 seconds, then phse B is on for 3 seconds, nd so on 3. A push button for the pedestrin crossing will be dded. When the button is pushed during phse A nd the remining green time for trffic flowing on Msschusetts Ave. is more thn 3 seconds, pushing the button reduces tht green time remining to 3 seconds for the current A phse. 4. If the pedestrin button is pushed when there is less thn 3 seconds of green time remining in phse A, or in phse B, it hs no effect. 5. Phse A begins t time = in your progrm. 6. Assume the touch sensor genertes n event relibly. A touch sensor is connected to port on the input side of the Phidgets interfce bord. Four LEDs re connected to the output ports: LED Type Output Port Representing RED Red signl for pedestrins, phse A (don t wlk) GREEN 1 Green signl for trffic flow, phse A RED 2 Red signl for trffic flow, phse B GREEN 3 Green signl for pedestrins, phse B (wlk) Your tsk is to implement the signl system using Phidgets nd Jv. Red the code given below nd complete the two methods (questions 5 nd 5b) so tht your progrm works in ccordnce to the specifiction bove. The Timer tick triggers n ActionEvent every second (1 milliseconds). Hndle exceptions where needed nd print to console (System.out.println()) if exceptions occur during runtime. 1./1.1 - Fll 211 - Finl Exm 13 / 15

public clss TrfficControl { /* Sttic members */ privte sttic InterfceKitPhidget interfcekit; privte sttic jvx.swing.timer tick; privte sttic int counter; // Counts up from seconds public sttic void min (String[] rgs) throws Exception { openintfckit(); tick = new jvx.swing.timer(1, new ActionListener(){ public void ctionperformed ( ActionEvent e ) { // Question 5: Complete the nonymous inner clss ); tick.strt(); // Code omitted to close the interfce kit. // End of min method // TrfficControl clss continues on pge 1./1.1 - Fll 211 - Finl Exm 14 / 15

privte sttic void openintfckit() { try { interfcekit = new InterfceKitPhidget(); // Question 5b: Write the event hndler for touch sensor interfcekit.openany(); interfcekit.witforattchment(); interfcekit.setrtiometric(true); while (!interfcekit.getrtiometric()); ctch (PhidgetException pe) { System.err.println(pe); // End of openintfckit() method // End of Trffic Control clss 1./1.1 - Fll 211 - Finl Exm 15 / 15

MIT OpenCourseWre http://ocw.mit.edu 1. / 1.1 / 1.2 Introduction to Computers nd Engineering Problem Solving Spring 212 For informtion bout citing these mterils or our Terms of Use, visit: http://ocw.mit.edu/terms.