Salta ai contenuti. | Salta alla navigazione

Strumenti personali

23 January 2012

English version

Fondamenti di Informatica Modulo A

Prof. Marco Gavanelli

 

23rd of January 2012

 

Esercizio (12 points)

Some university researchers in Italy also teach in university courses. Since teaching it is not a duty of researchers, the law states that universities have to pay them for teaching.

In a university, the rector decided a total amount of money for paying the researchers for their teaching, and this total amount of money should be divided among the researchers based on the number of credits of the courses they teach.

You have a binary file corsi.bin that contains information about the courses (max 100) taught by researchers. For each course, the file contains:

 

  • name of the course: string containing at most 20 characters, including the terminator;
  • name of the researcher: string containing at most 20 characters, including the terminator;
  • number of credits of the course: integer

Assuming that each researcher has to teach at most one course, write a program that computes the payment for each researcher.

For example, if the file corsi.bin contains

 

Rossi Analisi 6
Verdi Informatica 10
Bianchi Inglese 4

and the total amount of money is 4000 euros, the program should print:

 

Rossi   1200
Verdi   2000
Bianchi  800

Use the following algorithm:

 

  1. in the main , call a procedure or function that reads the file (step 2), then read from the keyboard the total amount of money, then call a procedure that computes the payment for researchers (step 3), finally call a printing procedure that prints the results (step 4).
  2. in the procedure or function devoted to reading the file, read the file corsi.bin and copy its content into a suitable array of structures. Show on video the content of the array.
  3. this procedure should take as parameters
    • the array read at step 2,
    • the total amount of money
    (plus, possibly, other parameters) and should provide to the main an array that contains, for each researcher, his name and his payment.
  4. this procedure should print the array with the payments, computed in step 3

 

Facoltativo (8 points)

Suppose now that there are some researchers that teach two or more courses. In this case, the file can contain two or more courses with the same teacher (use the file corsi2.bin ).

Modify the program such that it produces an array in which each researcher occurs only once, and for each researcher contains

  • the name of the researcher
  • the total amount of money he will receive

For example, if the file corsi2.bin contains

 

Rossi Analisi 6
Verdi Informatica 5
Rossi Calcolo 3
Bianchi Inglese 3
Verdi Database 3

and the total amount of money is 2000 euros, the program should print

 

Rossi    900
Verdi    800
Bianchi  300

Note that the payment could be non-integer.

You should organize the program in the following files (to be uploaded on the server):

  • a file funzioni.c containing the common functions of both exercises
  • a file main.c containing the main and those functions used only on the main exercise
  • a file facoltativo.c containing the main and those functions used only on the Optional exercise

Plus all the header files necessary for building the two applications.