Salta ai contenuti. | Salta alla navigazione

Strumenti personali

21 december 2011 afternoon

English version

Fondamenti di Informatica Modulo A

Prof. Marco Gavanelli

 

21 December 2011

 

Exercise (16 points)

A binary file orario.bin contains the timetabling of the lessons of a laurea course. The file contains at most 100 lessons. For each lesson, the file contains the following information:

 

  • name of the course, (string containing at most 20 characters, including the final null character)
  • day of the week ( int ranging from 1 to 5, representing the days from Monday to Friday)
  • Start time of the lesson ( int )
  • End time of the lesson ( int )

We want to know in which day of the week the students will spend more time at the university, intended as the difference between the start time of the first lesson and the end time of the last one.

For instance, if the file orario.bin contains the following information:

 

Informatica 1 16 18
Informatica 2 16 18
Analisi 1 8 11
Analisi 2 14 16
Geometria 2 10 13

then, the day in which the students spend most time at the university is day 1 (Monday). In fact, the first lesson starts at 8 o' clock, and the last lesson finishes at 18 (6pm), so they stay at the university for 10 hours. On day 2 (Tuesday), instead, lessons start at 10 and finish at 6pm (8 hours in total).

Use the following algorithm:

 

  1. In the main function, invoke a function that reads the file (to be implemented in step ), then invoke a function that computes the result (step ), and finally print the result (i.e., the day in which the students stay at the university for most time) on video.
  2. Write a function that reads the file orario.bin and inserts its data into a suitable array of structures. Print on video the array.
  3. The function computing the results takes as input the array read on step * (plus, possibly, other parameters) and returns the day of the week in which students stay for the longest time at the university.

    In order to do that, this function should invoke, for each day of the week, the function duration , that will be implemented on step .

  4. Function duration takes as input
    • the array read on step *,
    • a day of the week ( int )
    (plus, possibly, other parameters) and returns the number of hours the students stay at the university in the given day.

 

Optional (4 points)

 

Suppose now that the file orario.bin is too big to fit into the RAM memory; modify the program such that it does not use an array of structures, but it reads and processes the structures from the file one at a time.

Use an enumeration type to represent days (instead of integers).

Suppose now that the file orario.bin is sorted on the day field; make the program more efficient.

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.

archiviato sotto: