Introduction to Computer Science II (CSI 1101)

Similar documents
Introduction to Computer Science II (CSI 1101) Midterm Examination

Introduction to Computer Science II (ITI 1121) Midterm Examination

Introduction to Computer Science II (CSI 1101) Midterm Examination

Introduction to Computing II (ITI 1121) Final Examination

Introduction to Computer Science II (ITI 1121) Midterm Examination

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Introduction to Computing II (ITI 1121) Midterm Examination

Introduction to Computing II (ITI 1121) Midterm Examination

Introduction to Computer Science II (ITI 1121) Final Examination

Introduction to Computing II (ITI 1121) Final Examination

CSI 1100 / 1500 Fall 2004 Introduction to Computer Science I Final Examination

Introduction to Computer Science II (CSI 1101) Final Examination

CSC 207H Fall L Java Quiz Duration 25 minutes Aids allowed: none

York University AK/ITEC OBJECT-BASED PROGRAMMING. Midterm Test Sample. Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes

Largest Online Community of VU Students

Use the scantron sheet to enter the answer to questions (pages 1-6)

Practice Midterm 1. Problem Points Score TOTAL 50

Data Structure (CS301)

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

University of Palestine. Mid Exam Total Grade: 100

COS 126 General Computer Science Spring Written Exam 1

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Final Exam. COMP Summer I June 26, points

JAVA Programming Language Homework II Student ID: Name:

Exam 1 - (20 points)

University of Massachusetts Amherst, Electrical and Computer Engineering

SOLUTIONS (INCOMPLETE, UNCHECKED)

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Ryerson University Department of Electrical & Computer Engineering COE618 Midterm Examination February 26, 2013

Arrays. COMS W1007 Introduction to Computer Science. Christopher Conway 10 June 2003

CSCI 111 Midterm Spring 2014

Comp Intermediate Programming EXAM #1 February 16, 2004 Rice University - Instructors: Cox & Nguyen

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

ITI Introduction to Computing II

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination

COS 126 Written Exam 2, Fall 2009

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

Programming Problems 22nd Annual Computer Science Programming Contest

CSE 11 Midterm Fall 2008

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

MIDTERM REVIEW. midterminformation.htm

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

CS 101 Spring 2006 Final Exam Name: ID:

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

COS 226 Algorithms and Data Structures Fall Midterm

Programming overview

York University. AP/ITEC Section M INTRODUCTION TO DATA STRUCTURES Winter Midterm Test

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

I. True/False: (2 points each)

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

CIS 110 Introduction to Computer Programming Summer 2017 Final. Recitation # (e.g., 201):

COMP 401 Spring 2014 Midterm 1

Solutions Manual. Data Structures and Algorithms in Java, 5th edition International Student Version. M. T. Goodrich and R.

York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total

The University of Nottingham

Good Luck! CSC207, Fall 2012: Quiz 3 Duration 25 minutes Aids allowed: none. Student Number: Lecture Section: L0101. Instructor: Horton

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

Understanding class definitions

CSSE SEMESTER 1, 2017 EXAMINATIONS. CITS1001 Object-oriented Programming and Software Engineering FAMILY NAME: GIVEN NAMES:

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

ITI Introduction to Computing II

HALF-YEARLY EXAMINATIONS FEBRUARY Subject: Computing Form: 4 Time: 1 ½ hours MARKING SCHEME

Midterm Examination # 2 Wednesday, March 19, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

CS171 Midterm Exam. October 29, Name:

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

CS 3114 Data Structures and Algorithms READ THIS NOW!

CS 113 MIDTERM EXAM 2 SPRING 2013

I have neither given nor received any assistance in the taking of this exam.

Java Fundamentals (II)

CS 132 Midterm Exam Winter 2002

CS 61B, Spring 1999 MT3 Professor M. Clancy

Fall 2002 Page 1 of 9 READ THIS NOW!

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION /5:30-7:00

AP CS Unit 6: Inheritance Notes

Midterm assessment Spring The Solution

ITI Introduction to Computing II

Declarations and Access Control SCJP tips

CMPSCI 187 Midterm 1 (Feb 17, 2016)

CS 101 Exam 2 Spring Id Name

SFWR ENG/COMP SCI 2S03 Principles of Programming SOLUTIONS

Introduction to Programming (CS112): Sample

CS180. Exam 1 Review

Final Exam. Kenneth J. Goldman December 18, Name: Student ID Number: Signature:

ITI Introduction to Computing II

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

CS 132 Midterm Exam Spring 2004

Examination Questions Midterm 1

School of Informatics, University of Edinburgh

COS 126 Written Exam 2 (Spring 2015)

Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007

ECSE 321 Assignment 2

CS 101 Fall 2006 Midterm 3 Name: ID:

Transcription:

Introduction to Computer Science II (CSI 1101) Professor: M. Turcotte February 2002, duration: 75 minutes Identification Student name: last name: Section: Student number: initials: Signature: Instructions 1. This is a closed book examination. 2. No calculators or other aids are permitted. 3. Write your answers in the space provided. Use the backs of pages if necessary. You may not hand additional pages. 4. Write comments and assumptions to get partial marks. 5. Beware, poor hand writing can affect grades. 6. Do not remove the staple holding the examination pages together. 7. This midterm test is worth 30% of the grade. Marking scheme Question Maximum Marks 1 12 2 18 3 20 4 15 5 15 Total 80

February 2002 CSI 1101 Page 2 of 12 Question 1 (12 marks) Given the following class definitions: public class AAA { private int a = 1; public int get () { return a; public class BBB extends AAA { private int b = 2; public int get () { return b; public class CCC extends AAA { private int c = 3; public int get () { return c; (a) Which of the following declarations are valid? i) AAA a1 = new BBB(); ii) AAA a2 = new AAA(); iii) BBB a3 = new AAA(); iv) CCC a1 = new BBB(); (b) Give the value of x and y after the execution of the following sequence of statements: AAA o1 = new CCC (); CCC o2 = (CCC) o1; int x,y; x = o1.get (); y = o2.get ();

February 2002 CSI 1101 Page 3 of 12 Question 2 (18 marks) Given the following class hierarchy, where an ApartmentHouse and a House are specializations of a Building: Building ApartmentHouse House Knowing that: 1. all buildings have an address (a character string) 2. all buildings have a resale price (an integer) 3. the apartment houses have a number of apartments (an integer) 4. the houses have a swimming pool or not (a boolean) 5. all buildings are taxed by their city 6. the tax amount for an apartment house is equal to the resale price divided by the number of apartments. 7. the tax amount for a house is calculated as the resale price divided by 100, plus $100 for houses having a swimming pool. (a) Write these three classes in Java including the constructors and the methods that are necessary to calculate the tax amount to be payed for a building (10 marks).

February 2002 CSI 1101 Page 4 of 12 Question 2 (continued)

February 2002 CSI 1101 Page 5 of 12 Question 2 (continued) (b) Declare an array, called city, to hold up to 100 buildings (3 marks). (c) Knowing there are n buildings in the array city, write a for loop allowing to calculate the total amount of the taxes that these buildings will have to pay (5 marks).

February 2002 CSI 1101 Page 6 of 12 Question 3 (20 marks) Given a class Time with the following instance method: boolean before (Time t); which returns true if this time occurs before the time t. Also, given a Time linked list whose nodes are defined as follows: private class Node { Time value; Node next; Node (Time value, Node next) { this.value = value; this.next = next; Write an instance method that has the following declaration: public boolean isincreasing (); and returns true if each Time element of the list occurs before the Time element that immediately follows it in the list. You can assume there exist an instance varialble called head that refers to the first element of the list. The empty list and the singleton list are considered to be increasing.

February 2002 CSI 1101 Page 7 of 12 Question 3 (continued)

February 2002 CSI 1101 Page 8 of 12 Question 4 (15 marks) What will be printed on the screen if the method main of the class Lis, presented in the following pages, is executed? Read carefully all the methods before answering!

February 2002 CSI 1101 Page 9 of 12 public class Lis { private Object[] obj; private int n = 0; public Lis (int capinit) { obj= new Object[capInit]; public int dim() { return n; public void ajouteadd (Object ob) { if (n >= obj.length) { Object[] tmp= obj; obj= new Object[tmp.length * 3 / 2]; for (int i=0; i<n; i++) { obj[i]= tmp[i]; obj[n++]= ob; public void enleveremove() { if (n == 0) return; obj[--n] = null; if (n < obj.length/2) { Object[] tmp = obj; obj = new Object[1+tmp.length/2]; for (int i=0; i<n; i++) { obj[i]= tmp[i];

February 2002 CSI 1101 Page 10 of 12 public void affichedisplay () { for (int i=0; i<obj.length; i++) { if (obj[i] == null) System.out.println ("[" + i + "] = null"); else System.out.println ("[" + i + "] = " + obj[i]); public static void main (String[] arg) { Lis test = new Lis (4); test.ajouteadd ("paul"); test.ajouteadd ("eve"); test.ajouteadd ("sam"); System.out.println ("a)"); test.affichedisplay (); test.ajouteadd ("tim"); test.ajouteadd ("amanda"); System.out.println ("b)"); test.affichedisplay (); test.enleveremove (); test.enleveremove (); test.enleveremove (); System.out.println ("c)"); test.affichedisplay ();

February 2002 CSI 1101 Page 11 of 12 Question 5 (15 marks) Write a new method for the class Lis, described in the previous question, that removes duplicated elements from the list. For example, if the list contains the following character strings: "paul" "paul" "eve" "paul" "eve" "paul" "tim" A call to the new method, called removeduplicates, would change the list to: "paul" "eve" "tim" The strategy to be used is as follows: 1. A new array is created 2. For each element in the old array, check if an equivalent element already exists in the new array: (a) If not, this element is added at the end of the new array (b) If yes, this element is not added and the method proceeds with the next element 3. The new array becomes the array of the list Lis. Fill in the missing elements in the method removeduplicates below: public void removeduplicates () { Object[] tmp = obj; obj = new Object[tmp.length]; int last = 0; for (int i=0; ; i++) { boolean found = false; for (int j=0; j < last &&!found; j++) { if (tmp[i].equals( )) found = true; if (! found) { obj[ ] = tmp[ ]; last++; ;

February 2002 CSI 1101 Page 12 of 12 (blank space)