Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

8 Questions in Introduction to Computer Program II - Exam 3 | CS 1713, Exams of Computer Science

Material Type: Exam; Class: Intro to Computer Program II; Subject: Computer Science; University: University of Texas - San Antonio; Term: Spring 2009;

Typology: Exams

Pre 2010

Uploaded on 07/30/2009

koofers-user-dzk
koofers-user-dzk 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name
CS 1713 Exam 3 Spring 2009
This is a closed book exam. Answer all questions on these sheets.
1) (20 points)
a) Write a public method, linearSearch, that uses a linear search to find the first position in an array of
double of a given double. Return -1 if it is not found.
b) Write a public method, binarySearch, that uses a binary search to find a position in an array of double
of a given double. Return -1 if it is not found. Assume the array is sorted in increasing order.
pf3
pf4
pf5

Partial preview of the text

Download 8 Questions in Introduction to Computer Program II - Exam 3 | CS 1713 and more Exams Computer Science in PDF only on Docsity!

Name

CS 1713 Exam 3 — Spring 2009

This is a closed book exam. Answer all questions on these sheets.

  1. (20 points) a) Write a public method, linearSearch , that uses a linear search to find the first position in an array of double of a given double. Return -1 if it is not found.

b) Write a public method, binarySearch , that uses a binary search to find a position in an array of double of a given double. Return -1 if it is not found. Assume the array is sorted in increasing order.

  1. (20 points) Write a method to sort an array of String in increasing order using an selection sort. You may (and it is recommended that you) have your sort method call another method, but you need to write that other method also.
  1. (10 points) Write a method that takes an array of Rectangle as a parameter. For each element of the array in which its length is smaller that its width, interchange the length and the width. You may assume that the Rectangle class has the usual accessor and mutator methods.

  2. (8 points) Write a method that takes a two-dimensional array of ints as a parameter and returns the average of the elements of the array. Return 0 if the array has no elements.

  1. (10 points) Suppose Square is a class that has been appropriately written. It has a constructor with one double parameter, its side. Draw an accurate schematic diagram of the program variables showing the execution of the program. double w = 2; double x = 5; double y = 7; Square[] squares = new Square[3]; Square s; s = new Square(w); squares[0] = new Square(x); squares[1] = s; squares[2] = squares[0]; w = squares[2].getArea(); s = squares[2]; x = squares[1].getSide(); y = squares[0].getArea(); squares[2] = squares[1]; squares[2].setSide(9); squares[1] = new Square(8); y = squares[1].getArea(); x = squares[2].getSide();