Esercizi di Programmazione Avanzata

Exercises on Advance in Programming


Exercise 1: Test Driven Development on Functions.

To write the test units to support the development of the following functions:

  1. a function anagram that checks if a string passed as a parameter is palindrome, a string is palindrome when the represented sentence can be read the same way in either directions in spite of spaces, punctual and letter cases, e.g., detartrated, "Do geese see God?", "Rise to vote, sir.", ...
  2. a function validate that checks if a string composed of 'X', 'O' and ' ' is a correct configuration for the tic-tac-toe game and if it is a winning configuration for the 'X' or the 'O' symbols, an even configuration or if there are still moves.
  3. a function pluralize that transforms a noun from singular to plural in English (the rules and the solution non test-driven are available in the slides).
Exercise 2: Test Driven Development on Classes.

To write the test units to support the development of the following classes:

  1. a class SquareMatrix representing the square matrix of given size whose constructor initialize the matrix to the identity and with the methods transpose(), sum_by_row(), sum_by_column() and determinant() with the obvious meanings.
  2. a class Geography that maps each country with its neighbors when built and with a method neighbors() that took a country's names returns the list of its neighbors.
  3. a class account similar to that defined in lesson 14 with the following methods deposit(), withdraw(), balance() and the constraint that the balance cannot be negative.
Exercise 3: Test Driven Development for the Pascal's Triangle.

To write the test units to support the development of the following exercise from the last set.

Pascal's triangle is a geometric arrangement of the binomial coefficients in a triangle.

The rows of Pascal's triangle are conventionally enumerated starting with row 0, and the numbers in each row are usually staggered relative to the numbers in the adjacent rows. A simple construction of the triangle proceeds in the following manner. On row 0, write only the number 1. Then, to construct the elements of following rows, add the number directly above and to the left with the number directly above and to the right to find the new value. If either the number to the right or left is not present, substitute a zero in its place.

Implement an iterator for the Pascal's triangle that:

  1. at each step will return another iterator containing all the elements in the corresponding stage sorted as in the triangle
  2. the iterator can go forward and backward
  3. (advanced) it is possible to define the working algebra for the triangle, e.g., it could be on Z7 or on the alphabet

Walter Cazzola

Didactics

Publications

Funded Projects

Research Projects

Related Events








Valid XHTML 1.0 Transitional