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

Similar documents
Introduction to Computer Science Midterm 3 Fall, Points

Solutions to the 2005 exam

Introduction to Computer Science II (CSI 1101)

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

COS 126 General Computer Science Fall Exam 1

ITI 1120 Lab #9. Slides by: Diana Inkpen, Alan Williams, Daniel Amyot Some original material by Romelia Plesa

Computer Programming, I. Laboratory Manual. Final Exam Solution

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

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

Question: Total Points: Score:

COS 126 General Computer Science Spring Written Exam 1

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

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

Programming with Java

JAVA OPERATORS GENERAL

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

CSE351 Winter 2016, Final Examination March 16, 2016

Final Exam. COMP Summer I June 26, points

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Largest Online Community of VU Students

CSE 1223: Exam II Autumn 2016

COSC 1010 Introduction to Computer Programming

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

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi...

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014

Final Exam COMP Fall 2004 Dec 16, 2004

CS302: Self Check Quiz 2

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

COS 126 Midterm 1 Written Exam, Fall 2009

CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, Name:

I. True/False: (2 points each)

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

PROGRAMMING FUNDAMENTALS

Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

Code No: R Set No. 1

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Sample Examination Paper Programming and Software Development

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

COMPUTER APPLICATIONS

Data Structure (CS301)

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

CONCORDIA UNIVERSITY Summer 2005 Comp 248 /1 Section AA Introduction to Programming Final Examination/A

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

Last Name: Circle One: OCW Non-OCW

This exam is open book. Each question is worth 3 points.

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

Prof. Navrati Saxena TA: Rochak Sachan

The Java language has a wide variety of modifiers, including the following:

Use the Scantron sheets to write your answer. Make sure to write your Purdue ID (NOT Purdue Login ID) and your name on the Scantron answer sheet.

CIS 110 Introduction to Computer Programming Summer 2014 Final. Name:

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

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

INTRODUCTION TO SOFTWARE SYSTEMS (COMP1110/COMP1140/COMP1510/COMP6710)

Arrays Classes & Methods, Inheritance

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Good Luck! CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none. Student Number:

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

Place your name tag here

York University AK/ITEC INTRODUCTION TO DATA STRUCTURES. Final Sample II. Examiner: S. Chen Duration: Three hours

Course Outline. Introduction to java

CS2 Practical 1 CS2A 22/09/2004

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm

CS 101 Fall 2006 Midterm 3 Name: ID:

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

CSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

Building Java Programs

STUDENT LESSON A12 Iterations

Final Exam Practice. Partial credit will be awarded.

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Problem Points Score Grader Total 75

Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination

Following is the general form of a typical decision making structure found in most of the programming languages:

CS111: PROGRAMMING LANGUAGE II

Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015

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

CSE 142 Su 04 Computer Programming 1 - Java. Objects

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

BASIC ELEMENTS OF A COMPUTER PROGRAM

COS 126 General Computer Science Fall Programming Exam 2

Building Java Programs

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

General Instructions. You can use QtSpim simulator to work on these assignments.

Computer Programming : C++

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

CS 132 Midterm Exam Fall 2004

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

Logical Operators and switch

Transcription:

CSI 1100 / 1500 Final Examination Page 1 of 13 CSI 1100 / 1500 Fall 2004 Introduction to Computer Science I Final Examination Duration : 3 hours 09:30 December 9, 2004 Professors: Alan Williams, Daniel Amyot Page 1 of 13 Full name (please print): Student number: Instructions please read carefully! Fill out the identification information above in ink. This exam is closed-book. No books, papers, calculators, or other electronic devices are permitted. There are 7 questions in this exam, some of which have sub-parts. Answer the questions in the space provided. Answers written in pencil will not be re-graded even if there is a marking error. The marks allocated to each question are provided. Not all questions are worth the same, so plan your time accordingly. The exam has 100 marks in total, which represents 55% of your final grade. Algorithms in pseudocode should use the format from the course notes. You can use the back of pages for calculations and rough work, as well as page 12. Pages 12 and 13 can be detached and will not be graded. Les réponses en français sont acceptées. Question Marks Marks received Question Marks Marks received 1 12 5 15 2 8 6 25 3 15 7 10 4 15 Total 100

CSI 1100 / 1500 Final Examination Page 2 of 13 Question 1A) (4 marks) In this question, use only the following (pseudocode) Boolean expressions: comparison operators: <, >, =, and Boolean connectors: NOT, AND, OR arithmetic operators: +, -, *, /, and MOD (modulo) variable names and constants. Use parentheses where necessary. Do not use Java syntax! Environment Canada will report a humidex value as part of a weather forecast if the temperature (T) is greater than or equal to 30 degrees, if the temperature is greater than or equal to 25 degrees and the humidity (H) is greater than 35%, or the temperature is greater than or equal to 20 degrees and the humidity is greater than or equal to 65%. Write a Boolean expression that is true if Environment Canada will report a humidex value, and false otherwise. Answer: Question 1B) (4 marks) Consider the following Java program : MyClass[] obj; int index; obj = new MyClass[2]; index = 15; while( index > 2 ) obj[index % 2] = new MyClass( ); index = index / 2; // Line X i) How many instances of MyClass are created during the execution of this program? (2 marks) Answer: ii) How many instances of MyClass are still accessible at Line X? (2 marks) Answer:

CSI 1100 / 1500 Final Examination Page 3 of 13 Question 1C) (4 marks) Consider the following classes: class Foo private int x1; public static int x2; public static Bar x3; public Foo(int x4)... class Bar public int x5; public static int x6()... public Foo x7()... Suppose that the following instructions are used in the main() method in a class Test. Each choice should be considered independently as it if were in its own main() method. Circle the letter of the statement which causes a compilation error. (a) (b) (c) (d) (e) Foo[] a = new Foo[5]; a[4] = new Foo(-1); Foo f = Bar.x7(); Foo.x2 = Bar.x6(); int k = Foo.x3.x5; Bar b = new Bar(); Foo f = b.x7();

CSI 1100 / 1500 Final Examination Page 4 of 13 Question 2: (8 marks) Here is a program that uses recursion. class Football public static void main(string[ ] args) char[] t = G, e, e, -, G, e, e ; Rec(t, t.length - 1); public static void Rec(char[] var, int i) if (i < 0) ; // do nothing else if ( (var[i] > A ) && (var[i] < Z ) ) System.out.print( (char) (var[i] - A + a ) ); else if ( (var[i] > a ) && (var[i] < z ) ) System.out.print( (char) (var[i] - a + A ) ); else ; // do nothing Rec(var, i - 1); What is printed during the execution of the method main in this class Answer :

CSI 1100 / 1500 Final Examination Page 5 of 13 Question 3: (15 marks) Translate the algorithm on page 13 to a Java method.

CSI 1100 / 1500 Final Examination Page 6 of 13 Question 4: (15 marks) Olympic 10 metre platform diving events are scored as follows. Each judge watches an athlete s dive, and then submits a score for the dive (out of 10). The dive is also previously assigned a "degree of difficulty" (DD) based on the complexity of the particular dive (example: forward 2 1/2 somersault in the tuck position has DD = 2.7). The highest and lowest scores are discarded, and the remaining scores are added together and then multiplied by the degree of difficulty to determine the total dive score. Write an algorithm that will compute an athlete s total dive score from an array of scores submitted by N judges, for a dive of degree of difficulty DD. Remember to include comments with your algorithm!

CSI 1100 / 1500 Final Examination Page 7 of 13 Question 5: (15 marks) The lower right sub-matrix of a matrix is formed by selecting one element position (row and column) and excluding all elements that are to the left or above the selected element. For example, in the matrix M below, if we select M 11 = 5, the matrix S is the lower right sub-matrix. 1 2 3 5 6 M = 4 5 6 S = 7 8 9 8 9 Write a Java method that will take a matrix of integers M, and a row and column index, and returns a new matrix that is the lower right sub-matrix of M formed from that position. The header of the method is as follows: public static int[][] submatrix( int[][] m, int therow, int thecol )

CSI 1100 / 1500 Final Examination Page 8 of 13 Question 6: (25 marks) In this question, you will create a class Experiment that represents a record of some sort of scientific experiment. In order to verify that the results of an experiment are repeatable, there is a class Trial that contains the results from one run of an experiment. An experiment will then include a number of Trial objects. The class Trial stores a result that was measured during an experiment, and the duration that the experiment took, measured in milliseconds. The class Trial has already been implemented. A UML class diagram for the class Trial is as follows: - result : double - duration: int Trial + Trial( theresult : double, theduration : double ) + getresult( ) : double + getduration( ) : int On the next two pages, you will fill in the methods for Experiment. Your Experiment class should provide four public methods and/or constructors that would permit the following class TestExperiment to execute: class TestExperiment public static void main (String[] args) Experiment anexperiment; anexperiment = new Experiment( 2 ); anexperiment.addtrial( new Trial( 99.1, 10000 ) ); anexperiment.addtrial( new Trial( 97.1, 11000 ) ); anexperiment.addtrial( new Trial( 94.1, 12000 ) ); Experiment.setPredictedResult( 98.6 ); anexperiment.print(); Executing main() would result in the following being printed on the screen : No more trials can be added to the experiment. Trial 0: Result 99.1, duration 10000 (within 0.5 of prediction) Trial 1: Result 97.1, duration 11000 (within 1.5 of prediction)

CSI 1100 / 1500 Final Examination Page 9 of 13 Question 6: (continued) Complete the Class Experiment on this page and the next. class Experiment // FIELD DECLARATION(S): (4 marks) // CONSTRUCTOR: (5 marks) // Takes one integer parameter representing the maximum number of trials that can be put into // the experiment. // METHOD setpredictedresult: (4 marks) // Method parameters: a double that is the predicted result of the experiment. // Result: none

CSI 1100 / 1500 Final Examination Page 10 of 13 Question 6: (continued) // MODIFIER METHOD addtrial: (6 marks) // Method parameters: a Trial object that should be added to the Experiment. // Results: will print a message if the experiment has no room to store additional trials // (see page 8 for message format) // Modified: the Experiment object // METHOD print: (6 marks) // Method parameters: (none) // Returns: (none) // This method prints the result and duration of each trial, along with the absolute value // of the difference from the predicted result. // See the TestExperiment sample output on Page 8 for exact format. // End of class Experiment

CSI 1100 / 1500 Final Examination Page 11 of 13 Question 7: (10 marks) Suppose that you have an array of integers that is already known to be sorted in ascending order, and to contain no duplicate values. A binary search on such an array is done by locating the middle element of an array and comparing the search value with that element. If we have not found the value for which we are searching, we can choose the appropriate sub-interval (either the left or the right side) to restrict the search. Write a recursive method that will perform a binary search on an array a for the value findme between positions startindex and endindex. You can assume that both positions are less than the length of the array. The method should return true if the value is contained in the array, and false otherwise. The header of the method should be the following: public static boolean binarysearch(int[] a, int findme, int startindex, int endindex)

CSI 1100 / 1500 Final Examination Page 12 of 13 This page is for calculations and other work, and can be detached. This page will not be marked.

CSI 1100 / 1500 Final Examination Page 13 of 13 Algorithm for Question 3 (this page can be detached) GIVENS: Base: (a logarithm base, known to be > 0) Operand: (an array of integers for which to find the integer logarithm) N (the number of values in array Operand) RESULT: IntLog: INTERMEDIATES: Index Value Count (an array of N integer logarithms for the values in array Operand; a value of -1 is returned if the logarithm does not exist) (array index) (used for repeated divisions) (counts number of times an operand can be divided by base) HEADER: IntLog Logarithms( Base, Operand, N ) BODY: