Docsity

Quiz 4 - Introduction Computer Program via Web | CMSC 122, Quizzes of Computer Science

Toggle sidebar
bg1
CMSC 122 Quiz 4 Worksheet
The fourth quiz for the course will be on Wednesday, April 29 at the beginning of the class
(2:00 pm). The following list provides more information about the quiz:
The quiz will be a written quiz (no computer).
Closed book, closed notes quiz.
Answers must be neat and legible. We recommend that you use pencil and eraser.
The following exercises cover the material to be included in this quiz. Solutions to these
exercises will not be provided, but you are welcome to discuss your solutions with the TA or
instructor during office hours. You do not need to define a main() function or <script> tags
for the problems below. If we ask for the implementation of a function just provide the
function. We recommend you answer the exercises without a computer, then verify
your answers by writing the program in a computer.
Note: The prototype for a function is the word function followed by the function’s name and
the parameter’s list.
Exercises
1. Write a function named “initialize” that has the following prototype:
function initialize(initialValue, maxRows, maxCols);
The function creates a two-dimensional array of integers with a number of rows and
columns that corresponds to maxRows, and maxCols, respectively. In addition, the
function initializes each array entry with the value initialValue.
2. Write a function named “isRagged” that determines whether a two-dimensional array
is a ragged array. Remember, a ragged array is one where all the rows do not have
the same length.
3. Write a function named “equals” that has the following prototype:
function equals(array1, array2);
The function will return true if the two-dimensional arrays (array1 and array2) have
the same corresponding elements. For example:
10, 20, 30 equals to 10, 20, 30
50, 40 50, 40
10, 30, 20 not equals to 10, 20, 30
50, 40, 60 40, 50, 60
10, 20, 30 not equals to 10, 20, 30
40, 50 40, 50, 60
60
4. Write a function named “printByColumns” that prints the contents of a two-
dimensional array column by column (i.e., data of column 0 will be printed, followed
by data of column 1, etc.)
pf2

Partial preview of the text

Download Quiz 4 - Introduction Computer Program via Web | CMSC 122 and more Quizzes Computer Science in PDF only on Docsity!

CMSC 122 Quiz 4 Worksheet

The fourth quiz for the course will be on Wednesday, April 29 at the beginning of the class (2:00 pm). The following list provides more information about the quiz:

 The quiz will be a written quiz (no computer).  Closed book, closed notes quiz.  Answers must be neat and legible. We recommend that you use pencil and eraser.

The following exercises cover the material to be included in this quiz. Solutions to these exercises will not be provided, but you are welcome to discuss your solutions with the TA or instructor during office hours. You do not need to define a main() function or

  1. Write a function named “sum” that has the following prototype:

function sum(array1);

The function takes a two-dimensional array of integers ( array1 ) as parameter and returns a one-dimensional array where each entry of the one-dimensional array corresponds to the sum of the values of each row of array1. For example if array1 is:

10, 20, 30 50, 40 60, 9

sum will return

60, 90, 69