Exercise 12.1 Provide an iterative implementation of the following operations on lists of strings:
Exercise 12.2 Provide a recursive implementation of the operations of Exercise 12.1.
Exercise 12.3 Whenever on the domain of the elements of a list an order is defined, we can consider ordered lists, in which the sequence of elements in a list is ordered. Provide a recursive and an iterative implementation of the following operations on ordered lists of integers:
Exercise 12.4 Define a class ListOfPersons, each of whose objects maintains the information about a sequence of objects of a class Person (for each person, the information of interest are the name, surname, age, and city of residence). The class ListOfPersons should provide, besides the methods for insertion, deletion and modification of a person, a method to print all persons in the list, a method to count the number of persons in the list that live in a given city passed as parameter, and a method that computes the average age of all persons in the list.
Exercise 12.5 Solve Esercise 7.12 by removing the assumption that at most 10 persons live in an apartment, and handling such an information by means of a linked list, possibly using the class defined in the preceding exercise. Add to the class Apartment a method countPersons() that returns the number of persons living in the apartment, and checkFamily() that checks whether all persons living in the apartment have the same surname.
Exercise 12.6 Define a class ListCDs that maintains information about a sequence of objects of a class CD (for each CD, the information of interest are author, title, publication year, and price). The class ListCDs should provide, besides the methods for inserting, deleting and printing the elements of a list, a method that calculates the total price of the CDs contained in the list, and a method that returns the list of CDs of a given author passed as parameter.
Exercise 12.7 Define a class MyString, that handles sequences of characters (by means of a list of char) and implements some methods similar to those of the class String. Specifically, implement a constructor that creates an object of the class starting from a string, and the methods concat(), equals(), substring(), length(), charAt(), indexOf(), and toUpperCase(). Realize also a method, external to the class MyString, that behaves in the same way as the method Integer.parseInt(). More precisely, given an object of the class MyString, the method should return the integer value corresponding to the numeric digits represented in the MyString object, or should throw an exception if the object contains characters that are different from the digits '0', ..., '9'. Implement the latter method both using iteration and using recursion.
Exercise 12.8 Define a class BigNumber, whose objects represent positive integers with an unbounded number of digits, realized by means of a list of integers. The class should implement a constructor that creates a BigNumber object starting from a string of numeric digits, the methods to calculate the sum and difference of two BigNumbers, the predicates to compare whether two BigNumbers are equal and whether one is smaller than another, and the method toString that constructs the string corresponding to the number. For the difference, return the object representing the number 0 in the case where the result of the subtraction would be negative. We suggest to represent a BigNumber using a list of integers in which the least significant digit is the first element of the list, and the most significant digit the last element of the list.