Computer Science 1 Bh

Size: px
Start display at page:

Download "Computer Science 1 Bh"

Transcription

1 UNIVERSITY OF EDINBURGH course CS0077 FACULTY OF SCIENCE AND ENGINEERING DIVISION OF INFORMATICS SCHOOL OF COMPUTER SCIENCE Computer Science 1 Bh Degree Examination Specimen Solutions Date: Saturday 26th May 2001 Time: 12:00 13:30 (one and a half hours) Place: Roxburgh Place Room: Halls A and B Board of examiners Chair: Stuart Anderson External Examiner: Muffy Calder Notes about Specimen Solutions 1. These specimen solutions are issued for guidance only, to help as a revision aid. They do not represent a complete picture of how the exam was marked; they are specimen solutions, not a marking guide. 2. The solutions typically present one answer from a set of possible answers. Often, answers which have alternative wording or different technical details are equally acceptable. 3. If you have any questions concerning these solutions, please contact the course organiser. Please note that the course organiser will not be able to answer questions about the marking of the exam.

2 Question 1 Suppose we have a program which implements the following class hierarchy fragment: ClassA / \ ClassB ClassC / \ ClassD ClassE Suppose further that we have five variables declared and assigned by this program: ClassA a = new ClassA(); ClassB b = new ClassB(); ClassC c = (classc) (new ClassE()); ClassD d = null; ClassE e = new ClassE(); Fill in the result of executing the following program fragments. If you think that the Java compiler will reject the fragment, write does not compile. Remember that the Java compiler knows the class hierarchy and will reject programs where the types are always incompatible, whatever the run-time value of variables. System.out.println(a instanceof ClassA); true System.out.println(a instanceof ClassB); false System.out.println(b instanceof ClassA); true System.out.println(b instanceof ClassC); does not compile System.out.println(c instanceof ClassA); true System.out.println(c instanceof ClassB); does not compile System.out.println(c instanceof ClassE); true System.out.println(d instanceof ClassD); false System.out.println(d instanceof Object); false System.out.println(e instanceof Object); true Page 1 of 13

3 Question 2 A library class ArrayBinaryTree has an array field a declared by: private Object a[]; This array is used to represent a binary search tree of objects. The public methods of ArrayBinaryTree ensure that the tree is always balanced, which means that it has the smallest depth possible for a given number of elements stored in the tree. The tree is arranged in the array like this: a[0] a[1] a[2] a[3] a[4] a[5] a[6] If the tree does not have a node at a particular position, then the corresponding element in the array is null. i. The diagram shows an array big enough to hold a tree with up to 7 elements. If the number of elements stored in the tree is n, what is the size of the array needed? [2 marks] 2 log n +1 1 ii. Show, as trees, the possible ways of storing the integers 1, 2, 3, 4, 5, 6 in an ArrayBinaryTree object. [3 marks] / \ / \ / \ / \ / / \ \ / \ / \ \ / \ / iii. Write a method findleast which returns the integer index of the least element in the tree, making use of the binary search tree property. You may assume that the tree always has at least one node. [5 marks] Here is one possible solution. The counter i counts powers of 2. Since the array has at least the first position non-null, the result is 0 or more. class ArrayBinaryTree { Object a[]; public int findleast() { int i = 1; while ((i-1) < a.length && a[i-1]!= null) { i *= 2; return i/2-1; Page 2 of 13

4 Question 3 (a) This question concerns interfaces in Java. Recall that the purpose of an interface is to describe some methods which are to be implemented by a class. i. All methods in an interface are abstract. What does this mean? An abstract method is one which has no body, in other words, no implementation. ii. Since all methods are abstract, what else should be provided to explain an interface? An essential part of an interface is some accompanying documentation or comments to describe the purpose of the methods. iii. Show how you would write the standard Comparable interface in Java, which declares the compareto method. This method takes an object parameter and returns an integer, defining an ordering relation on objects in a class. [3 marks] public interface Comparable { // Compares this object with the specified object for order. // Returns a negative integer, zero, or a positive integer // as this object is less than, equal to, or greater than // the specified object. public int compareto(object o); (b) This question concerns abstract classes in Java. i. What is the difference between an abstract class and an ordinary class? Non- An abstract class is a class which contains at least one abstract method. abstract classes must provide implementations of all their methods. ii. Show how you would write an abstract class AbstractReverseComparable which implements the Comparable interface and contains a concrete definition of a method reversecompareto method in terms of compareto, which reverses the sense of the compareto comparison. This means that if a.compareto(b) = 1, then a.reversecompareto(b) = 1, and similarly for 1 and 1. [4 marks] abstract class AbstractReverseComparable implements Comparable { abstract public int compareto(object o); public int reversecompareto(object o) { return -1 * compareto(o); Page 3 of 13

5 Question 4 (a) Client-server systems require a method of identification of particular services on particular hosts. What is the naming and numbering system which is used for this identification? How are connections between hosts implemented in the Java programming language? [5 marks] Hosts are identified using their numeric network address (in the case of an IP network this might be ) or its host name e.g. scar.dcs.ed.ac.uk. The textual form of the name will be translated to the network address by a domain name service (DNS). Additionally each service that the host provides is associated with a port number. Java programs can connect to particular services using Socket objects initialised with the host s name and port number. e.g. Socket sock = new Socket ("scar.dcs.ed.ac.uk", 5055); (b) A Java program in the client-server model passes in turn each element of an array of messages (msgs) from the client to the server. The server acknowledges all non-empty messages. As usual, the server s input stream (serverin) is the client s output stream (serverout) and the client s input stream (clientin) is the server s output stream (clientout). An extract of the code is shown below. On the Server: On the Client: while (line!= null) { for (int i = 0 ; i < msgs.length ; i++) { if (line.equals("")) { serverout.println(msgs[i]); // ignore empty lines serverout.flush(); else { System.out.println(clientIn.readLine()); System.out.println (line); clientout.println("acknowledged"); clientout.flush(); line = serverin.readline(); After the system has been in use for some time an error occurs. What do you think is the likely error? How are these sorts of errors usually dealt with in client-server systems? [5 marks] The client sends a message to the server and then waits for a reply. The server waits for a message and the then sends an acknowledgement. If either the client s message or the server s response was lost by the network both server and client would be stuck waiting indefinitely for a message from the other. This situation is called deadlock. The usual way of avoiding deadlock in client-server systems is to place a limit (called a timeout) on how long the program will wait before taking some kind of corrective action, such as resending its last message. Page 4 of 13

6 Question 5 (a) Provide an equivalent Java byte code version for the Java method below. [Hint: you should use the instructions iconst, ifge, iload and ireturn.] [3 marks] \textit{int minabs (\textit{int x) \ttlbrace\\ \textbf{if (x < 0)\\ \textbf{return 0;\\ \textbf{else\\ \textbf{return x;\\ \ttrbrace Method int minabs(int) 0 iload_1 1 ifge 4 2 iconst_0 3 ireturn 4 iload_1 5 ireturn (b) Consider a Java virtual machine which has the following values in memory and on the stack. 1 2 memory stack 2 Giving this starting state, show the intermediate states of the memory and the stack as each instruction is executed. [7 marks] 1 imul 2 istore 1 3 iload 2 4 iinc istore 2 6 iconst 1 7 istore 2 1. M: 5 4 S: 6 2. M: 6 4 S: 3. M: 6 4 S: 4 4. M: 6 5 S: 4 5. M: 6 4 S: 6. M: 6 4 S: 1 7. M: 6 1 S: Page 5 of 13

7 Question 6 (a) You are to implement the graphical interface of a Java program to play chess. Your interface is to draw a chessboard as shown below, made up of alternating black and white squares. The frame in which the chessboard is to be drawn is pixels, so each of the black and white squares above measures pixels. Recall that the Color class provides the constants Color.white and Color.black and a graphics context Graphics g provides the following methods: public void setcolor (Color c) public void fillrect (int x, int y, int width, int height) Using these ingredients, provide an implementation of the paint() method for a class which displays the chessboard. [6 marks] public void paint(graphics g) { for (int x = 0 ; x < 8 ; x++) { for (int y = 0 ; y < 8 ; y++) { if ((x + y) % 2 == 0) g.setcolor(color.white); else g.setcolor(color.black); g.fillrect(x * 100, y * 100, 100, 100); (b) The program needs to register mouse clicks in the frame in order to identify the squares on the chessboard by their row and column position. These positions are used to index into a two-dimensional array of ChessPiece objects and so their values are to range between 0 and 7. Implement the method public void mousepressed(mouseevent e) for the MouseAdapter class listening for these mouse clicks. Recall that the MouseEvent class provides methods getx() and gety(). Update the int variables row and column accordingly. [4 marks] public void mousepressed(mouseevent e) { row = e.gety() / 100; column = e.getx() / 100; System.out.println("row = " + row); System.out.println("column = " + column); Page 6 of 13

8 Question 7 (a) Briefly describe the four steps you would undertake in debugging a program. [4 marks] 1. Test the program to detect any incorrect behaviour. 2. Identify the cause of the error. 3. Redesign the program to remove the error. 4. Implement the new design. Repeat the above cycle until no more errors are detected, and after every change to the program. [ Question continues on next page ] Page 7 of 13

9 (b) The method given below is intended to find the number that is the minimum of all the numbers in the Vector v that are larger than the minimum of the elements in v. You may assume that v contains at least two elements, and that that the first two elements are different numbers. 1 int second (Vector v) { 2 int min; 3 int secmin; 4 5 if (((Integer)v.elementAt(0)).intValue()<= 6 ((Integer)v.elementAt(1)).intValue()){ 7 min = ((Integer)v.elementAt(0)).intValue(); 8 secmin = ((Integer)v.elementAt(1)).intValue(); 9 else { 10 min = ((Integer)v.elementAt(1)).intValue(); 11 secmin = ((Integer)v.elementAt(0)).intValue(); for (int i = 2; i < v.size(); i++) { 15 if (((Integer)v.elementAt(i)).intValue() <= min) { 16 int tmp = min; 17 min = ((Integer)v.elementAt(i)).intValue(); 18 secmin = tmp; 19 else if (((Integer)v.elementAt(i)).intValue() <= secmin) { 20 secmin = ((Integer)v.elementAt(i)).intValue(); return secmin; 24 i. Describe a vector of Integers that will give the correct result using the above method. [2 marks] 1, 2, 3, 4 ii. Describe a vector of Integers that will give incorrect results using the above method. [2 marks] 1, 2, 1, 1 iii. Outline how you would go about repairing the fault in the program so it would give correct results with both your tests. [2 marks] Change the tests at lines 15 and 19 to strict inequalities. Page 8 of 13

10 Question 8 Consider the following brief description of the Informatics Teaching Office (ITO): The ITO maintains information about each student taking a taught course in the Division of Informatics. Each student follows a programme of studies comprising a collection of individual courses and for each course an assessment record is maintained. Each student s director of studies maintains oversight over the selection of courses and the students progress. An analyst has begun to build a class model for this system and has identified: Student, Programme, Course, Assessment and DoS have been identified as class names in building the class model. (a) Explain what is meant by an association and how associations are used to make a more elaborate class model. Illustrate your answer by identifying some associations between the classes identified in the question. [3 marks] Associations between classes represent relationships between the entities represented by the classes. They frequently describe the way the classes will interact with each other. Examples from above: Student is directed by a DoS Student follows a Programme Course is part of a Programme (b) Explain how you might go about validating a class model. Use the example above to illustrate your answer. [3 marks] One method of validating a class model is to check the multiplicities of the associations. For example in the above we each Student should have exactly one DoS, while each DoS may have many Students. Our model should enforce these limits. Another method is the use of CRC cards. Each class get a card which lists its responsibilities and the other classes it collaborates with to carry them out. By role playing with the cards we can determine if the model allows each class to carry out its responsibilities. For example each DoS must oversee the course selection of their Students. Therefore the model should include an association between DoS and Course. (c) The DoS has the responsibility to check students they supervise are making satisfactory progress. Describe, using the classes identified above and the associations you have identified, how a DoS can carry out this responsibility. You may identify additional associations if necessary. [2 marks] In addition to the above we might add the following associations: Assessment is taken by a Student. DoS can check an Assessment. Now for each Student that DoS directs, DoS can check each Assessment that Student has taken. Page 9 of 13

11 (d) What is meant by refactoring in object-oriented design? Explain its role in the design process. [2 marks] Refactoring is a disciplined process of transforming the class model so it is better structured and cleaner in design. The aim of refactoring is to improve the code without changing its behaviour. It is used in OO design to ensure the quality of the model is maintained as it is developed. Page 10 of 13

12 Question 9 The Java language provides an operation + for concatenating two strings. (a) Using only the operations of addition, subtraction and concatenation, by repeated concatenation or otherwise, write a Java implementation of a method static String repeat(string s, int n) such that, if s is a String and n is a natural number (i.e. a non-negative integer), then repeat(s, n) is the result of concatenating n copies of s. [4 marks] static String repeat (String s, int n) { if (n == 0) return "; else return s + repeat(s, n-1); [ Question continues on next page ] Page 11 of 13

13 (b) The following function e defined on strings makes 2 n copies of the string s. The definition uses the function + to concatenate strings. e(s, 0) = s e(s, n + 1) = e(s, n) + e(s, n) The following Java method is intended to be an implementation of this function: static String exp(string s, int n) { if (n == 0) { return s; else { String res = exp(s,n-1); return res+res; [6 marks] Base case n = 0 : We must show that e(s, 0) = exp(s, 0). Using the definition of e we must show exp(s, 0) = s. This is true by computation on exp. Induction Step: Assume e(s, n) = exp(s, n). We have that exp(s, n + 1) = res + res, where res = exp(s, n). By the induction hypothesis, res = e(s, n) and so exp(s, n + 1) = e(s, n) + e(s, n) = e(s, n + 1) by definition of e. Page 12 of 13

14 Question 10 This question concerns stack-based evaluation of arithmetic expressions. (a) Draw syntax trees for the following expressions: 5 ((2 3) + 4) (5 2) (3 + 4) ((5 2) 3) + 4 [3 marks] * * + / \ / \ / \ 5 + * + * 4 / \ / \ / \ / \ * * 3 / \ / \ (b) Give the expressions derived from each of these trees by (i) infix and (ii) postfix tree traversal. [3 marks] (i) infix traversals: (ii) postfix traversals: (c) Using the Java byte code instructions imul, iadd, iconst, show the result of compiling the expression 5 ((2 3) + 4). [4 marks] 1 iconst 5 2 iconst 2 3 iconst 3 4 imul 5 iconst 4 6 iadd 7 imul Page 13 of 13

Computer Science 1 Bh

Computer Science 1 Bh UNIVERSITY OF EDINBURGH course CS0077 FACULTY OF SCIENCE AND ENGINEERING DIVISION OF INFORMATICS SCHOOL OF COMPUTER SCIENCE Computer Science 1 Bh Degree Examination Date: Saturday 26th May 2001 Time: 12:00

More information

Computer Science 1 Bh

Computer Science 1 Bh UNIVERSITY OF EDINBURGH course CS0077 FACULTY OF SCIENCE AND ENGINEERING DIVISION OF INFORMATICS SCHOOL OF COMPUTER SCIENCE Computer Science 1 Bh Degree Examination Date: Saturday 25th May 2002 Time: 12:00

More information

Computer Science 1 Bh

Computer Science 1 Bh UNIVERSITY OF EDINBURGH course CS0077 COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS Computer Science 1 Bh Resit Examination Specimen Solutions Date: Friday 6th September 2002 Time: 09:30 11:00

More information

Computer Science 1 Ah

Computer Science 1 Ah UNIVERSITY OF EDINBURGH course CS0077 COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS Computer Science 1 Ah Resit Examination Specimen Solutions Date: Monday 1st September 2003 Time: 09:30 11:00

More information

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

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

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Computer Science 1 Ah

Computer Science 1 Ah UNIVERSITY OF EDINBURGH course CS0077 FACULTY OF SCIENCE AND ENGINEERING DIVISION OF INFORMATICS SCHOOL OF COMPUTER SCIENCE Computer Science 1 Ah Degree Examination Date: Saturday 25th May 2002 Time: 09:30

More information

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

School of Computer Science CPS109 Course Notes Set 7 Alexander Ferworn Updated Fall 15 CPS109 Course Notes 7 CPS109 Course Notes 7 Alexander Ferworn Unrelated Facts Worth Remembering The most successful people in any business are usually the most interesting. Don t confuse extensive documentation of a situation

More information

CS 314 Exam 2 Spring

CS 314 Exam 2 Spring Points off 1 2 3 4 5 Total off CS 314 Exam 2 Spring 2017 Your Name Your UTEID Instructions: 1. There are 5 questions on this test. 100 points available. Scores will be scaled to 200 points. 2. You have

More information

Topics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1)

Topics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1) Topics Data Structures and Information Systems Part 1: Data Structures Michele Zito Lecture 3: Arrays (1) Data structure definition: arrays. Java arrays creation access Primitive types and reference types

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Interface Abstract data types Version of January 26, 2013 Abstract These lecture notes are meant

More information

Give one example where you might wish to use a three dimensional array

Give one example where you might wish to use a three dimensional array CS 110: INTRODUCTION TO COMPUTER SCIENCE SAMPLE TEST 3 TIME ALLOWED: 60 MINUTES Student s Name: MAXIMUM MARK 100 NOTE: Unless otherwise stated, the questions are with reference to the Java Programming

More information

Unit 10: Sorting/Searching/Recursion

Unit 10: Sorting/Searching/Recursion Unit 10: Sorting/Searching/Recursion Notes AP CS A Searching. Here are two typical algorithms for searching a collection of items (which for us means an array or a list). A Linear Search starts at the

More information

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>= Operators in java Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc. There are many types of operators in java which are given below: Unary Operator, Arithmetic

More information

EXAM Computer Science 1 Part 1

EXAM Computer Science 1 Part 1 Maastricht University Faculty of Humanities and Science Department of Knowledge Engineering EXAM Computer Science 1 Part 1 Block 1.1: Computer Science 1 Code: KEN1120 Examiner: Kurt Driessens Date: Januari

More information

Programming Basics. Digital Urban Visualization. People as Flows. ia

Programming Basics.  Digital Urban Visualization. People as Flows. ia Programming Basics Digital Urban Visualization. People as Flows. 28.09.2015 ia zuend@arch.ethz.ch treyer@arch.ethz.ch Programming? Programming is the interaction between the programmer and the computer.

More information

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

McGill University School of Computer Science COMP-202A Introduction to Computing 1 McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif

More information

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

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

CLO Assessment CLO1 Q1(10) CLO2 Q2 (10) CLO3 Q4 (10) CLO4 Q3a (4)

CLO Assessment CLO1 Q1(10) CLO2 Q2 (10) CLO3 Q4 (10) CLO4 Q3a (4) CS210 Data Structures (171) Final Exam Name: ID Instructions: This exam contains four questions with multiple parts. Time allowed: 180 minutes Closed Book, Closed Notes. There are 10 pages in this exam

More information

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:... Family Name:... Other Names:... Signature:... Student Number:... THE UNIVERSITY OF NEW SOUTH WALES SCHOOL OF COMPUTER SCIENCE AND ENGINEERING Sample Examination COMP1917 Computing 1 EXAM DURATION: 2 HOURS

More information

Object-Oriented Programming and Software Engineering CITS1001 MID-SEMESTER TEST

Object-Oriented Programming and Software Engineering CITS1001 MID-SEMESTER TEST Object-Oriented Programming and Software Engineering School of Computer Science & Software Engineering The University of Western Australia CITS1001 MID-SEMESTER TEST Semester 1, 2013 CITS1001 This Paper

More information

Repetition. We might start out with the following program that draws only the left most object.

Repetition. We might start out with the following program that draws only the left most object. page 2 1 Chapter 2 Repetition 2.1 Repetition Methods with parameters Suppose we want to produce the following image. We might start out with the following program that draws only the left most object.

More information

CS171 Midterm Exam. October 29, Name:

CS171 Midterm Exam. October 29, Name: CS171 Midterm Exam October 29, 2012 Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 50 minutes to complete this exam. Read each problem carefully, and

More information

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Spring 2014 7-10p, Tuesday, April 8 Name: NetID: Lab Section

More information

Advances in Programming Languages: Exam preparation and exam questions

Advances in Programming Languages: Exam preparation and exam questions Advances in Programming Languages: Exam preparation and exam questions Stephen Gilmore The University of Edinburgh March 24, 2006 Examinations What is the purpose of examinations? 1. To test understanding.

More information

Computer Science CS221 Test 2 Name. 1. Give a definition of the following terms, and include a brief example. a) Big Oh

Computer Science CS221 Test 2 Name. 1. Give a definition of the following terms, and include a brief example. a) Big Oh Computer Science CS221 Test 2 Name 1. Give a definition of the following terms, and include a brief example. a) Big Oh b) abstract class c) overriding d) implementing an interface 10/21/1999 Page 1 of

More information

Overview. ITI Introduction to Computing II. Interface 1. Problem 1. Problem 1: Array sorting. Problem 1: Array sorting. Problem 1: Array sorting

Overview. ITI Introduction to Computing II. Interface 1. Problem 1. Problem 1: Array sorting. Problem 1: Array sorting. Problem 1: Array sorting Overview ITI 1121. Introduction to Computing II Rafael Falcon and Marcel Turcotte (with contributions from R. Holte) Electrical Engineering and Computer Science University of Ottawa Interface Abstract

More information

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes CSE 250 Final Exam Fall 2013 Time: 3 hours. Dec 11, 2013 Total points: 100 14 pages Please use the space provided for each question, and the back of the page if you need to. Please do not use any extra

More information

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming s SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177 Programming Time allowed: THREE hours: Answer: ALL questions Items permitted: Items supplied: There is

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Computer Science Foundation Exam. Dec. 19, 2003 COMPUTER SCIENCE I. Section I A. No Calculators! KEY

Computer Science Foundation Exam. Dec. 19, 2003 COMPUTER SCIENCE I. Section I A. No Calculators! KEY Computer Science Foundation Exam Dec. 19, 2003 COMPUTER SCIENCE I Section I A No Calculators! Name: KEY SSN: Score: 50 In this section of the exam, there are Three (3) problems You must do all of them.

More information

Code No: R Set No. 1

Code No: R Set No. 1 Code No: R05010106 Set No. 1 1. (a) Draw a Flowchart for the following The average score for 3 tests has to be greater than 80 for a candidate to qualify for the interview. Representing the conditional

More information

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

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Largest Online Community of VU Students

Largest Online Community of VU Students WWW.VUPages.com http://forum.vupages.com WWW.VUTUBE.EDU.PK Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions

More information

COMPUTING SCIENCE 3Z: PROGRAMMING LANGUAGES 3

COMPUTING SCIENCE 3Z: PROGRAMMING LANGUAGES 3 Tuesday, 28 May 2009 2.00 pm 3.30 pm (Duration: 1 hour 30 minutes) DEGREES OF MSci, MEng, BEng, BSc, MA and MA (Social Sciences) COMPUTING SCIENCE 3Z: PROGRAMMING LANGUAGES 3 Answer all 4 questions. This

More information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships

More information

Draw a diagram of an empty circular queue and describe it to the reader.

Draw a diagram of an empty circular queue and describe it to the reader. 1020_1030_testquestions.text Wed Sep 10 10:40:46 2014 1 1983/84 COSC1020/30 Tests >>> The following was given to students. >>> Students can have a good idea of test questions by examining and trying the

More information

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40% CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40% Name ID Directions: There are 9 questions in this exam. To earn a possible full score, you must solve all questions. Time allowed: 180 minutes Closed

More information

DUKE UNIVERSITY Department of Computer Science. Test 1: CompSci 100

DUKE UNIVERSITY Department of Computer Science. Test 1: CompSci 100 DUKE UNIVERSITY Department of Computer Science Test 1: CompSci 100 Name (print): Community Standard acknowledgment (signature): Problem 1 value 30 pts. grade Problem 2 16 pts. Problem 3 14 pts. Problem

More information

Selenium Class 9 - Java Operators

Selenium Class 9 - Java Operators Selenium Class 9 - Java Operators Operators are used to perform Arithmetic, Comparison, and Logical Operations, Operators are used to perform operations on variables and values. public class JavaOperators

More information

COS 226 Midterm Exam, Spring 2011

COS 226 Midterm Exam, Spring 2011 NAME: login ID: Precept (circle one): P01 P01A P01B P02 P02A P03 COS 226 Midterm Exam, Spring 2011 This test is 9 questions, weighted as indicated. The exam is closed book, except that you are allowed

More information

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

1. Which of the following is the correct expression of character 4? a. 4 b. 4 c. '\0004' d. '4' Practice questions: 1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 2. Will System.out.println((char)4) display 4? a. Yes b. No 3. The expression "Java

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

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

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java Chapter 3 Syntax, Errors, and Debugging Objectives Construct and use numeric and string literals. Name and use variables and constants. Create arithmetic expressions. Understand the precedence of different

More information

Operators and Expressions

Operators and Expressions Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

More information

CS171 Final Practice Exam

CS171 Final Practice Exam CS171 Final Practice Exam Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 150 minutes to complete this exam. Read each problem carefully, and review your

More information

Solution to CSE 250 Final Exam

Solution to CSE 250 Final Exam Solution to CSE 250 Final Exam Fall 2013 Time: 3 hours. December 13, 2013 Total points: 100 14 pages Please use the space provided for each question, and the back of the page if you need to. Please do

More information

Points off Total off Net Score. CS 314 Final Exam Spring 2016

Points off Total off Net Score. CS 314 Final Exam Spring 2016 Points off 1 2 3 4 5 6 Total off Net Score CS 314 Final Exam Spring 2016 Your Name Your UTEID Instructions: 1. There are 6 questions on this test. 100 points available. Scores will be scaled to 300 points.

More information

ESC101 : Fundamental of Computing

ESC101 : Fundamental of Computing ESC101 : Fundamental of Computing End Semester Exam 19 November 2008 Name : Roll No. : Section : Note : Read the instructions carefully 1. You will lose 3 marks if you forget to write your name, roll number,

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Place your name tag here

Place your name tag here CS 170 Exam 1 Section 001 Spring 2015 Name: Place your name tag here Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2017 EXAMINATIONS CSC 104 H1S Instructor(s): G. Baumgartner Duration 3 hours PLEASE HAND IN No Aids Allowed Student Number: Last (Family)

More information

Expressions and Casting

Expressions and Casting Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence

More information

Prof. Navrati Saxena TA: Rochak Sachan

Prof. Navrati Saxena TA: Rochak Sachan JAVA Prof. Navrati Saxena TA: Rochak Sachan Operators Operator Arithmetic Relational Logical Bitwise 1. Arithmetic Operators are used in mathematical expressions. S.N. 0 Operator Result 1. + Addition 6.

More information

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7) Array Basics: Outline Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and Constants

More information

EXAMINATIONS 2008 MID-YEAR COMP431 COMPILERS. Instructions: Read each question carefully before attempting it.

EXAMINATIONS 2008 MID-YEAR COMP431 COMPILERS. Instructions: Read each question carefully before attempting it. T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON EXAMINATIONS 2008 MID-YEAR COMP431 COMPILERS Time Allowed: 3 Hours Instructions: Read each

More information

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures MIDTERM EXAMINATION Spring 2010 CS301- Data Structures Question No: 1 Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the

More information

Second Examination Solution

Second Examination Solution University of Illinois at Urbana-Champaign Department of Computer Science Second Examination Solution CS 225 Data Structures and Software Principles Fall 2007 7p-9p, Thursday, November 8 Name: NetID: Lab

More information

Data Structures and Algorithms 1

Data Structures and Algorithms 1 CS Content Academy: Data Structures Outline 1. How Does Data Structures Fit into CS What Is CS? 2. What Are Data Structures and Algorithms? 3. The Structure of Data Structures and Algorithms 3.1 Part A:

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1 CSC 1051 Algorithms and Data Structures I Midterm Examination February 24, 2014 Name: KEY 1 Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in

More information

Test 1: CPS 100. Owen Astrachan. October 1, 2004

Test 1: CPS 100. Owen Astrachan. October 1, 2004 Test 1: CPS 100 Owen Astrachan October 1, 2004 Name: Login: Honor code acknowledgment (signature) Problem 1 value 20 pts. grade Problem 2 30 pts. Problem 3 20 pts. Problem 4 20 pts. TOTAL: 90 pts. This

More information

Total Score /1 /20 /41 /15 /23 Grader

Total Score /1 /20 /41 /15 /23 Grader NAME: NETID: CS2110 Spring 2015 Prelim 2 April 21, 2013 at 5:30 0 1 2 3 4 Total Score /1 /20 /41 /15 /23 Grader There are 5 questions numbered 0..4 on 8 pages. Check now that you have all the pages. Write

More information

CSE wi Midterm Exam 2/8/18 Sample Solution

CSE wi Midterm Exam 2/8/18 Sample Solution Remember: For all of the questions involving proofs, assertions, invariants, and so forth, you should assume that all numeric quantities are unbounded integers (i.e., overflow can not happen) and that

More information

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm CIS 110 Introduction To Computer Programming February 29, 2012 Midterm Name: Recitation # (e.g. 201): Pennkey (e.g. bjbrown): My signature below certifies that I have complied with the University of Pennsylvania

More information

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course : Advanced Java Concepts + Additional Questions from Earlier Parts of the Course 1. Given the following hierarchy: class Alpha {... class Beta extends Alpha {... class Gamma extends Beta {... In what order

More information

CIS 341 Final Examination 4 May 2017

CIS 341 Final Examination 4 May 2017 CIS 341 Final Examination 4 May 2017 1 /14 2 /15 3 /12 4 /14 5 /34 6 /21 7 /10 Total /120 Do not begin the exam until you are told to do so. You have 120 minutes to complete the exam. There are 14 pages

More information

ISY00245 Principles of Programming. Module 7

ISY00245 Principles of Programming. Module 7 ISY00245 Principles of Programming Module 7 Module 7 Loops and Arrays Introduction This week we have gone through some of the concepts in your lecture, and will be putting them in to practice (as well

More information

COMPUTER SCIENCE Paper 1

COMPUTER SCIENCE Paper 1 COMPUTER SCIENCE Paper 1 (THEORY) (Three hours) Maximum Marks: 70 (Candidates are allowed additional 15 minutes for only reading the paper. They must NOT start writing during this time) -----------------------------------------------------------------------------------------------------------------------

More information

Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. Page 1 of 16 SOLUTION HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2004 FINAL EXAMINATION 9am to 12noon, 22 DECEMBER 2004 Instructors: Alan

More information

Java Simple Data Types

Java Simple Data Types Intro to Java Unit 1 Multiple Choice Java Simple Data Types DO NOT WRITE ON THIS TEST This test includes program segments, which are not complete programs. Answer such questions with the assumption that

More information

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam 1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Exam Name: Email Address: TA: Section: You have three hours to complete this exam. For coding questions, you do not need to include

More information

TeenCoder : Java Programming (ISBN )

TeenCoder : Java Programming (ISBN ) TeenCoder : Java Programming (ISBN 978-0-9887070-2-3) and the AP * Computer Science A Exam Requirements (Alignment to Tennessee AP CS A course code 3635) Updated March, 2015 Contains the new 2014-2015+

More information

Compiling expressions

Compiling expressions E H U N I V E R S I T Y T O H F R G Compiling expressions E D I N B U Javier Esparza Computer Science School of Informatics The University of Edinburgh The goal 1 Construct a compiler for arithmetic expressions

More information

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions

More information

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm CIS 110 Introduction to Computer Programming February 29, 2012 Midterm Name: Recitation # (e.g. 201): Pennkey (e.g. bjbrown): My signature below certifies that I have complied with the University of Pennsylvania

More information

Creating Two-dimensional Arrays

Creating Two-dimensional Arrays ANY TYPE CAN BE USED as the base type of an array. You can have an array of ints, an array of Strings, an array of Objects, and so on. In particular, since an array type is a first-class Java type, you

More information

CS 61B Data Structures and Programming Methodology. July 2, 2008 David Sun

CS 61B Data Structures and Programming Methodology. July 2, 2008 David Sun CS 61B Data Structures and Programming Methodology July 2, 2008 David Sun Announcements Project 1 spec and code is available on the course website. Due July 15 th. Start early! Midterm I is next Wed in

More information

THE AUSTRALIAN NATIONAL UNIVERSITY First Semester Examination June COMP3320/6464/HONS High Performance Scientific Computing

THE AUSTRALIAN NATIONAL UNIVERSITY First Semester Examination June COMP3320/6464/HONS High Performance Scientific Computing THE AUSTRALIAN NATIONAL UNIVERSITY First Semester Examination June 2014 COMP3320/6464/HONS High Performance Scientific Computing Study Period: 15 minutes Time Allowed: 3 hours Permitted Materials: Non-Programmable

More information

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

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Please check your tutorial (TUT) section from the list below: TUT 101: F 11:30, MC 4042 TUT 102: M 10:30, MC 4042 TUT 103: M 11:30, MC 4058 TUT 104: F 10:30,

More information

Java Simple Data Types

Java Simple Data Types Intro to Java Unit 1 Multiple Choice Test Key Java Simple Data Types This Test Is a KEY DO NOT WRITE ON THIS TEST This test includes program segments, which are not complete programs. Answer such questions

More information

Key Java Simple Data Types

Key Java Simple Data Types AP CS P w Java Unit 1 Multiple Choice Practice Key Java Simple Data Types This test includes program segments, which are not complete programs. Answer such questions with the assumption that the program

More information

Java byte code verification

Java byte code verification Java byte code verification SOS Master Science Informatique U. Rennes 1 Thomas Jensen SOS Java byte code verification 1 / 26 Java security architecture Java: programming applications with code from different

More information

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Introduction to Computing II (ITI 1121) FINAL EXAMINATION 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

More information

Chapter 9 Introduction to Arrays. Fundamentals of Java

Chapter 9 Introduction to Arrays. Fundamentals of Java Chapter 9 Introduction to Arrays Objectives Write programs that handle collections of similar items. Declare array variables and instantiate array objects. Manipulate arrays with loops, including the enhanced

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract

More information

CMSC430 Spring 2014 Midterm 2 Solutions

CMSC430 Spring 2014 Midterm 2 Solutions CMSC430 Spring 2014 Midterm 2 Solutions 1. (12 pts) Syntax directed translation & type checking Consider the following grammar fragment for an expression for C--: exp CONST IDENT 1 IDENT 2 [ exp 1 ] Assume

More information

CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed

CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What would

More information

CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid:

CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid: CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid: CS 2150 Exam 1 Name You MUST write your e-mail ID on EACH page and put your name on the top of this page, too. If you are still writing when pens down

More information

NATIONAL UNIVERSITY OF SINGAPORE

NATIONAL UNIVERSITY OF SINGAPORE NATIONAL UNIVERSITY OF SINGAPORE SCHOOL OF COMPUTING EXAMINATION FOR CS1020 Semester 2: AY2011/12 CS1020 Data Structures and Algorithms I April 2012 Time allowed: 2 hours Matriculation number: INSTRUCTIONS

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba Before writing a program to solve a problem, have a thorough understanding of the problem and a carefully planned approach to solving it. Understand the types of building

More information

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA 1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \ BSc IT C Programming (2013-2017) Unit I Q1. What do you understand by type conversion? (2013) Q2. Why we need different data types? (2013) Q3 What is the output of the following (2013) main() Printf( %d,

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. CSIS 10A PRACTICE FINAL EXAM SOLUTIONS Closed Book Closed Computer 3 Sheets of Notes Allowed MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What

More information

CIS 120 Programming Languages and Techniques. Final Exam, May 3, 2011

CIS 120 Programming Languages and Techniques. Final Exam, May 3, 2011 CIS 120 Programming Languages and Techniques Final Exam, May 3, 2011 Name: Pennkey: My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in

More information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer) COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back

More information

CSE 331 Final Exam 12/9/13

CSE 331 Final Exam 12/9/13 Name There are 10 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed

More information