Review Questions for CSC3405/CSC3605: Algorithms and Data Structures - Prof. Susanna Wei, Exams of Computer Science

A series of programming questions for a final exam in csc3405/csc3605, focusing on recursion, iteration, arrays, and basic data structures. Students are asked to write methods for printing strings backwards, computing factorials, checking array equality, summing arrays, handling account balances, and shuffling arrays, among other tasks.

Typology: Exams

Pre 2010

Uploaded on 08/16/2009

koofers-user-kn7
koofers-user-kn7 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSC3405/CSC3605
Review for Final
Write a recursive method to print a string backwards.
Write an iterative method to print a string backwards.
Write a recursive method to compute the factorial of a number.
Write an iterative method to compute the factorial of a number.
1) Write a function that takes 2 arrays of 10 integers as arguments, and returns true if all of the
elements in the first array match (in order) all of the elements of the second array.
2) Write a function verify that takes an array of integers and the size of the array. The
function returns true if the first element of the array is equal to the sum of the rest of the
elements, false if not.
3) Write a method(function) that reads integers from the input until the first non-zero integer
is found. Return this number.
4) Write a method (function) that takes an array of integers, the size of the array, and an
integer skip as parameters. The method returns the sum of all numbers in the array,
skipping the first skip elements.
5) Write a program that reads an account balance (at the start of the month), the total value
of deposits (for the month), the total value of withdrawals (for the month), and displays
both the final balance and the net change to the balance.
6) Write a program that reads integers count and marker from the input. It then reads count
integers. Of these integers, the program prints the first integer after any time marker
appears. For example, input of "8 0 0 2 3 0 0 -3 0 10" should result in output of "2 0 -3 10".
Notice that in this input, count = 8 and marker = 0 and there are 8 integers following the
input of 8 and 0.
7) Write a function shuffle that takes an array of 20 integers and then shuffles the integers
using the following algorithm: For each element X of the array, generate a random number
N between 0 and 19, inclusive. Swap X with the element that corresponds to N.
1
pf2

Partial preview of the text

Download Review Questions for CSC3405/CSC3605: Algorithms and Data Structures - Prof. Susanna Wei and more Exams Computer Science in PDF only on Docsity!

CSC3405/CSC

Review for Final

Write a recursive method to print a string backwards. Write an iterative method to print a string backwards. Write a recursive method to compute the factorial of a number. Write an iterative method to compute the factorial of a number.

  1. Write a function that takes 2 arrays of 10 integers as arguments, and returns true if all of the elements in the first array match (in order) all of the elements of the second array.
  2. Write a function verify that takes an array of integers and the size of the array. The function returns true if the first element of the array is equal to the sum of the rest of the elements, false if not.
  3. Write a method(function) that reads integers from the input until the first non-zero integer is found. Return this number.
  4. Write a method (function) that takes an array of integers , the size of the array , and an integer skip as parameters. The method returns the sum of all numbers in the array, skipping the first skip elements.
  5. Write a program that reads an account balance (at the start of the month), the total value of deposits (for the month), the total value of withdrawals (for the month), and displays both the final balance and the net change to the balance.
  6. Write a program that reads integers count and marker from the input. It then reads count integers. Of these integers, the program prints the first integer after any time marker appears. For example, input of "8 0 0 2 3 0 0 -3 0 10" should result in output of "2 0 -3 10". Notice that in this input, count = 8 and marker = 0 and there are 8 integers following the input of 8 and 0.
  7. Write a function shuffle that takes an array of 20 integers and then shuffles the integers using the following algorithm: For each element X of the array, generate a random number N between 0 and 19, inclusive. Swap X with the element that corresponds to N.

8) Write a program that reads integers with values guaranteed to be in the range 1-

from the keyboard and prints the mode, that is, the integer which appears the most

frequently and how often it appears. You should also be able to write this as a

function. (Similarly, write a program and/or function which does the same for an

array of 100 integers in the range 1-5).

13) Implement the following Money class. When you finish your implementation,

write a driver to test it.

public class Money

public final char SYMBOL = '$';

private long dollars;

private long cents;

14). Define a extMoney class to extend the above money class to include a field that

says whether the money is real money or play money.

public class ExtMoney extends Money

private String kindOfMoney;

  1. What are the obligations of a class that implements a specific interface? Briefly explain
  2. What is catch or declare rule?