Salta ai contenuti. | Salta alla navigazione

Strumenti personali

19 December 2019 - AM - B

English version

Fondamenti di Informatica e laboratorio - Compito B

Prof. Marco Gavanelli

19 December 2019

 

1  Esercizio (punti 16)

The health Ministry received an important communication: in the far away country of Macondo a terrorist was able to spread a toxin in the main bazar of the capital city. That toxin does not give visible effects immediately, but it is lethal in the long term, if not countered in the right way. The terrorist spread the toxin in the day 23rd of April.

The health ministry wants to get in touch with all the citizens that were in Macondo in the day 23rd of April. The technicians of the ministry were able to have the list of all citizens that went to Macondo. The list is contained in the binary file tossina.bin; the citizens are at most 100 and for each citizen the file contains:

  • Name (String of 20 characters maximum, including the terminator).
  • Arrival date in Macondo (two integers: the first represents the day and the second the month of arrival in Macondo).
  • departure date from Macondo (two integers, representing the day and the month in which the citizen left Macondo.).

Write a C program that shows the names of the persons that were in Macondo on the day 23rd of April.

Organize the program as follows:

  1. main: in the main function, call a function to read the file tossina.bin (to be implemented in step 2), one that computes the result (to be implemented in step 3), finally show the result through a print procedure (to be implemented in step 5)
  2. read file tossina.bin: the read function should read the file tossina.bin and copy its content into a suitable array of structures. Each element of the array is a structure that contains 3 fields: name of the person, arrival date in Macondo (a struct containing day and month) and departure date (another structure of date type). Show on the video the content of the array.
  3. elaboration: The elaboration function has as as parameters
    • the array read on step 2
    plus, possibly, other parameters and provides to the main function an array of strings, containing the names of the persons that were in Macondo the day 23rd of April.

    To do that, it invokes, for each element of the array read in step 2, a function (to be implemented in step 4) that computes if that citizen was in Macondo in the day in which the toxin was spread.

  4. included: the function has as parameters three structures of type date:
    • the arrival and departure dates
    • the day in which the toxin was spread
    and provides
    • 1 if the date in which the toxin was spread is between the arrival and the departure date
    • 0 otherwise
  5. print: The print function takes as parameter the array of strings generated in 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 ministry's technicians were able to obtain also the telephone numbers of the persons that were in Macondo.

These are listed in the text file nomitel.txt. For each person (maximum 100) the following data is provided:

  • telephone (Integer).
  • name (string containing at most 20 characters, without spaces).

The file is sorted by name in alphabetic order.

Show, per each person in Macondo in day 23rd of April, the telephone number.

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

 

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 one 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.