English version

# Fondamenti di Informatica - Compito A

## 1  Exercise (16 points)

Last night a murder was perpetrated; from the autopsy, the doctor was able to assess that the murder was perpetrated at 23.17 (17 past 11 p.m.). In order to have an idea about who the murderer could be, the policemen asked to the mobile phone provider the list of all the cellular numbers that were in the cell of the place were the murder was done.

The mobile phone company provided a text file cellula.log; it contains a list of cellular numbers, each associated with two times of the day: the time in which the mobile phone entered into the cell, and the time in which it exited the cell. More precisely, for each mobile phone number we have:

• mobile phone number: a string containing at most 12 characters, without spaces
• time (hours and minutes, two integer numbers) in which the phone entered the cell, time (hours and minutes) in which the phone exited the cell (2 integers).

The file cellula.log contains at most 100 elements, that are all the mobile phones that entered into that cell during the day. The police wants to restrict only to those mobile phones that were in the cell at the time the murder was perpetrated, i.e. 23.17.

Write a C program that shows the list of those cellular numbers that were in the cell at 23.17.

Organize the program as follows:

1. main: in the `main` function, invoke a function to read the file cellula.log (the function will be implemented in step 2), one to compute the result (to be implemented in step 3), finally show the result through a print procedure (to be implemented in step 5)
2. read cellula.log: the function that reads cellula.log should read the file cellula.log and insert the data contained in the file into a suitable array of structures. Each element of the array is a structure containing three fields: mobile phone number, time of entering the cell (structure of type "time": it contains hours and minutes) and time in which the mobile exited the cell (another structure of type "time"). Show the content of the array on video.
3. elaborazione: the function computing the results has as parameters
• the array that was read at step 2
plus, possibly, other parameters, and provides to the `main` function an array of strings, containing the phone numbers that were in the cell at the time of the murder. In order to compute that, it invokes, for each element of the array read at step 2, a function (to be developed at step 4) that computes if that mobile phone was in the cell at the time the murder was perpetrated.
4. inside: the function receives as parameters three structures of type time:
• the time in which the mobile phone entered and exited the cell
• the time in which the murder was perpetrated
and provides
• 1 if the time in which the murder was committed is comprised in the interval in which the mobile entered and exited the cell
• 0 otherwise
5. print: the function receives as parameter the array of strings generated at step 3 (plus, possibly, other parameters) and shows the array on the screen.

It is necessary to organize the program into procedures and functions; it is highly recommendable to add other procedures/functions beyond those explicitly given in the text.

## 2  Exercise (points 4)

The police asked to the mobile phone provider also the names of its clients, together with their mobile phone numbers. The phone company provided the data in a text file nomi.txt. For each telephone number it contains:

• telephone number: string containing at most 12 characters, without spaces
• name, surname: strings containing at most 20 characters, without spaces.

We wish to know, for each telephone number that was in the cell at the time the murder was perpetrated, who is the owner of that cell phone.

The file is sorted by telephone number.

The student should use the most efficient algorithm (s)he knows, considering that the file is sorted by telephone number.

It is mandatory to organize the program in suitable functions, in particular adding a significant number of functions with respect to exercise 1.

If the student does only exercise 1, (s)he can write all the exercise in une c file.

If (s)he does also exercise 2, then (s)he should provide the following file:

• a file `SURNAME.c` (where SURNAME is to be substituted with the surname of the student) containing the `main` and the functions that are use only in exercise 1
• a file `facoltativo.c` containing the `main` function and those functions used only in exercise 2
• a file `funzioni.c` that contains the functions used in both exercises

plus all the header files that the student believes are necessary.

When correcting the program, the professor will create two projects:

• in one project, he will insert files `SURNAME.c` and `funzioni.c` . The executable obtained from this project should solve exercise 1.
• in the other project, he will insert files `facoltativo.c` and `funzioni.c` . The executable obtained in this way should solve exercise 2.

-

Ultime notizie
17/05

23/10