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

Similar documents
Arrays. Eng. Mohammed Abdualal

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

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

CSE 142 Su01 Final Exam Sample Solution page 1 of 7

CS 101 Spring 2007 Midterm 2 Name: ID:

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

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

AP Computer Science Unit 1. Programs

Question 2. [5 points] Given the following symbolic constant definition

CS 231 Data Structures and Algorithms Fall Arrays Lecture 07 - September 19, Prof. Zadia Codabux

1. Find the output of following java program. class MainClass { public static void main (String arg[])

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

Pace University. Fundamental Concepts of CS121 1

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

Recitation: Loop Jul 7, 2008

CS 180 Final Exam Review 12/(11, 12)/08

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

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Programming II (CS300)

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer

Programming II (CS300)

Nested Loops. A loop can be nested inside another loop.

Array. Lecture 12. Based on Slides of Dr. Norazah Yusof

CS 101 Fall 2006 Midterm 3 Name: ID:

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

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

Object Oriented Programming. Java-Lecture 6 - Arrays

Example: Monte Carlo Simulation 1

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

Java Assignment 3: Loop Practice Ver 3.0 Last Updated: 12/1/2015 8:57 AM

Introduction to Programming Using Java (98-388)

Lecture 2. Two-Dimensional Arrays

Software Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Chapter 4: Control structures. Repetition

Lesson 2: First Java Programs

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

AP CS Unit 3: Control Structures Notes

Section 2.2 Your First Program in Java: Printing a Line of Text

Computer Science II (20082) Week 1: Review and Inheritance

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

Full file at

Software Practice 1 Basic Grammar

Loops. CSE 114, Computer Science 1 Stony Brook University

Chapter 4: Control structures

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

CS18000: Problem Solving And Object-Oriented Programming

1. What is the difference between a compiler and an interpreter? Also, discuss Java s method.

Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 45 Obtained Marks:

Arrays and Lists CSC 121 Fall 2015 Howard Rosenthal

CIS 110: Introduction to Computer Programming

Arrays and Lists CSC 121 Fall 2016 Howard Rosenthal

CS 455 Midterm 2 Spring 2018 [Bono] Apr. 3, 2018

Arrays and Lists CSC 121 Fall 2014 Howard Rosenthal

Arrays. Chapter 7 (Done right after 4 arrays and loops go together, especially for loops)

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Top-Down Program Development

CS111: PROGRAMMING LANGUAGE II

Lecture 13: Two- Dimensional Arrays

Java Loop Control. Programming languages provide various control structures that allow for more complicated execution paths.

Array. Array Declaration:

AP Computer Science Unit 1. Writing Programs Using BlueJ

AP COMPUTER SCIENCE A

CP122 CS I. Iteration

Getting started with Java

CSE 20. SAMPLE FINAL Version A Time: 180 minutes. The following precedence table is provided for your use:

Last Class. While loops Infinite loops Loop counters Iterations

Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8. Handout 5. Loops.

Array. Prepared By - Rifat Shahriyar

Chapters 1-4 Summary. Syntax - Java or C? Syntax - Java or C?

Language Features. 1. The primitive types int, double, and boolean are part of the AP

How to declare an array in C?

The for Loop, Accumulator Variables, Seninel Values, and The Random Class. CS0007: Introduction to Computer Programming

1 Short Answer (10 Points Each)

Boolean Expressions. So, for example, here are the results of several simple Boolean expressions:

More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario

Administration. Conditional Statements. Agenda. Syntax. Flow of control. Lab 2 due now on floppy Lab 3 due tomorrow via FTP

Input from Files. Buffered Reader

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

STUDENT LESSON A12 Iterations

Final Examination CS 125 Introduction to Computer Science Fall Hours

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Chapter 2: Basic Elements of Java

Mr. Monroe s Guide to Mastering Java Syntax

CS 307 Midterm 1 Fall 2007

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

Full file at

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

Introduction to Java Unit 1. Using BlueJ to Write Programs

Instructor: Eng.Omar Al-Nahal

Computer Programming, I. Laboratory Manual. Final Exam Solution

F I N A L E X A M I N A T I O N

Transcription:

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 Language. You may use extra sheets if need be. Q1: Concepts and Definitions 25 marks By declaring an array that will contain 10 floating-point numbers, show the difference between the following: Array size, Array element Array index List two example situations where you may wish to use two-dimensional arrays in organizing your program data Give one example where you might wish to use a three dimensional array 1

Sorting is generally more time consuming than searching. Yet, fast searching algorithms require sorting as an initial step. Give one examples of a situation where it may be useful to sort the data before it is searched. Give one reason (or an example) when it won t be necessary to sort the data before it is searched. List two parameters that are generally considered in the analysis of an algorithm Given the functions that grow proportional to the following formulae, arrange them in increasing order of size (as N becomes large): N N 2 N 4 N 3 N log N N log N log (log N) Which of the following are not valid Java keywords? Just circle them java, class, Class, extends, extend, final, finalize, object, JFrame, swing, awt, null, this, Scanner, interface, FileReader, PrintWriter, implements 2

Q2: Errors in C++ programs or C++ statements 30 marks In each of the following programs or program segments, find the error(s) in the program. Note that the error could be a syntax error, a logic error, missing declaration, missing comments, missing statements, etc. There could be more than one error on the same line. Mark ALL the errors. (a) Question2.java Java program for question 2 Public class Question2() final int N = 20; static Scanner ins = new Scanner(System.in); static int main(string [] args) int array (N); int product for (int k =0; k <= N; k++) array (k) = ins.nextint(); // function call product = arrayproduct (int array, N); //function definition void arrayproduct(int array, int N); float product; float k; product = 0; for (k=0; k > N; k++) System.out.println ( processing element + k +); product = product * array (k); return product; 3

(b) Indicate the syntax errors in the following program. Note, this is supposed to be a Java program, and not just a program segment. (You can also correct the errors if that is easier) public class RTwo extends JFrame public RTwoProgram() private JLabel length, width, area; settitle("good day area"); length = JLabel("Enter the length); width = JLabel("Enter the width); area = JLabel("Area: "); containerpane = ContentPane(); pane.setlayout(gridlayout(4, 1)); setsize(width, HEIGHT); setvisible(); setdefaultcloseoperation(exit_on_close); public static void main( String args[] ) RTwoProgram R2 = new RTwoProgram (); 4

Q3: True or False Question s. 10 marks For each of the following, indicate whether the assertion is TRUE or FALSE. s/n Assertion True or False 1 In Java, the array index can be any number, example double, float, or int 2 A file stream is automatically connected to a physical file at the time the stream is declared 3 In Java event handling, clicking a button can be taken as one event 4 A file To use a 2-dimensional array in a function, we are only required to specify the number of rows (and not the columns) in defining the function. 5 To pass a one-dimensional array to a function, we must always specify the size of the array. 6 Any multi-dimensional array can be represented as a set of some one-dimensional arrays 7 In general, binary search is always faster than sequential search 8 A program that requires time that is proportional to N is generally more efficient than one that requires running time that is proportional to N log N 9 Given a class, we can declare an array of objects of the given class. Conversely, we can also have a class that contains an array in its definition 10 In Java, JFrame is a class 5

Question 4: Program Outputs Ignore syntax errors in this section. 10 marks Consider the following program segment: int numbers[3][3]; int k, j, count; count =0; for (k=0; k< 3; k++ ) for (j=0; j< 3; j++) numbers[k][j] = 0; count++; // second nested for loop for (k=0; k< 3; k++ ) for (j=0; j< 3; j++) if (j==k) numbers[k][j]=(k+j)*(k+j); System.out.print( + numbers[k][j] ) ; // one space inside quotation marks System.out.println(); b1. List the content of the array numbers when execution reaches the line marked second nested for loop. b2. What will be the output of the program segment when it is executed? 6

Question 5: Writing a Program 25 marks (a) You are required to write a program to display the square root of the numbers in a matrix. The program will be based on a user-defined method called matrixelementsqroot( ). The method will take one 2-D array (i.e. a matrix) A as its input, and produce another matrix (2-D array) C, whereby each element in the output matrix C will correspond to the square root of elements at the corresponding position in A. That is C = ij A ij Assume each matrix is of size N x N, where N is 4. You can also assume that the matrix is already initialized to some values. You program must include the following: b. How this method will be called by the main() program, c. The definition for the method matrixelementsqroot( ) Please see last question on next page 7