Introduction to Computing II (ITI 1121) MIDTERM EXAMINATION

Similar documents
Introduction to Computing II (ITI1121) FINAL EXAMINATION

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Data Structures and Algorithms Winter Semester

EENG/INFE 212 Stacks

Stacks. Definitions Operations Implementation (Arrays and Linked Lists) Applications (system stack, expression evaluation) Data Structures 1 Stacks

Lists, Stacks, and Queues (plus Priority Queues)

Solution suggestions for examination of Logic, Algorithms and Data Structures,

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal

CSEN202: Introduction to Computer Programming Spring Semester 2014 Final Exam

Hypothesis Tests and Estimation for Population Variances. Copyright 2014 Pearson Education, Inc.

CMSC 132, Object-Oriented Programming II Summer Lecture 12

CSE 355 Test 2, Fall 2016

CMSC 132, Object-Oriented Programming II Summer Lecture 6:

MA EXAM 2 INSTRUCTIONS VERSION 01 March 9, Section # and recitation time

Outline Maps of Canada

You have 3 hours to complete the exam. Some questions are harder than others, so don t spend too long on any one question.

Our true, holographic blueprint of the human matrix system

University of Ottawa

Lecture 4: Stacks and Queues

MA EXAM 1 INSTRUCTIONS VERSION 01 FEBRUARY 8, Section # and recitation time

MODULE TITLE : MASS AND ENERGY BALANCE TOPIC TITLE : ENERGY BALANCE TUTOR MARKED ASSIGNMENT 3

FINAL EXAMINATION PAPER # 64 TITLE PAGE COURSE: MATH 1210

PHYSICS 221 SPRING EXAM 2: March 30, 2017; 8:15pm 10:15pm

ITI Introduction to Computing II

Statistics 433 Practice Final Exam: Cover Sheet and Marking Sheet

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:

University of Ottawa

MA EXAM 1 INSTRUCTIONS VERSION 01 September 13, Section # and recitation time

MA 262, Spring 2018, Midterm 1 Version 01 (Green)

MA EXAM 2 INSTRUCTIONS VERSION 01 March 10, Section # and recitation time

Forecasting. Copyright 2015 Pearson Education, Inc.

STUDENT NAME: STUDENT SIGNATURE: STUDENT ID NUMBER: SECTION NUMBER AND RECITATION INSTRUCTOR:

University of Ottawa

Insert Sorted List Insert as the Last element (the First element?) Delete Chaining. 2 Slide courtesy of Dr. Sang-Eon Park

MATH 322, Midterm Exam Page 1 of 10 Student-No.: Midterm Exam Duration: 80 minutes This test has 6 questions on 10 pages, for a total of 70 points.

Math 51 Midterm 1 July 6, 2016

STUDENT NAME: STUDENT SIGNATURE: STUDENT ID NUMBER: SECTION NUMBER RECITATION INSTRUCTOR:

STUDENT NAME: STUDENT SIGNATURE: STUDENT ID NUMBER: SECTION NUMBER AND RECITATION INSTRUCTOR:

MA Exam 1 Fall 2015 VERSION 01

CS-140 Fall 2018 Test 2 Version Practice Nov. 12, Name:

Physics 101 Hour Exam 3 December 2, 2013

University of Ottawa

HKUST. MATH1013 Calculus IB. Directions:

MIDTERM: CS 6375 INSTRUCTOR: VIBHAV GOGATE October,

MA162 EXAM III SPRING 2017 APRIL 11, 2017 TEST NUMBER 01 INSTRUCTIONS:

Formal Conformance Testing 2006

Lecture 5: Sep. 23 &25

COWLEY COLLEGE & Area Vocational Technical School

CS-141 Exam 2 Review October 19, 2016 Presented by the RIT Computer Science Community

ITI Introduction to Computing II

Mathematics Section Released Form DO NOT OPEN THIS BOOKLET UNTIL YOU ARE TOLD TO DO SO.

Queues. Principles of Computer Science II. Basic features of Queues

Math 2114 Common Final Exam May 13, 2015 Form A

Hour Examination # 3

MA EXAM 3 INSTRUCTIONS VERSION 01 April 17, Section # and recitation time

MA EXAM 3 INSTRUCTIONS VERSION 01 April 14, Section # and recitation time

Math 221 Midterm Fall 2017 Section 104 Dijana Kreso

Session-Based Queueing Systems

MA EXAM 3 INSTRUCTIONS VERSION 01 November 8, Section # and recitation time

Math 51 First Exam October 19, 2017

ORF 245 Fundamentals of Engineering Statistics. Final Exam

FINANCIAL ECONOMETRICS AND EMPIRICAL FINANCE -MODULE2 Midterm Exam Solutions - March 2015

YORK UNIVERSITY. Faculty of Science Department of Mathematics and Statistics. MATH C Test #1. October 23, 2013.

Physics 101 Hour Exam 1 March 3, 2014

HWA CHONG INSTITUTION JC2 PRELIMINARY EXAMINATION Wednesday 14 September hours. List of Formula (MF15)

Time: 1 hour 30 minutes

Lecture 14: Nov. 11 & 13

OXFORD CAMBRIDGE AND RSA EXAMINATIONS A2 GCE 4733/01. MATHEMATICS Probability & Statistics 2 QUESTION PAPER

Diagnostic Series XX/vii/MMXVII Version 2


MAT 2377C FINAL EXAM PRACTICE

SDS developer guide. Develop distributed and parallel applications in Java. Nathanaël Cottin. version

10. The GNFA method is used to show that

Academic. Grade 9 Assessment of Mathematics. Spring 2006

Daffodil Spring. by Irena Freeman illustrated by Graham Smith HOUGHTON MIFFLIN HARCOURT

FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING OBJECT ORIENTED PROGRAMMING DATE 07/2014 SESSION 8:00-10:00

AN INTRODUCTION TO PROBABILITY AND STATISTICS

PHYSICS 111 SPRING EXAM 2: March 6, 2018; 8:15-9:45 pm

ME201 ADVANCED CALCULUS MIDTERM EXAMINATION. Instructor: R. Culham. Name: Student ID Number: Instructions

CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018

Physics 101. Hour Exam I Spring Last Name: First Name Network-ID Discussion Section: Discussion TA Name:

Compiling Techniques

Physics 101. Hour Exam I Fall Last Name: First Name Network-ID Discussion Section: Discussion TA Name:

The University of British Columbia Final Examination - April, 2007 Mathematics 257/316

ETA Copyright 2005 by Classroom Products. All rights reserved.

1 Java Night Countdown (30%)

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

Course Announcements. John Jannotti (cs32) Scope, Collections & Generics Feb 8, / 1

Enantiomer Separation

University of Ottawa

Spring 2017 Exam 2 NAME: PIN:

Parsing Algorithms. CS 4447/CS Stephen Watt University of Western Ontario

CS Java. Introduction to Java. Andy Mroczkowski Department of Computer Science Drexel University

Department of Electrical and Computer Engineering University of Wisconsin Madison. Fall Final Examination

Physics 101. Hour Exam 3 Spring Last Name: First Name Network-ID Discussion Section: Discussion TA Name:

CMSC 132, Object-Oriented Programming II Summer Lecture 10:

The University of British Columbia. Mathematics 300 Final Examination. Thursday, April 13, Instructor: Reichstein

Applied Regression Modeling

BSc/MSci MidTerm Test

Transcription:

Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of Engineering School of Electrical Engineering and Computer Science Identification Introduction to Computing II (ITI 1121) MIDTERM EXAMINATION Instructors: Guy-Vincent Jourdan and Marcel Turcotte March 2018, duration: 2 hours Last name: First name: Student #: Seat #: Signature: Section: A or B or C Instructions 1. This is a closed book examination. 2. No calculators, electronic devices or other aids are permitted. (a) Any electronic device or tool must be shut off, stored and out of reach. (b) Anyone who fails to comply with these regulations may be charged with academic fraud. 3. Write your answers in the space provided. (a) Use the back of pages if necessary. (b) You may not hand in additional pages. 4. Do not remove pages or the staple holding the examination pages together. 5. Write comments and assumptions to get partial marks. 6. Beware, poor hand-writing can affect grades. 7. Wait for the start of the examination. Marking scheme Question Maximum Result 1 35 2 15 3 15 4 5 Total 70 All rights reserved. No part of this document may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise without prior written permission from the instructors.

March 2018 ITI 1121 Page 2 of 17 Question 1 (35 marks) This question is about object-oriented programming in Java. Specifically, this is a small part of a software system that you are developing for a supermarket chain. We are focussing on 2 types of goods, books and baskets of nuts, and the part of the software system that computes the price of good and services after taxes for all items sold by the chain, in every province. «GoodsAndServices» + getprice: double Book - year : int - title : String - author : String - price : double + equals : boolean + tostring : String NutsBasket - weight : int - nutstype : String + tostring: String TaxedPrice + ON : + QC : + pricetaxesincluded: double In our software system, every object representing a good or a service, which includes objects of the classes Book and NutsBasket, can be seen as a GoodsAndServices. A GoodsAndServices has a method called getprice, which returns a double value that is the price of that good or service before taxes. Book has 4 instance variables: the price before taxes of the book, of type double, the year of publication, of type int, and then two instances of String for the title and the author of the book. The constructor of the class receives these 4 elements of information as parameters. You need to also include three methods in Book: first, the instance method tostring, which should behave as shown in the example below. Second, the instance method equals. Two books should be considered the same if they have the same title and author, and are published the same year. Finally, for getprice, the price before tax of a book has been received as a parameter to the constructor. NutsBasket has 2 instance variables, the nutstype, of type String, and the weight in grams, which is an int. The constructor of the class receives these 2 elements of information as parameters. The class will also need an implementation of the instance method tostring. In the case of a NutsBasket, the price before taxes is 0.1$ per gram. The Java source code below shows the intended use of the classes and their methods.

March 2018 ITI 1121 Page 3 of 17 Book b1, b2, b3 ; b1 = new Book ( 1 9 9 6, "John Smith", "Java for dummies", 8 5. 0 ) ; b2 = new Book ( 1 9 9 6, "John Smith", "Java for dummies", 4 0. 0 ) ; b3 = new Book ( 2 0 1 0, "Jane Adam", "Python for dummies", 5 0. 0 ) ; System. o u t. p r i n t l n ( b1 ) ; System. o u t. p r i n t l n ( b2 ) ; System. o u t. p r i n t l n ( b3 ) ; System. o u t. p r i n t l n ( b1. e q u a l s ( b2 ) ) ; System. o u t. p r i n t l n ( b1. e q u a l s ( b3 ) ) ; N u t s B a s k e t n1, n2 ; n1 = new N u t s B a s k e t ( "Pistachios", 1 5 0 ) ; n2 = new N u t s B a s k e t ( "Almonds", 4 0 0 ) ; System. o u t. p r i n t l n ( n1 ) ; System. o u t. p r i n t l n ( n2 ) ; The execution of the above program should produce the following output on the console. "Java for dummies" by John Smith, sold for 85.0$ plus taxes "Java for dummies" by John Smith, sold for 40.0$ plus taxes "Python for dummies" by Jane Adam, sold for 50.0$ plus taxes true false basket of Pistachios costing 15.0$ plus taxes basket of Almonds costing 40.0$ plus taxes In the boxes next pages, you need to provide all the code necessary for this to work as described.

March 2018 ITI 1121 Page 4 of 17

March 2018 ITI 1121 Page 5 of 17

March 2018 ITI 1121 Page 6 of 17

March 2018 ITI 1121 Page 7 of 17 Lastly, you need to create a class TaxedPrice. This class is used to have the price of a good or service with taxes included, in various provinces. We will only support 2 provinces at the moment: in Ontario, goods and services are taxed at 13%, and in Quebec, goods and services are taxed at 14,975%. TaxedPrice has a class method pricetaxesincluded that accepts two parameters, the good or service and the province. It returns the price of the good or service, including the taxes for that province. The Java source code below shows the intended use of that class. Book b1 ; b1 = new Book ( 1 9 9 6, "John Smith","Java for dummies", 8 5. 0 ) ; N u t s B a s k e t n1 ; n1 = new N u t s B a s k e t ( "Pistachios", 1 5 0 ) ; System. o u t. p r i n t l n ( "With taxes: " + b1 + " costs " + T a x e d P r i c e. p r i c e T a x e s I n c l u d e d ( b1, T a x e d P r i c e.on) + " in Ontario and " + T a x e d P r i c e. p r i c e T a x e s I n c l u d e d ( b1, T a x e d P r i c e.qc) + " in Quebec." ) ; System. o u t. p r i n t l n ( "With taxes: " + n1 + " costs " + T a x e d P r i c e. p r i c e T a x e s I n c l u d e d ( n1, T a x e d P r i c e.on) + " in Ontario and " + T a x e d P r i c e. p r i c e T a x e s I n c l u d e d ( n1, T a x e d P r i c e.qc) + " in Quebec." ) ; The execution of the above program should produce the following output on the console. With taxes: "Java for dummies" by John Smith, sold for 85.0$ plus taxes costs 96.05 in Ontario and 97.72875 in Quebec. With taxes: basket of Pistachios costing 15.0$ plus taxes costs 16.95 in Ontario and 17.24625 in Quebec. In the box next page, provide the code for the class TaxedPrice.

March 2018 ITI 1121 Page 8 of 17

March 2018 ITI 1121 Page 9 of 17 Question 2 (15 marks) In assignment 1, we introduced the concept of curve fitting through a linear regression. Smoothing is a similar concept, which finds applications in statistics and image processing. Whereas curve fitting uses an explicit function, smoothing gradually changes the values of a data set to remove noise and approximate some unknown function. For the class Smoothing on the next page, implement the class methods printarray and smooth. The method printarray receives the reference of an array of doubles as a parameter, and prints the values of that array as shown in the example below. The method smooth also receives the reference of an array of doubles as a parameter, and smoothes its value, which means that each value will be replaced by the average of the value before, the value itself, and the value after in the array. The first value is replaced by the average of the first value and the second value, and the last value is replaced by the average of the last value and the one before the last. For instance, an array [2.0, 3.0, 1.0, 5.0] will be smoothed into [2.5, 2.0, 3.0, 3.0]. The Java source code below shows the intended use of the class. double [ ] t e s t ; t e s t = new double [ ] { 0. 0, 5. 0, 0. 0, 5. 0 } ; Smoothing. t e s t S m o o t h ( t e s t ) ; t e s t = new double [ ] { 0. 0, 5. 0, 5. 0, 0. 0 } ; Smoothing. t e s t S m o o t h ( t e s t ) ; t e s t = new double [ ] { 0. 0 } ; Smoothing. t e s t S m o o t h ( t e s t ) ; t e s t = new double [ ] { 0. 0, 1. 0 } ; Smoothing. t e s t S m o o t h ( t e s t ) ; t e s t = new double [ ] { 2. 0, 3. 0, 1. 0, 5. 0 } ; Smoothing. t e s t S m o o t h ( t e s t ) ; t e s t = n u l l ; Smoothing. t e s t S m o o t h ( t e s t ) ; The execution of the above program should produce the following output on the console. Running testsmooth on: [0.0, 5.0, 0.0, 5.0] After smoothing: [2.5, 1.6666666666666667, 3.3333333333333335, 2.5] Running testsmooth on: [0.0, 5.0, 5.0, 0.0] After smoothing: [2.5, 3.3333333333333335, 3.3333333333333335, 2.5] Running testsmooth on: [0.0] After smoothing: [0.0] Running testsmooth on: [0.0, 1.0] After smoothing: [0.5, 0.5] Running testsmooth on: [2.0, 3.0, 1.0, 5.0] After smoothing: [2.5, 2.0, 3.0, 3.0] Not a valid value, null, for the method testsmooth. Complete the implementation of the class Smoothing on the next page.

March 2018 ITI 1121 Page 10 of 17 p u b l i c c l a s s Smoothing { p r i v a t e s t a t i c void t e s t S m o o t h ( double [ ] a ) { i f ( a == n u l l ) { System. o u t. p r i n t l n ( "Not a valid value, null, for the method testsmooth." ) ; return ; } System. o u t. p r i n t ( "Running testsmooth on: " ) ; p r i n t A r r a y ( a ) ; smooth ( a ) ; System. o u t. p r i n t ( "After smoothing: " ) ; p r i n t A r r a y ( a ) ; } p r i v a t e s t a t i c void p r i n t A r r a y ( double [ ] a ) { }

March 2018 ITI 1121 Page 11 of 17 p r i v a t e s t a t i c void smooth ( double [ ] a ) { } }

March 2018 ITI 1121 Page 12 of 17 Question 3 (15 marks) For the class StackInspector on the next page, complete the implementation of the method findlast(e elem). The method findlast returns the index of the last occurrence of the specified element in the stack. If there is more than one occurrence, the last occurrence is the one closest to the bottom of the stack. This is also the one with the highest index. The method returns -1 if the stack does not contain the element. The value of the index increases from top to bottom. The index of the top element is 0. The method findlast does not change the state of the stack. That is before and after a call to the method, the stack must contain the same elements, in the same order. The value null is not a valid value for the parameter elem. The example below illustrates the behaviour of the method findlast. Stack <S t r i n g > s t a c k ; s t a c k = new S t a c k I m p l e m e n t a t i o n <S t r i n g > ( ) ; s t a c k. push ( "one" ) ; s t a c k. push ( "two" ) ; s t a c k. push ( "one" ) ; s t a c k. push ( "two" ) ; s t a c k. push ( "three" ) ; S t a c k I n s p e c t o r <S t r i n g > i n s p e c t o r ; i n s p e c t o r = new S t a c k I n s p e c t o r <S t r i n g >( s t a c k ) ; System. o u t. p r i n t l n ( i n s p e c t o r. f i n d L a s t ( "one" ) ) ; System. o u t. p r i n t l n ( i n s p e c t o r. f i n d L a s t ( "two" ) ) ; System. o u t. p r i n t l n ( i n s p e c t o r. f i n d L a s t ( "three" ) ) ; System. o u t. p r i n t l n ( i n s p e c t o r. f i n d L a s t ( "four" ) ) ; Executing the above Java code produces the following output on the console. 4 3 0-1 For this question, there is class called StackImplementation that implements the interface Stack. An instance of the class StackImplementation can store an arbitrarily large number of elements. You do not need to write its implementation, it has been provided to you.

March 2018 ITI 1121 Page 13 of 17 p u b l i c c l a s s S t a c k I n s p e c t o r <E> { p r i v a t e Stack <E> s t a c k ; p u b l i c S t a c k I n s p e c t o r ( Stack <E> s t a c k ) { t h i s. s t a c k = s t a c k ; } }

March 2018 ITI 1121 Page 14 of 17 / S t a c k A b s t r a c t Data Type. A S t a c k i s a l i n e a r data s t r u c t u r e f o l l o w i n g l a s t in f i r s t o u t p r o t o c o l, i. e. t h e l a s t e l e m e n t t h a t has been added onto t h e Stack, i s t h e f i r s t one t o be removed. / p u b l i c i n t e r f a c e Stack <E> { } / T e s t s i f t h i s S t a c k i s empty. @return t r u e i f t h i s S t a c k i s empty ; and f a l s e o t h e r w i s e. / boolean isempty ( ) ; / R e t u r n s a r e f e r e n c e t o t h e t o p e l e m e n t ; does n o t change t h e s t a t e o f t h i s S t a c k. @return The t o p e l e m e n t o f t h i s s t a c k w i t h o u t removing i t. / E peek ( ) ; / Removes and r e t u r n s t h e e l e m e n t a t t h e t o p o f t h i s s t a c k. @return The t o p e l e m e n t o f t h i s s t a c k. / E pop ( ) ; / Puts an e l e m e n t o nto t h e t o p o f t h i s s t a c k. @param e l e m e n t t h e e l e m e n t be p u t onto t h e t o p o f t h i s s t a c k. / void push ( E e l e m e n t ) ;

March 2018 ITI 1121 Page 15 of 17 Question 4 (5 marks) You will find below an expression written in the postfix format. Using the algorithm seen in class, you need to give the corresponding expression written in the infix format. 4 3 7 6 2 4 + /

March 2018 ITI 1121 (blank space)

March 2018 ITI 1121 (blank space)