Docsity

Solved Exam 1 - Algorithms and Data Structures | CP SC 212, Exams of Algorithms and Programming

Toggle sidebar
bg1
CPSC 212-301 Name: _____________________________
Test #1A September 22, 2004
Honor Pledge:
I pledge that I have neither given nor received unauthorized assistance on this test.
Signed: _______________________ Date: _____________
20 points. 50 minutes. Open Java API. Open cucs API. You may not visit any other web
page.
You are to develop a class called MatrixManager which has:
1. an instance variable which is a two-dimensional int array,
2. a one-argument constructor MatrixManager(String filename)
which instantiates and populates the array with values read from the user-
provided input file, and
3. public methods: printMax(), printMin (), printMatrix ()
which print the maximum value, the minimum value, and all values of the array as
shown in the example below.
For example, assume that a sample input file called “inputfile” contains the following
data:
3 5
1 2 3 4 5
13 12 15 11 14
10 9 8 7 6
The first line contains the number of rows (3 in the sample file) and columns (5) of the
array. The next lines contain array int values. Note that there are 3 lines with 5 int
values per line. Values are separated by spaces. There are no blank lines. You may
assume that the input is error free.
Then the following test driver:
public static void main(String args[]) {
MatrixManager mm = new MatrixManager("inputfile");
mm.printMatrix();
mm.printMin();
mm.printMax();
} // end main
pf2

Partial preview of the text

Download Solved Exam 1 - Algorithms and Data Structures | CP SC 212 and more Exams Algorithms and Programming in PDF only on Docsity!

CPSC 212-301 Name: _____________________________ Test #1A September 22, 2004 Honor Pledge: I pledge that I have neither given nor received unauthorized assistance on this test. Signed: _______________________ Date: _____________ 20 points. 50 minutes. Open Java API. Open cucs API. You may not visit any other web page. You are to develop a class called MatrixManager which has:

  1. an instance variable which is a two-dimensional int array,
  2. a one-argument constructor MatrixManager(String filename) which instantiates and populates the array with values read from the user- provided input file, and
  3. public methods: printMax(), printMin (), printMatrix () which print the maximum value, the minimum value, and all values of the array as shown in the example below. For example, assume that a sample input file called “inputfile” contains the following data: 3 5 1 2 3 4 5 13 12 15 11 14 10 9 8 7 6 The first line contains the number of rows ( 3 in the sample file) and columns ( 5 ) of the array. The next lines contain array int values. Note that there are 3 lines with 5 int values per line. Values are separated by spaces. There are no blank lines. You may assume that the input is error free. Then the following test driver: public static void main(String args[]) { MatrixManager mm = new MatrixManager("inputfile"); mm.printMatrix(); mm.printMin(); mm.printMax(); } // end main

produces the following output: The matrix has 3 rows and 5 columns: 1 2 3 4 5 13 12 15 11 14 10 9 8 7 6 Minimum value: M[0][0] = 1 Maximum value: M[1][2] = 15 Note that the matrix values output do not have to be column-aligned. Submission: Submit your work using: handin.212.301 1 MatrixManager.java Also submit any helper methods you developed during this test and required by your class. Evaluation: Your program will be evaluated on: (a) correctness of algorithm, and (b) selection of storage/data structure, and (c) efficiency of algorithm. Note: Make sure that you include public methods printMatrix(), printMin(), and printMax()in your class even if you were not able to complete them. This is in order that your program will compile with our test driver. If you cannot complete a method, print one line in the method stating so. For example: printMin() method not completed or printMax() method not completed