CSCI A201/A597

Lecture Notes 30

Spring 2000


Course wrap-up. More practice problems for the practical exam.

Here are some more practice problems for the practical:

  1. Write a program that creates a two-dimensional array and fills it with random integers between -50 and 50. The number of lines and columns should be specified by the user on the command line. Your program should show the array to the user and then count and report the number of negative values in the array (strictly less than zero).

  2. Write a program that creates a two-dimensional array of booleans and fills it with either true or false randomly. The number of lines and columns should be specified by the user on the command line. Your program should show the array to the user and then count and report the number of values in the array which are true.

  3. Write a program that creates two two-dimensional arrays of the same size (number of lines and columns are to be specified by the user on the command line). The values in the arrays should be random integers between -50 and 50. Your program should show the arrays to the user and then count and report the number of times the corresponding elements in the arrays differ by more than 10.

  4. Write a program that creates a two-dimensional array of characters and fills it with random lower case characters. The number of lines and columns in the array is to be specified by the user. The program then counts and reports the number of vowels in the array.

  5. Write a program that creates a two-dimensional array and fills it with random integers between -50 and 50. The number of lines and columns should be specified by the user on the command line. Your program should show the array to the user and then report the number of values strictly greater than zero and their average.

  6. Write a program that creates a two-dimensional array and fills it with random integers between -50 and 50. The number of lines and columns should be specified by the user on the command line. Your program should show the array to the user and then report the minimum and maximum value in the array as well as the average of all values.

  7. Write a program that creates two two-dimensional arrays and then adds them up. The two arrays should be of the same size, same number of lines and columns, specified by the user on the command line. The program should randomly fill the arrays with integers between -50 and 50. The sum of the arrays is an array of the same size whose elements are the sums of the corresponding elements in the original arrays.

  8. Write a program that creates two two-dimensional arrays and then computes their difference. The two arrays should be of the same size, same number of lines and columns, specified by the user on the command line. The program should randomly fill the arrays with integers between -50 and 50. The sum of the arrays is an array of the same size whose elements are differences between the corresponding elements in the original arrays.

  9. Write a program that creates two one-dimensional arrays (of the same size) and then computes their alternate scalar product. The size of the arrays should be specified on the command line by the user of the program, and the arrays should be filled with random integers between -50 and 50. The alternate scalar product is defined as
    a0b0 - a1b1 + a2b2 - a3b3 + a4b4 ... (-1)nan-1bn-1
    that is it is just like the scalar product but with instead of adding all the products a[i]b[i] we add the first one, subtract the next one, and so forth in an alternating way.

  10. Write a program that creates a two-dimensional array of booleans, randomly initialized with true or false. The size of the array is to be specified by the user on the command line. The program should then show the array to the user both in the DOS window (as text) and as a grid of black and white squares in a drawing window, with each true value represented as a black cell and each false value represented as a white cell.

  11. Write a program that generates four blue triangles and a red rectangle in a drawing window and then lets the user move the red rectangle with the mouse in the window as many number of times as the user wants. The size of the rectangle should be generated by the user on the command line (width and height in pixels) and the dimensions of the triangles and their locations are up to you. The user should be able to move the rectangle by pressing the mouse inside it and then dragging the mouse across the window, then releasing the mouse button. When the user releases the mouse button the rectangle should stop following the mouse pointer. This sequence of actions can be repeated as many times as the user wants. The triangles should remain unchanged throughout this process. To move the rectangle the user needs to click inside it, if the user clicks outside the rectangle should not move.

Let me know if you have any questions or if you need help.

Last modified: Apr 27, 2000 for A201 by Adrian German